dd1783f984
* Disable `import/no-default-export` properly * Disable `import/no-default-export`
72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import type { ClipsRepository, ClipFavoritesRepository } from '@/models/index.js';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { ApiError } from '../../error.js';
|
|
|
|
export const meta = {
|
|
tags: ['clip'],
|
|
|
|
requireCredential: true,
|
|
|
|
prohibitMoved: true,
|
|
|
|
kind: 'write:clip-favorite',
|
|
|
|
errors: {
|
|
noSuchClip: {
|
|
message: 'No such clip.',
|
|
code: 'NO_SUCH_CLIP',
|
|
id: '2603966e-b865-426c-94a7-af4a01241dc1',
|
|
},
|
|
|
|
notFavorited: {
|
|
message: 'You have not favorited the clip.',
|
|
code: 'NOT_FAVORITED',
|
|
id: '90c3a9e8-b321-4dae-bf57-2bf79bbcc187',
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
clipId: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['clipId'],
|
|
} as const;
|
|
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
|
constructor(
|
|
@Inject(DI.clipsRepository)
|
|
private clipsRepository: ClipsRepository,
|
|
|
|
@Inject(DI.clipFavoritesRepository)
|
|
private clipFavoritesRepository: ClipFavoritesRepository,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
const clip = await this.clipsRepository.findOneBy({ id: ps.clipId });
|
|
if (clip == null) {
|
|
throw new ApiError(meta.errors.noSuchClip);
|
|
}
|
|
|
|
const exist = await this.clipFavoritesRepository.findOneBy({
|
|
clipId: clip.id,
|
|
userId: me.id,
|
|
});
|
|
|
|
if (exist == null) {
|
|
throw new ApiError(meta.errors.notFavorited);
|
|
}
|
|
|
|
await this.clipFavoritesRepository.delete(exist.id);
|
|
});
|
|
}
|
|
}
|