sharkey/src/server/api/endpoints/drive/files/upload_from_url.ts

23 lines
645 B
TypeScript
Raw Normal View History

2017-02-17 05:46:14 +09:00
/**
* Module dependencies
*/
2017-03-09 03:50:09 +09:00
import $ from 'cafy';
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';
2017-02-17 05:46:14 +09:00
/**
* Create a file from a URL
*/
2017-11-14 04:28:51 +09:00
module.exports = async (params, user): 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
2017-03-09 03:50:09 +09:00
const [url, urlErr] = $(params.url).string().$;
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
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
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
};