Add search for files in drive

This commit is contained in:
Leah 2024-06-28 16:27:28 +02:00
parent 84e3eae77f
commit 2ebdc36c7a
3 changed files with 24 additions and 0 deletions

View file

@ -37,6 +37,7 @@ export const paramDef = {
folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
type: { type: 'string', nullable: true, pattern: /^[a-zA-Z\/\-*]+$/.toString().slice(1, -1) },
sort: { type: 'string', nullable: true, enum: ['+createdAt', '-createdAt', '+name', '-name', '+size', '-size', null] },
searchQuery: {type : 'string', default: '' }
},
required: [],
} as const;
@ -60,6 +61,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
query.andWhere('file.folderId IS NULL');
}
if (ps.searchQuery.length > 0) {
query.andWhere('file.name ILIKE :searchQuery OR file.comment ILIKE :searchQuery', { searchQuery: `%${ps.searchQuery}%` });
}
if (ps.type) {
if (ps.type.endsWith('/*')) {
query.andWhere('file.type like :type', { type: ps.type.replace('/*', '/') + '%' });

View file

@ -35,6 +35,7 @@ export const paramDef = {
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
searchQuery: {type : 'string', default: '' }
},
required: [],
} as const;
@ -58,6 +59,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
query.andWhere('folder.parentId IS NULL');
}
if (ps.searchQuery.length > 0) {
query.andWhere('folder.name ILIKE :searchQuery', { searchQuery: `%${ps.searchQuery}%` });
}
const folders = await query.limit(ps.limit).getMany();
return await Promise.all(folders.map(folder => this.driveFolderEntityService.pack(folder)));