2020-01-29 20:37:25 +01:00
|
|
|
import $ from 'cafy';
|
2021-08-19 14:55:45 +02:00
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
import define from '../../define';
|
|
|
|
import { ApiError } from '../../error';
|
|
|
|
import { Clips } from '@/models/index';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['clips'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
kind: 'write:account',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
clipId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
name: {
|
|
|
|
validator: $.str.range(1, 100),
|
2020-11-15 04:34:47 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
isPublic: {
|
2021-12-09 15:58:30 +01:00
|
|
|
validator: $.optional.bool,
|
2020-11-15 04:34:47 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
description: {
|
2021-12-09 15:58:30 +01:00
|
|
|
validator: $.optional.nullable.str.range(1, 2048),
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchClip: {
|
|
|
|
message: 'No such clip.',
|
|
|
|
code: 'NO_SUCH_CLIP',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: 'b4d92d70-b216-46fa-9a3f-a8c811699257',
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 15:58:30 +01:00
|
|
|
ref: 'Clip',
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2020-01-29 20:37:25 +01:00
|
|
|
export default define(meta, async (ps, user) => {
|
|
|
|
// Fetch the clip
|
|
|
|
const clip = await Clips.findOne({
|
|
|
|
id: ps.clipId,
|
2021-12-09 15:58:30 +01:00
|
|
|
userId: user.id,
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if (clip == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
await Clips.update(clip.id, {
|
2020-11-15 04:34:47 +01:00
|
|
|
name: ps.name,
|
|
|
|
description: ps.description,
|
|
|
|
isPublic: ps.isPublic,
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return await Clips.pack(clip.id);
|
|
|
|
});
|