summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/clips/create.ts
blob: b26c42c56ce912068fdc1f475b7aefe49f06c229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import $ from 'cafy';
import define from '../../define';
import { genId } from '../../../../misc/gen-id';
import { Clips } from '../../../../models';

export const meta = {
	tags: ['clips'],

	requireCredential: true as const,

	kind: 'write:account',

	params: {
		name: {
			validator: $.str.range(1, 100)
		},

		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.save({
		id: genId(),
		createdAt: new Date(),
		userId: user.id,
		name: ps.name,
		isPublic: ps.isPublic,
		description: ps.description,
	});

	return await Clips.pack(clip);
});