diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2021-04-26 11:10:45 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2021-04-26 11:10:45 +0900 |
| commit | 42539575a659a6dbf165f0e9c20495a748ce61b6 (patch) | |
| tree | bfa4b0a60966f57c3842a5e7ba416550ef440b5c /src/server/api/endpoints/gallery/posts/update.ts | |
| parent | :art: (diff) | |
| download | sharkey-42539575a659a6dbf165f0e9c20495a748ce61b6.tar.gz sharkey-42539575a659a6dbf165f0e9c20495a748ce61b6.tar.bz2 sharkey-42539575a659a6dbf165f0e9c20495a748ce61b6.zip | |
ギャラリー投稿の編集と削除
Diffstat (limited to 'src/server/api/endpoints/gallery/posts/update.ts')
| -rw-r--r-- | src/server/api/endpoints/gallery/posts/update.ts | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/server/api/endpoints/gallery/posts/update.ts b/src/server/api/endpoints/gallery/posts/update.ts new file mode 100644 index 0000000000..c8bb8d48c9 --- /dev/null +++ b/src/server/api/endpoints/gallery/posts/update.ts @@ -0,0 +1,81 @@ +import $ from 'cafy'; +import * as ms from 'ms'; +import define from '../../../define'; +import { ID } from '../../../../../misc/cafy-id'; +import { DriveFiles, GalleryPosts } from '../../../../../models'; +import { GalleryPost } from '../../../../../models/entities/gallery-post'; +import { ApiError } from '../../../error'; + +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 != 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); +}); |