hippofish/packages/backend/src/server/api/endpoints/clips/create.ts

47 lines
906 B
TypeScript
Raw Normal View History

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