Sharkey/src/server/api/endpoints/clips/create.ts

46 lines
856 B
TypeScript
Raw Normal View History

import $ from 'cafy';
import define from '../../define.js';
import { genId } from '@/misc/gen-id.js';
import { Clips } from '@/models/index.js';
export const meta = {
tags: ['clips'],
2020-02-15 14:33:32 +02:00
requireCredential: true as const,
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)
}
},
res: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'Clip'
}
};
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 05:04:54 +02:00
isPublic: ps.isPublic,
description: ps.description,
}).then(x => Clips.findOneOrFail(x.identifiers[0]));
return await Clips.pack(clip);
});