Sharkey/src/server/api/endpoints/drive/files/upload_from_url.ts
2018-04-27 19:12:15 +09:00

22 lines
698 B
TypeScript

/**
* Module dependencies
*/
import $ from 'cafy'; import ID from '../../../../../cafy-id';
import { pack } from '../../../../../models/drive-file';
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
/**
* Create a file from a URL
*/
module.exports = async (params, user): Promise<any> => {
// Get 'url' parameter
// TODO: Validate this url
const [url, urlErr] = $(params.url).string().get();
if (urlErr) throw 'invalid url param';
// Get 'folderId' parameter
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).get();
if (folderIdErr) throw 'invalid folderId param';
return pack(await uploadFromUrl(url, user, folderId));
};