diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-11-12 02:02:25 +0900 |
| commit | 0e4a111f81cceed275d9bec2695f6e401fb654d8 (patch) | |
| tree | 40874799472fa07416f17b50a398ac33b7771905 /src/server/api/endpoints/clips | |
| parent | update deps (diff) | |
| download | sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.gz sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.tar.bz2 sharkey-0e4a111f81cceed275d9bec2695f6e401fb654d8.zip | |
refactoring
Resolve #7779
Diffstat (limited to 'src/server/api/endpoints/clips')
| -rw-r--r-- | src/server/api/endpoints/clips/add-note.ts | 76 | ||||
| -rw-r--r-- | src/server/api/endpoints/clips/create.ts | 45 | ||||
| -rw-r--r-- | src/server/api/endpoints/clips/delete.ts | 40 | ||||
| -rw-r--r-- | src/server/api/endpoints/clips/list.ts | 28 | ||||
| -rw-r--r-- | src/server/api/endpoints/clips/notes.ts | 93 | ||||
| -rw-r--r-- | src/server/api/endpoints/clips/show.ts | 50 | ||||
| -rw-r--r-- | src/server/api/endpoints/clips/update.ts | 65 |
7 files changed, 0 insertions, 397 deletions
diff --git a/src/server/api/endpoints/clips/add-note.ts b/src/server/api/endpoints/clips/add-note.ts deleted file mode 100644 index 79d7b8adde..0000000000 --- a/src/server/api/endpoints/clips/add-note.ts +++ /dev/null @@ -1,76 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ClipNotes, Clips } from '@/models/index'; -import { ApiError } from '../../error'; -import { genId } from '@/misc/gen-id'; -import { getNote } from '../../common/getters'; - -export const meta = { - tags: ['account', 'notes', 'clips'], - - requireCredential: true as const, - - kind: 'write:account', - - params: { - clipId: { - validator: $.type(ID), - }, - - noteId: { - validator: $.type(ID), - }, - }, - - errors: { - noSuchClip: { - message: 'No such clip.', - code: 'NO_SUCH_CLIP', - id: 'd6e76cc0-a1b5-4c7c-a287-73fa9c716dcf' - }, - - noSuchNote: { - message: 'No such note.', - code: 'NO_SUCH_NOTE', - id: 'fc8c0b49-c7a3-4664-a0a6-b418d386bb8b' - }, - - alreadyClipped: { - message: 'The note has already been clipped.', - code: 'ALREADY_CLIPPED', - id: '734806c4-542c-463a-9311-15c512803965' - }, - } -}; - -export default define(meta, async (ps, user) => { - const clip = await Clips.findOne({ - id: ps.clipId, - userId: user.id - }); - - if (clip == null) { - throw new ApiError(meta.errors.noSuchClip); - } - - const note = await getNote(ps.noteId).catch(e => { - if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); - throw e; - }); - - const exist = await ClipNotes.findOne({ - noteId: note.id, - clipId: clip.id - }); - - if (exist != null) { - throw new ApiError(meta.errors.alreadyClipped); - } - - await ClipNotes.insert({ - id: genId(), - noteId: note.id, - clipId: clip.id - }); -}); diff --git a/src/server/api/endpoints/clips/create.ts b/src/server/api/endpoints/clips/create.ts deleted file mode 100644 index 02d2773709..0000000000 --- a/src/server/api/endpoints/clips/create.ts +++ /dev/null @@ -1,45 +0,0 @@ -import $ from 'cafy'; -import define from '../../define'; -import { genId } from '@/misc/gen-id'; -import { Clips } from '@/models/index'; - -export const meta = { - tags: ['clips'], - - requireCredential: true as const, - - kind: 'write:account', - - params: { - name: { - validator: $.str.range(1, 100) - }, - - isPublic: { - validator: $.optional.bool - }, - - description: { - validator: $.optional.nullable.str.range(1, 2048) - } - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Clip' - } -}; - -export default define(meta, async (ps, user) => { - const clip = await Clips.insert({ - id: genId(), - createdAt: new Date(), - userId: user.id, - name: ps.name, - isPublic: ps.isPublic, - description: ps.description, - }).then(x => Clips.findOneOrFail(x.identifiers[0])); - - return await Clips.pack(clip); -}); diff --git a/src/server/api/endpoints/clips/delete.ts b/src/server/api/endpoints/clips/delete.ts deleted file mode 100644 index ca489af3bf..0000000000 --- a/src/server/api/endpoints/clips/delete.ts +++ /dev/null @@ -1,40 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ApiError } from '../../error'; -import { Clips } from '@/models/index'; - -export const meta = { - tags: ['clips'], - - requireCredential: true as const, - - kind: 'write:account', - - params: { - clipId: { - validator: $.type(ID), - } - }, - - errors: { - noSuchClip: { - message: 'No such clip.', - code: 'NO_SUCH_CLIP', - id: '70ca08ba-6865-4630-b6fb-8494759aa754' - } - } -}; - -export default define(meta, async (ps, user) => { - const clip = await Clips.findOne({ - id: ps.clipId, - userId: user.id - }); - - if (clip == null) { - throw new ApiError(meta.errors.noSuchClip); - } - - await Clips.delete(clip.id); -}); diff --git a/src/server/api/endpoints/clips/list.ts b/src/server/api/endpoints/clips/list.ts deleted file mode 100644 index 1f6db9b979..0000000000 --- a/src/server/api/endpoints/clips/list.ts +++ /dev/null @@ -1,28 +0,0 @@ -import define from '../../define'; -import { Clips } from '@/models/index'; - -export const meta = { - tags: ['clips', 'account'], - - requireCredential: true as const, - - kind: 'read:account', - - res: { - type: 'array' as const, - optional: false as const, nullable: false as const, - items: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Clip' - } - } -}; - -export default define(meta, async (ps, me) => { - const clips = await Clips.find({ - userId: me.id, - }); - - return await Promise.all(clips.map(x => Clips.pack(x))); -}); diff --git a/src/server/api/endpoints/clips/notes.ts b/src/server/api/endpoints/clips/notes.ts deleted file mode 100644 index 5a9fed52fa..0000000000 --- a/src/server/api/endpoints/clips/notes.ts +++ /dev/null @@ -1,93 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ClipNotes, Clips, Notes } from '@/models/index'; -import { makePaginationQuery } from '../../common/make-pagination-query'; -import { generateVisibilityQuery } from '../../common/generate-visibility-query'; -import { generateMutedUserQuery } from '../../common/generate-muted-user-query'; -import { ApiError } from '../../error'; -import { generateBlockedUserQuery } from '../../common/generate-block-query'; - -export const meta = { - tags: ['account', 'notes', 'clips'], - - requireCredential: false as const, - - kind: 'read:account', - - params: { - clipId: { - validator: $.type(ID), - }, - - limit: { - validator: $.optional.num.range(1, 100), - default: 10 - }, - - sinceId: { - validator: $.optional.type(ID), - }, - - untilId: { - validator: $.optional.type(ID), - }, - }, - - errors: { - noSuchClip: { - message: 'No such clip.', - code: 'NO_SUCH_CLIP', - id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00' - } - }, - - res: { - type: 'array' as const, - optional: false as const, nullable: false as const, - items: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Note' - } - } -}; - -export default define(meta, async (ps, user) => { - const clip = await Clips.findOne({ - id: ps.clipId, - }); - - if (clip == null) { - throw new ApiError(meta.errors.noSuchClip); - } - - if (!clip.isPublic && (user == null || (clip.userId !== user.id))) { - throw new ApiError(meta.errors.noSuchClip); - } - - const clipQuery = ClipNotes.createQueryBuilder('joining') - .select('joining.noteId') - .where('joining.clipId = :clipId', { clipId: clip.id }); - - const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId) - .andWhere(`note.id IN (${ clipQuery.getQuery() })`) - .innerJoinAndSelect('note.user', 'user') - .leftJoinAndSelect('note.reply', 'reply') - .leftJoinAndSelect('note.renote', 'renote') - .leftJoinAndSelect('reply.user', 'replyUser') - .leftJoinAndSelect('renote.user', 'renoteUser') - .setParameters(clipQuery.getParameters()); - - if (user) { - generateVisibilityQuery(query, user); - generateMutedUserQuery(query, user); - generateBlockedUserQuery(query, user); - } - - const notes = await query - .take(ps.limit!) - .getMany(); - - return await Notes.packMany(notes, user); -}); diff --git a/src/server/api/endpoints/clips/show.ts b/src/server/api/endpoints/clips/show.ts deleted file mode 100644 index 8f245cd18e..0000000000 --- a/src/server/api/endpoints/clips/show.ts +++ /dev/null @@ -1,50 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ApiError } from '../../error'; -import { Clips } from '@/models/index'; - -export const meta = { - tags: ['clips', 'account'], - - requireCredential: false as const, - - kind: 'read:account', - - params: { - clipId: { - validator: $.type(ID), - }, - }, - - errors: { - noSuchClip: { - message: 'No such clip.', - code: 'NO_SUCH_CLIP', - id: 'c3c5fe33-d62c-44d2-9ea5-d997703f5c20' - }, - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Clip' - } -}; - -export default define(meta, async (ps, me) => { - // Fetch the clip - const clip = await Clips.findOne({ - id: ps.clipId, - }); - - if (clip == null) { - throw new ApiError(meta.errors.noSuchClip); - } - - if (!clip.isPublic && (me == null || (clip.userId !== me.id))) { - throw new ApiError(meta.errors.noSuchClip); - } - - return await Clips.pack(clip); -}); diff --git a/src/server/api/endpoints/clips/update.ts b/src/server/api/endpoints/clips/update.ts deleted file mode 100644 index 7f645560bb..0000000000 --- a/src/server/api/endpoints/clips/update.ts +++ /dev/null @@ -1,65 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../define'; -import { ApiError } from '../../error'; -import { Clips } from '@/models/index'; - -export const meta = { - tags: ['clips'], - - requireCredential: true as const, - - kind: 'write:account', - - params: { - clipId: { - validator: $.type(ID), - }, - - name: { - validator: $.str.range(1, 100), - }, - - isPublic: { - validator: $.optional.bool - }, - - description: { - validator: $.optional.nullable.str.range(1, 2048) - } - }, - - errors: { - noSuchClip: { - message: 'No such clip.', - code: 'NO_SUCH_CLIP', - id: 'b4d92d70-b216-46fa-9a3f-a8c811699257' - }, - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'Clip' - } -}; - -export default define(meta, async (ps, user) => { - // Fetch the clip - const clip = await Clips.findOne({ - id: ps.clipId, - userId: user.id - }); - - if (clip == null) { - throw new ApiError(meta.errors.noSuchClip); - } - - await Clips.update(clip.id, { - name: ps.name, - description: ps.description, - isPublic: ps.isPublic, - }); - - return await Clips.pack(clip.id); -}); |