mirror of
https://github.com/HeyPuter/puter
synced 2024-11-15 06:15:47 +00:00
Reject invalid types for puter.fs.upload() items or .write() data
Previously, this would crash in upload() when trying to iterate the `entries` array, which is undefined when the `items` parameter is an unsupported type.
This commit is contained in:
parent
a9c89cef19
commit
03fe3b6a0d
@ -123,6 +123,10 @@ const upload = async function(items, dirPath, options = {}){
|
||||
entries[i].fullPath = entries[i].name;
|
||||
}
|
||||
}
|
||||
// Anything else is invalid
|
||||
else {
|
||||
return error({ code: 'field_invalid', message: 'upload() items parameter is an invalid type' });
|
||||
}
|
||||
|
||||
// Will hold directories and files to be uploaded
|
||||
let dirs = [];
|
||||
|
@ -46,6 +46,11 @@ const write = async function (targetPath, data, options = {}) {
|
||||
if(!data)
|
||||
data = new File([data ?? ''], filename);
|
||||
|
||||
// data should be a File now. If it's not, it's an unsupported type
|
||||
if (!(data instanceof File)) {
|
||||
throw new Error({ code: 'field_invalid', message: 'write() data parameter is an invalid type' });
|
||||
}
|
||||
|
||||
// perform upload
|
||||
return this.upload(data, parent, options);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user