mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-14 21:53:08 +02:00
26 lines
709 B
TypeScript
26 lines
709 B
TypeScript
/**
|
|
* Module dependencies
|
|
*/
|
|
import $ from 'cafy';
|
|
import { pack } from '../../../../../models/drive-file';
|
|
import uploadFromUrl from '../../../../../drive/upload-from-url';
|
|
|
|
/**
|
|
* Create a file from a URL
|
|
*
|
|
* @param {any} params
|
|
* @param {any} user
|
|
* @return {Promise<any>}
|
|
*/
|
|
module.exports = async (params, user): Promise<any> => {
|
|
// Get 'url' parameter
|
|
// TODO: Validate this url
|
|
const [url, urlErr] = $(params.url).string().$;
|
|
if (urlErr) throw 'invalid url param';
|
|
|
|
// Get 'folderId' parameter
|
|
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
|
if (folderIdErr) throw 'invalid folderId param';
|
|
|
|
return pack(await uploadFromUrl(url, user, folderId));
|
|
};
|