summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/sw
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-11-12 02:02:25 +0900
commit0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch)
tree40874799472fa07416f17b50a398ac33b7771905 /src/server/api/endpoints/sw
parentupdate deps (diff)
downloadsharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz
sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2
sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip
refactoring
Resolve #7779
Diffstat (limited to 'src/server/api/endpoints/sw')
-rw-r--r--src/server/api/endpoints/sw/register.ts74
-rw-r--r--src/server/api/endpoints/sw/unregister.ts22
2 files changed, 0 insertions, 96 deletions
diff --git a/src/server/api/endpoints/sw/register.ts b/src/server/api/endpoints/sw/register.ts
deleted file mode 100644
index 6e14ba2669..0000000000
--- a/src/server/api/endpoints/sw/register.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import $ from 'cafy';
-import define from '../../define';
-import { fetchMeta } from '@/misc/fetch-meta';
-import { genId } from '@/misc/gen-id';
-import { SwSubscriptions } from '@/models/index';
-
-export const meta = {
- tags: ['account'],
-
- requireCredential: true as const,
-
- params: {
- endpoint: {
- validator: $.str
- },
-
- auth: {
- validator: $.str
- },
-
- publickey: {
- validator: $.str
- }
- },
-
- res: {
- type: 'object' as const,
- optional: false as const, nullable: false as const,
- properties: {
- state: {
- type: 'string' as const,
- optional: false as const, nullable: false as const,
- enum: ['already-subscribed', 'subscribed']
- },
- key: {
- type: 'string' as const,
- optional: false as const, nullable: false as const
- }
- }
- }
-};
-
-export default define(meta, async (ps, user) => {
- // if already subscribed
- const exist = await SwSubscriptions.findOne({
- userId: user.id,
- endpoint: ps.endpoint,
- auth: ps.auth,
- publickey: ps.publickey,
- });
-
- const instance = await fetchMeta(true);
-
- if (exist != null) {
- return {
- state: 'already-subscribed',
- key: instance.swPublicKey
- };
- }
-
- await SwSubscriptions.insert({
- id: genId(),
- createdAt: new Date(),
- userId: user.id,
- endpoint: ps.endpoint,
- auth: ps.auth,
- publickey: ps.publickey
- });
-
- return {
- state: 'subscribed',
- key: instance.swPublicKey
- };
-});
diff --git a/src/server/api/endpoints/sw/unregister.ts b/src/server/api/endpoints/sw/unregister.ts
deleted file mode 100644
index 817ad1f517..0000000000
--- a/src/server/api/endpoints/sw/unregister.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-import $ from 'cafy';
-import define from '../../define';
-import { SwSubscriptions } from '../../../../models';
-
-export const meta = {
- tags: ['account'],
-
- requireCredential: true as const,
-
- params: {
- endpoint: {
- validator: $.str
- },
- }
-};
-
-export default define(meta, async (ps, user) => {
- await SwSubscriptions.delete({
- userId: user.id,
- endpoint: ps.endpoint,
- });
-});