@cocreate/file
Advanced tools
Comparing version 1.17.5 to 1.18.0
@@ -0,1 +1,13 @@ | ||
# [1.18.0](https://github.com/CoCreate-app/CoCreate-file/compare/v1.17.5...v1.18.0) (2024-08-24) | ||
### Bug Fixes | ||
* handle file.id when setFile() rendering. ([f9a561b](https://github.com/CoCreate-app/CoCreate-file/commit/f9a561b325ae0b8fe964b11d192c09ba2d144e4f)) | ||
### Features | ||
* import file from url ([c073276](https://github.com/CoCreate-app/CoCreate-file/commit/c073276894009a04fdf59e3bebabbd34bea3f55b)) | ||
## [1.17.5](https://github.com/CoCreate-app/CoCreate-file/compare/v1.17.4...v1.17.5) (2024-06-19) | ||
@@ -2,0 +14,0 @@ |
{ | ||
"name": "@cocreate/file", | ||
"version": "1.17.5", | ||
"version": "1.18.0", | ||
"description": "A versatile, configurable headless file uploader supporting local and server operations. Accessible via a JavaScript API and HTML5 attributes, it provides seamless file reading, writing, and uploading with fallbacks to the standard HTML5 file input API. Ideal for developers needing robust file management in headless environments.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -349,2 +349,4 @@ /******************************************************************************** | ||
for (let i = 0; i < files.length; i++) { | ||
if (!files[i].id) | ||
files[i].id = files[i].pathname | ||
files[i].input = element | ||
@@ -805,2 +807,54 @@ selected.set(files[i].id, files[i]) | ||
// TODO: handled by import? if value is a valid url get file by url? | ||
async function importURL(action) { | ||
try { | ||
let element = action.element | ||
let url = element.getAttribute('url') | ||
if (!url) { | ||
element = action.form.querySelector('[import-url]') | ||
if (!element) | ||
return | ||
url = element.getValue() | ||
if (!url) | ||
return | ||
} | ||
const urlObject = new URL(url); | ||
const filename = urlObject.pathname.split('/').pop(); | ||
const file = { | ||
src: url, | ||
name: filename, | ||
directory: '/', | ||
path: '/', | ||
pathname: '/' + filename | ||
}; | ||
await getCustomData(file) | ||
let data = await Crud.socket.send({ | ||
method: 'importUrl', | ||
file, | ||
broadcast: false, | ||
broadcastClient: false | ||
}) | ||
let queriedElements = queryElements({ element, prefix: 'import-url' }) | ||
if (queriedElements) { | ||
for (let queriedElement of queriedElements) | ||
queriedElement.setValue(data.file) | ||
} | ||
document.dispatchEvent(new CustomEvent(action.name, { | ||
detail: {} | ||
})); | ||
} catch (error) { | ||
console.error('Error importing file from URL:', error); | ||
throw error; | ||
} | ||
} | ||
async function fileRenderAction(action) { | ||
@@ -918,3 +972,3 @@ const element = action.element | ||
{ | ||
name: ["upload", "download", "saveLocally", "asveAs", "import", "export"], | ||
name: ["upload", "download", "saveLocally", "asveAs", "import", "export", "importUrl"], | ||
callback: (action) => { | ||
@@ -929,2 +983,4 @@ if (action.name === 'upload') | ||
Import(action.element) | ||
} else if (action.name === 'importUrl') { | ||
importURL(action) | ||
} else { | ||
@@ -931,0 +987,0 @@ // Something... |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
154763
1422