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