server: add pagination to file attachment timeline

As a side effect this also makes the notes appear in chronological order.

Changelog: Changed
This commit is contained in:
Johann150 2023-03-27 20:46:26 +02:00
parent 3747d7ecb1
commit 6179b2e5f0
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -1,6 +1,7 @@
import { DriveFiles, Notes } from '@/models/index.js';
import define from '@/server/api/define.js';
import { ApiError } from '@/server/api/error.js';
import { makePaginationQuery } from '@/server/api/common/make-pagination-query.js';
export const meta = {
tags: ['drive', 'notes'],
@ -28,6 +29,9 @@ export const paramDef = {
type: 'object',
properties: {
fileId: { type: 'string', format: 'misskey:id' },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
},
required: ['fileId'],
} as const;
@ -42,8 +46,13 @@ export default define(meta, paramDef, async (ps, user) => {
if (file == null) throw new ApiError('NO_SUCH_FILE');
const notes = await Notes.createQueryBuilder('note')
.where(':file = ANY(note.fileIds)', { file: file.id })
const notes = await makePaginationQuery(
Notes.createQueryBuilder('note'),
ps.sinceId,
ps.untilId,
)
.andWhere(':file = ANY(note.fileIds)', { file: file.id })
.take(ps.limit)
.getMany();
return await Notes.packMany(notes, user, {