2018-07-07 19:19:00 +09:00
|
|
|
import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
|
2018-07-17 04:36:44 +09:00
|
|
|
const ms = require('ms');
|
2018-03-29 20:32:18 +09:00
|
|
|
import { pack } from '../../../../../models/drive-file';
|
2018-04-08 04:02:12 +09:00
|
|
|
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
|
2018-06-18 14:28:43 +09:00
|
|
|
import { ILocalUser } from '../../../../../models/user';
|
2017-02-17 05:46:14 +09:00
|
|
|
|
2018-07-17 04:36:44 +09:00
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2018-08-29 06:59:43 +09:00
|
|
|
'ja-JP': 'ドライブに指定されたURLに存在するファイルをアップロードします。'
|
2018-07-17 04:36:44 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
limit: {
|
|
|
|
duration: ms('1hour'),
|
|
|
|
max: 10
|
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
kind: 'drive-write'
|
|
|
|
};
|
|
|
|
|
2017-02-17 05:46:14 +09:00
|
|
|
/**
|
|
|
|
* Create a file from a URL
|
|
|
|
*/
|
2018-07-06 02:58:29 +09:00
|
|
|
export default async (params: any, user: ILocalUser): Promise<any> => {
|
2017-02-17 05:46:14 +09:00
|
|
|
// Get 'url' parameter
|
2017-02-21 09:28:11 +09:00
|
|
|
// TODO: Validate this url
|
2018-05-02 18:06:16 +09:00
|
|
|
const [url, urlErr] = $.str.get(params.url);
|
2017-11-14 04:28:51 +09:00
|
|
|
if (urlErr) throw 'invalid url param';
|
2017-02-17 05:46:14 +09:00
|
|
|
|
2018-03-29 14:48:47 +09:00
|
|
|
// Get 'folderId' parameter
|
2018-07-05 23:36:07 +09:00
|
|
|
const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
|
2018-03-29 14:48:47 +09:00
|
|
|
if (folderIdErr) throw 'invalid folderId param';
|
2017-02-17 05:46:14 +09:00
|
|
|
|
2018-03-27 16:51:12 +09:00
|
|
|
return pack(await uploadFromUrl(url, user, folderId));
|
2017-11-14 04:28:51 +09:00
|
|
|
};
|