a07d753da8
* Update api document in admin/announcements * Update api document in announcements * Update api document in i/read-announcements * Update api document in username/available * Update api document & Fix typo in API 403 error * Update api document * Update api document * Update api document * Fix API permission definition * Update api document * Update api document * Update api document * Update api document * Update api document * Update api document * Update api document * Update api document * Fix bug in users (api) * Apply reviews #6757 * Apply reviews #6757 Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
88 lines
2.0 KiB
TypeScript
88 lines
2.0 KiB
TypeScript
import $ from 'cafy';
|
|
import { ID } from '../../../../misc/cafy-id';
|
|
import define from '../../define';
|
|
import { ClipNotes, Clips, Notes } from '../../../../models';
|
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
|
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
|
|
import { generateMutedUserQuery } from '../../common/generate-muted-user-query';
|
|
import { ApiError } from '../../error';
|
|
|
|
export const meta = {
|
|
tags: ['account', 'notes', 'clips'],
|
|
|
|
requireCredential: false as const,
|
|
|
|
kind: 'read:account',
|
|
|
|
params: {
|
|
clipId: {
|
|
validator: $.type(ID),
|
|
},
|
|
|
|
limit: {
|
|
validator: $.optional.num.range(1, 100),
|
|
default: 10
|
|
},
|
|
|
|
sinceId: {
|
|
validator: $.optional.type(ID),
|
|
},
|
|
|
|
untilId: {
|
|
validator: $.optional.type(ID),
|
|
},
|
|
},
|
|
|
|
errors: {
|
|
noSuchClip: {
|
|
message: 'No such clip.',
|
|
code: 'NO_SUCH_CLIP',
|
|
id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00'
|
|
}
|
|
},
|
|
|
|
res: {
|
|
type: 'array' as const,
|
|
optional: false as const, nullable: false as const,
|
|
items: {
|
|
type: 'object' as const,
|
|
optional: false as const, nullable: false as const,
|
|
ref: 'Note'
|
|
}
|
|
}
|
|
};
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
const clip = await Clips.findOne({
|
|
id: ps.clipId,
|
|
});
|
|
|
|
if (clip == null) {
|
|
throw new ApiError(meta.errors.noSuchClip);
|
|
}
|
|
|
|
if (!clip.isPublic && (user == null || (clip.userId !== user.id))) {
|
|
throw new ApiError(meta.errors.noSuchClip);
|
|
}
|
|
|
|
const clipQuery = ClipNotes.createQueryBuilder('joining')
|
|
.select('joining.noteId')
|
|
.where('joining.clipId = :clipId', { clipId: clip.id });
|
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
|
.andWhere(`note.id IN (${ clipQuery.getQuery() })`)
|
|
.leftJoinAndSelect('note.user', 'user')
|
|
.setParameters(clipQuery.getParameters());
|
|
|
|
if (user) {
|
|
generateVisibilityQuery(query, user);
|
|
generateMutedUserQuery(query, user);
|
|
}
|
|
|
|
const notes = await query
|
|
.take(ps.limit!)
|
|
.getMany();
|
|
|
|
return await Notes.packMany(notes, user);
|
|
});
|