yumechi-no-kuni/src/server/api/endpoints/drive/files/upload_from_url.ts
2018-11-02 03:32:24 +09:00

41 lines
999 B
TypeScript

import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
const ms = require('ms');
import { pack } from '../../../../../models/drive-file';
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
import { ILocalUser } from '../../../../../models/user';
import getParams from '../../../get-params';
export const meta = {
desc: {
'ja-JP': 'ドライブに指定されたURLに存在するファイルをアップロードします。'
},
limit: {
duration: ms('1hour'),
max: 10
},
requireCredential: true,
kind: 'drive-write',
params: {
url: {
// TODO: Validate this url
validator: $.str,
},
folderId: {
validator: $.type(ID).optional.nullable,
default: null as any as any,
transform: transform
},
}
};
export default async (params: any, user: ILocalUser): Promise<any> => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
return pack(await uploadFromUrl(ps.url, user, ps.folderId));
};