directus-extension-file-import-operation
Version:
A Directus extension that adds a custom operation to import files from a remote URL.
2 lines (1 loc) • 549 B
JavaScript
;var r={id:"file-import",handler:async(r,e)=>{const i=r.importUrl;if(!i)throw JSON.stringify({error:"Import URL is required."});const{services:t}=e;let s,o;try{s=new t.FilesService({knex:e.database,schema:await e.getSchema()})}catch(r){throw JSON.stringify({error:"Error creating file service",errorDetails:r.message?r.message:r})}try{o=await s.importOne(i)}catch(r){throw JSON.stringify({error:"Error importing file",errorDetails:r.message?r.message:r})}if(!o)throw JSON.stringify({error:"File not found"});return o}};module.exports=r;