yumechi-no-kuni/src/server/api/endpoints/drive/files/upload_from_url.ts

42 lines
999 B
TypeScript
Raw Normal View History

2018-11-01 13:32:24 -05:00
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
2018-07-16 14:36:44 -05:00
const ms = require('ms');
2018-03-29 06:32:18 -05:00
import { pack } from '../../../../../models/drive-file';
2018-04-07 14:02:12 -05:00
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
2018-06-18 00:28:43 -05:00
import { ILocalUser } from '../../../../../models/user';
2018-11-01 13:32:24 -05:00
import getParams from '../../../get-params';
2017-02-16 14:46:14 -06:00
2018-07-16 14:36:44 -05:00
export const meta = {
desc: {
2018-08-28 16:59:43 -05:00
'ja-JP': 'ドライブに指定されたURLに存在するファイルをアップロードします。'
2018-07-16 14:36:44 -05:00
},
limit: {
duration: ms('1hour'),
max: 10
},
requireCredential: true,
2018-11-01 13:32:24 -05:00
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
},
}
2018-07-16 14:36:44 -05:00
};
2018-07-05 12:58:29 -05:00
export default async (params: any, user: ILocalUser): Promise<any> => {
2018-11-01 13:32:24 -05:00
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
2017-02-16 14:46:14 -06:00
2018-11-01 13:32:24 -05:00
return pack(await uploadFromUrl(ps.url, user, ps.folderId));
2017-11-13 13:28:51 -06:00
};