From f6154dc0af1a0d65819e87240f4385f9573095cb Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 30 Jan 2020 04:37:25 +0900 Subject: v12 (#5712) Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com> --- src/server/api/endpoints/clips/update.ts | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/server/api/endpoints/clips/update.ts (limited to 'src/server/api/endpoints/clips/update.ts') diff --git a/src/server/api/endpoints/clips/update.ts b/src/server/api/endpoints/clips/update.ts new file mode 100644 index 0000000000..d1c31eb8e6 --- /dev/null +++ b/src/server/api/endpoints/clips/update.ts @@ -0,0 +1,49 @@ +import $ from 'cafy'; +import { ID } from '../../../../misc/cafy-id'; +import define from '../../define'; +import { ApiError } from '../../error'; +import { Clips } from '../../../../models'; + +export const meta = { + tags: ['clips'], + + requireCredential: true, + + kind: 'write:account', + + params: { + clipId: { + validator: $.type(ID), + }, + + name: { + validator: $.str.range(1, 100), + } + }, + + errors: { + noSuchClip: { + message: 'No such clip.', + code: 'NO_SUCH_CLIP', + id: 'b4d92d70-b216-46fa-9a3f-a8c811699257' + }, + } +}; + +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 + }); + + return await Clips.pack(clip.id); +}); -- cgit v1.2.3-freya