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:
parent
3747d7ecb1
commit
6179b2e5f0
1 changed files with 11 additions and 2 deletions
|
@ -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, {
|
||||
|
|
Loading…
Reference in a new issue