forked from FoundKeyGang/FoundKey
Johann150
94d1cf75aa
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.
44 lines
987 B
TypeScript
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 })));
|
|
});
|