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