diff options
Diffstat (limited to 'src/server/api/endpoints/gallery/posts')
| -rw-r--r-- | src/server/api/endpoints/gallery/posts/create.ts | 77 | ||||
| -rw-r--r-- | src/server/api/endpoints/gallery/posts/delete.ts | 40 | ||||
| -rw-r--r-- | src/server/api/endpoints/gallery/posts/like.ts | 71 | ||||
| -rw-r--r-- | src/server/api/endpoints/gallery/posts/show.ts | 43 | ||||
| -rw-r--r-- | src/server/api/endpoints/gallery/posts/unlike.ts | 54 | ||||
| -rw-r--r-- | src/server/api/endpoints/gallery/posts/update.ts | 82 |
6 files changed, 0 insertions, 367 deletions
diff --git a/src/server/api/endpoints/gallery/posts/create.ts b/src/server/api/endpoints/gallery/posts/create.ts deleted file mode 100644 index 38b487e6ea..0000000000 --- a/src/server/api/endpoints/gallery/posts/create.ts +++ /dev/null @@ -1,77 +0,0 @@ -import $ from 'cafy'; -import * as ms from 'ms'; -import define from '../../../define'; -import { ID } from '../../../../../misc/cafy-id'; -import { DriveFiles, GalleryPosts } from '@/models/index'; -import { genId } from '../../../../../misc/gen-id'; -import { GalleryPost } from '@/models/entities/gallery-post'; -import { ApiError } from '../../../error'; -import { DriveFile } from '@/models/entities/drive-file'; - -export const meta = { - tags: ['gallery'], - - requireCredential: true as const, - - kind: 'write:gallery', - - limit: { - duration: ms('1hour'), - max: 300 - }, - - params: { - title: { - validator: $.str.min(1), - }, - - description: { - validator: $.optional.nullable.str, - }, - - fileIds: { - validator: $.arr($.type(ID)).unique().range(1, 32), - }, - - isSensitive: { - validator: $.optional.bool, - default: false, - }, - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'GalleryPost', - }, - - errors: { - - } -}; - -export default define(meta, async (ps, user) => { - const files = (await Promise.all(ps.fileIds.map(fileId => - DriveFiles.findOne({ - id: fileId, - userId: user.id - }) - ))).filter((file): file is DriveFile => file != null); - - if (files.length === 0) { - throw new Error(); - } - - const post = await GalleryPosts.insert(new GalleryPost({ - id: genId(), - createdAt: new Date(), - updatedAt: new Date(), - title: ps.title, - description: ps.description, - userId: user.id, - isSensitive: ps.isSensitive, - fileIds: files.map(file => file.id) - })).then(x => GalleryPosts.findOneOrFail(x.identifiers[0])); - - return await GalleryPosts.pack(post, user); -}); diff --git a/src/server/api/endpoints/gallery/posts/delete.ts b/src/server/api/endpoints/gallery/posts/delete.ts deleted file mode 100644 index e5b7c07f2f..0000000000 --- a/src/server/api/endpoints/gallery/posts/delete.ts +++ /dev/null @@ -1,40 +0,0 @@ -import $ from 'cafy'; -import define from '../../../define'; -import { ApiError } from '../../../error'; -import { GalleryPosts } from '@/models/index'; -import { ID } from '@/misc/cafy-id'; - -export const meta = { - tags: ['gallery'], - - requireCredential: true as const, - - kind: 'write:gallery', - - params: { - postId: { - validator: $.type(ID), - }, - }, - - errors: { - noSuchPost: { - message: 'No such post.', - code: 'NO_SUCH_POST', - id: 'ae52f367-4bd7-4ecd-afc6-5672fff427f5' - }, - } -}; - -export default define(meta, async (ps, user) => { - const post = await GalleryPosts.findOne({ - id: ps.postId, - userId: user.id, - }); - - if (post == null) { - throw new ApiError(meta.errors.noSuchPost); - } - - await GalleryPosts.delete(post.id); -}); diff --git a/src/server/api/endpoints/gallery/posts/like.ts b/src/server/api/endpoints/gallery/posts/like.ts deleted file mode 100644 index 81a25c0ad1..0000000000 --- a/src/server/api/endpoints/gallery/posts/like.ts +++ /dev/null @@ -1,71 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../../define'; -import { ApiError } from '../../../error'; -import { GalleryPosts, GalleryLikes } from '@/models/index'; -import { genId } from '@/misc/gen-id'; - -export const meta = { - tags: ['gallery'], - - requireCredential: true as const, - - kind: 'write:gallery-likes', - - params: { - postId: { - validator: $.type(ID), - } - }, - - errors: { - noSuchPost: { - message: 'No such post.', - code: 'NO_SUCH_POST', - id: '56c06af3-1287-442f-9701-c93f7c4a62ff' - }, - - yourPost: { - message: 'You cannot like your post.', - code: 'YOUR_POST', - id: 'f78f1511-5ebc-4478-a888-1198d752da68' - }, - - alreadyLiked: { - message: 'The post has already been liked.', - code: 'ALREADY_LIKED', - id: '40e9ed56-a59c-473a-bf3f-f289c54fb5a7' - }, - } -}; - -export default define(meta, async (ps, user) => { - const post = await GalleryPosts.findOne(ps.postId); - if (post == null) { - throw new ApiError(meta.errors.noSuchPost); - } - - if (post.userId === user.id) { - throw new ApiError(meta.errors.yourPost); - } - - // if already liked - const exist = await GalleryLikes.findOne({ - postId: post.id, - userId: user.id - }); - - if (exist != null) { - throw new ApiError(meta.errors.alreadyLiked); - } - - // Create like - await GalleryLikes.insert({ - id: genId(), - createdAt: new Date(), - postId: post.id, - userId: user.id - }); - - GalleryPosts.increment({ id: post.id }, 'likedCount', 1); -}); diff --git a/src/server/api/endpoints/gallery/posts/show.ts b/src/server/api/endpoints/gallery/posts/show.ts deleted file mode 100644 index 93852a5f8d..0000000000 --- a/src/server/api/endpoints/gallery/posts/show.ts +++ /dev/null @@ -1,43 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../../define'; -import { ApiError } from '../../../error'; -import { GalleryPosts } from '@/models/index'; - -export const meta = { - tags: ['gallery'], - - requireCredential: false as const, - - params: { - postId: { - validator: $.type(ID), - }, - }, - - errors: { - noSuchPost: { - message: 'No such post.', - code: 'NO_SUCH_POST', - id: '1137bf14-c5b0-4604-85bb-5b5371b1cd45' - }, - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'GalleryPost' - } -}; - -export default define(meta, async (ps, me) => { - const post = await GalleryPosts.findOne({ - id: ps.postId, - }); - - if (post == null) { - throw new ApiError(meta.errors.noSuchPost); - } - - return await GalleryPosts.pack(post, me); -}); diff --git a/src/server/api/endpoints/gallery/posts/unlike.ts b/src/server/api/endpoints/gallery/posts/unlike.ts deleted file mode 100644 index 0347cdf79e..0000000000 --- a/src/server/api/endpoints/gallery/posts/unlike.ts +++ /dev/null @@ -1,54 +0,0 @@ -import $ from 'cafy'; -import { ID } from '@/misc/cafy-id'; -import define from '../../../define'; -import { ApiError } from '../../../error'; -import { GalleryPosts, GalleryLikes } from '@/models/index'; - -export const meta = { - tags: ['gallery'], - - requireCredential: true as const, - - kind: 'write:gallery-likes', - - params: { - postId: { - validator: $.type(ID), - } - }, - - errors: { - noSuchPost: { - message: 'No such post.', - code: 'NO_SUCH_POST', - id: 'c32e6dd0-b555-4413-925e-b3757d19ed84' - }, - - notLiked: { - message: 'You have not liked that post.', - code: 'NOT_LIKED', - id: 'e3e8e06e-be37-41f7-a5b4-87a8250288f0' - }, - } -}; - -export default define(meta, async (ps, user) => { - const post = await GalleryPosts.findOne(ps.postId); - if (post == null) { - throw new ApiError(meta.errors.noSuchPost); - } - - const exist = await GalleryLikes.findOne({ - postId: post.id, - userId: user.id - }); - - if (exist == null) { - throw new ApiError(meta.errors.notLiked); - } - - // Delete like - await GalleryLikes.delete(exist.id); - - GalleryPosts.decrement({ id: post.id }, 'likedCount', 1); -}); diff --git a/src/server/api/endpoints/gallery/posts/update.ts b/src/server/api/endpoints/gallery/posts/update.ts deleted file mode 100644 index 54eea130d3..0000000000 --- a/src/server/api/endpoints/gallery/posts/update.ts +++ /dev/null @@ -1,82 +0,0 @@ -import $ from 'cafy'; -import * as ms from 'ms'; -import define from '../../../define'; -import { ID } from '../../../../../misc/cafy-id'; -import { DriveFiles, GalleryPosts } from '@/models/index'; -import { GalleryPost } from '@/models/entities/gallery-post'; -import { ApiError } from '../../../error'; -import { DriveFile } from '@/models/entities/drive-file'; - -export const meta = { - tags: ['gallery'], - - requireCredential: true as const, - - kind: 'write:gallery', - - limit: { - duration: ms('1hour'), - max: 300 - }, - - params: { - postId: { - validator: $.type(ID), - }, - - title: { - validator: $.str.min(1), - }, - - description: { - validator: $.optional.nullable.str, - }, - - fileIds: { - validator: $.arr($.type(ID)).unique().range(1, 32), - }, - - isSensitive: { - validator: $.optional.bool, - default: false, - }, - }, - - res: { - type: 'object' as const, - optional: false as const, nullable: false as const, - ref: 'GalleryPost', - }, - - errors: { - - } -}; - -export default define(meta, async (ps, user) => { - const files = (await Promise.all(ps.fileIds.map(fileId => - DriveFiles.findOne({ - id: fileId, - userId: user.id - }) - ))).filter((file): file is DriveFile => file != null); - - if (files.length === 0) { - throw new Error(); - } - - await GalleryPosts.update({ - id: ps.postId, - userId: user.id, - }, { - updatedAt: new Date(), - title: ps.title, - description: ps.description, - isSensitive: ps.isSensitive, - fileIds: files.map(file => file.id) - }); - - const post = await GalleryPosts.findOneOrFail(ps.postId); - - return await GalleryPosts.pack(post, user); -}); |