良い感じに
This commit is contained in:
parent
1e4a86da8e
commit
1744316656
8 changed files with 76 additions and 50 deletions
|
@ -1,8 +1,36 @@
|
|||
import * as fs from 'fs';
|
||||
const ms = require('ms');
|
||||
import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
|
||||
import { validateFileName, pack } from '../../../../../models/drive-file';
|
||||
import create from '../../../../../services/drive/add-file';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
ja: 'ドライブにファイルをアップロードします。'
|
||||
},
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
limit: {
|
||||
duration: ms('1hour'),
|
||||
max: 100
|
||||
},
|
||||
|
||||
withFile: true,
|
||||
|
||||
kind: 'drive-write',
|
||||
|
||||
params: {
|
||||
folderId: $.type(ID).optional.nullable.note({
|
||||
default: null,
|
||||
desc: {
|
||||
ja: 'フォルダID'
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a file
|
||||
|
@ -27,17 +55,19 @@ export default async (file: any, params: any, user: ILocalUser): Promise<any> =>
|
|||
name = null;
|
||||
}
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
function cleanup() {
|
||||
fs.unlink(file.path, () => {});
|
||||
}
|
||||
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) {
|
||||
cleanup();
|
||||
throw psErr;
|
||||
}
|
||||
|
||||
try {
|
||||
// Create file
|
||||
const driveFile = await create(user, file.path, name, null, folderId);
|
||||
const driveFile = await create(user, file.path, name, null, ps.folderId);
|
||||
|
||||
cleanup();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue