2022-09-17 21:27:08 +03:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2022-09-20 23:33:11 +03:00
|
|
|
import type { NotesRepository, ClipsRepository, ClipNotesRepository } from '@/models/index.js';
|
2022-09-17 21:27:08 +03:00
|
|
|
import { QueryService } from '@/core/QueryService.js';
|
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-02-27 04:07:39 +02:00
|
|
|
import { ApiError } from '../../error.js';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['account', 'notes', 'clips'],
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: false,
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
kind: 'read:account',
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchClip: {
|
2020-11-15 05:04:54 +02:00
|
|
|
message: 'No such clip.',
|
2020-01-29 21:37:25 +02:00
|
|
|
code: 'NO_SUCH_CLIP',
|
2021-12-09 16:58:30 +02:00
|
|
|
id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00',
|
|
|
|
},
|
2021-03-06 15:34:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 15:34:11 +02:00
|
|
|
items: {
|
2022-01-18 15:27:10 +02:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 16:58:30 +02:00
|
|
|
ref: 'Note',
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
clipId: { type: 'string', format: 'misskey:id' },
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
sinceId: { type: 'string', format: 'misskey:id' },
|
|
|
|
untilId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['clipId'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 19:12:50 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 21:27:08 +03:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.clipsRepository)
|
|
|
|
private clipsRepository: ClipsRepository,
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
@Inject(DI.notesRepository)
|
|
|
|
private notesRepository: NotesRepository,
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
@Inject(DI.clipNotesRepository)
|
|
|
|
private clipNotesRepository: ClipNotesRepository,
|
2020-11-15 10:32:29 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
private noteEntityService: NoteEntityService,
|
|
|
|
private queryService: QueryService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const clip = await this.clipsRepository.findOneBy({
|
|
|
|
id: ps.clipId,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (clip == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchClip);
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
if (!clip.isPublic && (me == null || (clip.userId !== me.id))) {
|
|
|
|
throw new ApiError(meta.errors.noSuchClip);
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
|
|
|
.innerJoin(this.clipNotesRepository.metadata.targetName, 'clipNote', 'clipNote.noteId = note.id')
|
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
|
|
|
.leftJoinAndSelect('user.avatar', 'avatar')
|
|
|
|
.leftJoinAndSelect('user.banner', 'banner')
|
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
|
|
|
.leftJoinAndSelect('replyUser.avatar', 'replyUserAvatar')
|
|
|
|
.leftJoinAndSelect('replyUser.banner', 'replyUserBanner')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
|
|
|
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
|
|
|
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner')
|
|
|
|
.andWhere('clipNote.clipId = :clipId', { clipId: clip.id });
|
|
|
|
|
|
|
|
if (me) {
|
|
|
|
this.queryService.generateVisibilityQuery(query, me);
|
|
|
|
this.queryService.generateMutedUserQuery(query, me);
|
|
|
|
this.queryService.generateBlockedUserQuery(query, me);
|
|
|
|
}
|
|
|
|
|
|
|
|
const notes = await query
|
|
|
|
.take(ps.limit)
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
return await this.noteEntityService.packMany(notes, me);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|