2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-20 22:33:11 +02:00
|
|
|
import type { ClipsRepository } from '@/models/index.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { ClipEntityService } from '@/core/entities/ClipEntityService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { ApiError } from '../../error.js';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['clips'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: true,
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
kind: 'write:account',
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchClip: {
|
|
|
|
message: 'No such clip.',
|
|
|
|
code: 'NO_SUCH_CLIP',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: 'b4d92d70-b216-46fa-9a3f-a8c811699257',
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 15:58:30 +01:00
|
|
|
ref: 'Clip',
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
clipId: { type: 'string', format: 'misskey:id' },
|
|
|
|
name: { type: 'string', minLength: 1, maxLength: 100 },
|
|
|
|
isPublic: { type: 'boolean' },
|
|
|
|
description: { type: 'string', nullable: true, minLength: 1, maxLength: 2048 },
|
|
|
|
},
|
|
|
|
required: ['clipId', 'name'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 20:27:08 +02:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.clipsRepository)
|
|
|
|
private clipsRepository: ClipsRepository,
|
|
|
|
|
|
|
|
private clipEntityService: ClipEntityService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
// Fetch the clip
|
|
|
|
const clip = await this.clipsRepository.findOneBy({
|
|
|
|
id: ps.clipId,
|
|
|
|
userId: me.id,
|
|
|
|
});
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
if (clip == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchClip);
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
await this.clipsRepository.update(clip.id, {
|
|
|
|
name: ps.name,
|
|
|
|
description: ps.description,
|
|
|
|
isPublic: ps.isPublic,
|
|
|
|
});
|
|
|
|
|
2023-03-16 09:24:49 +01:00
|
|
|
return await this.clipEntityService.pack(clip.id, me);
|
2022-09-17 20:27:08 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|