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