2018-07-07 12:19:00 +02:00
|
|
|
import $ from 'cafy'; import ID 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';
|
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,
|
|
|
|
|
|
|
|
kind: 'drive-write'
|
|
|
|
};
|
|
|
|
|
2017-02-16 21:46:14 +01:00
|
|
|
/**
|
|
|
|
* Create a file from a URL
|
|
|
|
*/
|
2018-07-05 19:58:29 +02:00
|
|
|
export default async (params: any, user: ILocalUser): Promise<any> => {
|
2017-02-16 21:46:14 +01:00
|
|
|
// Get 'url' parameter
|
2017-02-21 01:28:11 +01:00
|
|
|
// TODO: Validate this url
|
2018-05-02 11:06:16 +02:00
|
|
|
const [url, urlErr] = $.str.get(params.url);
|
2017-11-13 20:28:51 +01:00
|
|
|
if (urlErr) throw 'invalid url param';
|
2017-02-16 21:46:14 +01:00
|
|
|
|
2018-03-29 07:48:47 +02:00
|
|
|
// Get 'folderId' parameter
|
2018-07-05 16:36:07 +02:00
|
|
|
const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
|
2018-03-29 07:48:47 +02:00
|
|
|
if (folderIdErr) throw 'invalid folderId param';
|
2017-02-16 21:46:14 +01:00
|
|
|
|
2018-03-27 09:51:12 +02:00
|
|
|
return pack(await uploadFromUrl(url, user, folderId));
|
2017-11-13 20:28:51 +01:00
|
|
|
};
|