2020-01-29 21:37:25 +02:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../../define';
|
2021-03-23 10:43:07 +02:00
|
|
|
import { genId } from '@/misc/gen-id';
|
2020-01-29 21:37:25 +02:00
|
|
|
import { Clips } from '../../../../models';
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['clips'],
|
|
|
|
|
2020-02-15 14:33:32 +02:00
|
|
|
requireCredential: true as const,
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
kind: 'write:account',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
name: {
|
|
|
|
validator: $.str.range(1, 100)
|
2020-11-15 05:04:54 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
isPublic: {
|
|
|
|
validator: $.optional.bool
|
|
|
|
},
|
|
|
|
|
|
|
|
description: {
|
|
|
|
validator: $.optional.nullable.str.range(1, 2048)
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
},
|
2021-03-06 15:34:11 +02:00
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
ref: 'Clip'
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async (ps, user) => {
|
2021-03-24 04:05:37 +02:00
|
|
|
const clip = await Clips.insert({
|
2020-01-29 21:37:25 +02:00
|
|
|
id: genId(),
|
|
|
|
createdAt: new Date(),
|
|
|
|
userId: user.id,
|
|
|
|
name: ps.name,
|
2020-11-15 05:04:54 +02:00
|
|
|
isPublic: ps.isPublic,
|
|
|
|
description: ps.description,
|
2021-03-24 04:05:37 +02:00
|
|
|
}).then(x => Clips.findOneOrFail(x.identifiers[0]));
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
return await Clips.pack(clip);
|
|
|
|
});
|