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