FoundKey/packages/backend/src/server/api/endpoints/drive/files/find.ts
Johann150 94d1cf75aa
server: unify drive object types in database
Minor adjustment: The 'name' columns have the same max length.

Major adjustment: Rename both columns to be "parentId" and update
all references of this name in the backend. API parameters are not
changed, since that would be an unnecessary breaking change.
2023-03-26 11:05:55 +02:00

44 lines
987 B
TypeScript

import { IsNull } from 'typeorm';
import { DriveFiles } from '@/models/index.js';
import define from '@/server/api/define.js';
export const meta = {
requireCredential: true,
tags: ['drive'],
kind: 'read:drive',
description: 'Search for a drive file by the given parameters.',
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'DriveFile',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
name: { type: 'string' },
folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
},
required: ['name'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => {
const files = await DriveFiles.findBy({
name: ps.name,
userId: user.id,
parentId: ps.folderId ?? IsNull(),
});
return await Promise.all(files.map(file => DriveFiles.pack(file, { self: true })));
});