mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-04 21:58:22 +00:00
files -> fs
This commit is contained in:
1 parent
01aeaa207c
commit
7c88072489
1 file changed
+15
-9
+15
-9
@@ -266,7 +266,7 @@
|
|||||||
el.v2 = v2;
|
el.v2 = v2;
|
||||||
};
|
};
|
||||||
|
|
||||||
function handle_upload(el) {
|
function upload(el, is_ota) {
|
||||||
if (el.bound) return;
|
if (el.bound) return;
|
||||||
el.bound = true;
|
el.bound = true;
|
||||||
el.addEventListener("change", function (ev) {
|
el.addEventListener("change", function (ev) {
|
||||||
@@ -275,7 +275,7 @@
|
|||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsArrayBuffer(f);
|
reader.readAsArrayBuffer(f);
|
||||||
reader.onload = function () {
|
reader.onload = function () {
|
||||||
const url = `files/${encodeURIComponent(f.name)}`;
|
const url = is_ota ? 'api/ota' : `fs/${encodeURIComponent(f.name)}`;
|
||||||
let begin = Date.now(), body = reader.result, ok = false;
|
let begin = Date.now(), body = reader.result, ok = false;
|
||||||
// console.log(2, url, body);
|
// console.log(2, url, body);
|
||||||
fetch(url, { method: 'POST', body })
|
fetch(url, { method: 'POST', body })
|
||||||
@@ -290,6 +290,9 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handle_upload = el => upload(el, false);
|
||||||
|
const handle_ota = el => upload(el, true);
|
||||||
|
|
||||||
function substituteExpressions(text, context) {
|
function substituteExpressions(text, context) {
|
||||||
const expected = { string: 1, number: 1, boolean: 1 };
|
const expected = { string: 1, number: 1, boolean: 1 };
|
||||||
const f = (orig, expr) => {
|
const f = (orig, expr) => {
|
||||||
@@ -320,14 +323,17 @@
|
|||||||
if (v !== attr.value) attr.value = v;
|
if (v !== attr.value) attr.value = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const datakeys = { bind: 1, save: 1, cancel: 1, repeat: 1, upload: 1 };
|
//const datakeys = { bind: 1, save: 1, cancel: 1, repeat: 1, upload: 1, ota: 1 };
|
||||||
|
const handlers = {
|
||||||
|
bind: handle_bind,
|
||||||
|
save: handle_save,
|
||||||
|
cancel: handle_cancel,
|
||||||
|
repeat: handle_repeat,
|
||||||
|
upload: handle_upload,
|
||||||
|
ota: handle_ota,
|
||||||
|
};
|
||||||
for (const [key, val] of Object.entries(el.dataset)) {
|
for (const [key, val] of Object.entries(el.dataset)) {
|
||||||
if (!datakeys[key]) continue;
|
handlers[key]?.(el, val, context);
|
||||||
if (key == 'bind') handle_bind(el, val, context);
|
|
||||||
if (key == 'save') handle_save(el, val.split(/\s*,\s*/));
|
|
||||||
if (key == 'cancel') handle_cancel(el, val.split(/\s*,\s*/));
|
|
||||||
if (key == 'repeat') handle_repeat(el, val, context);
|
|
||||||
if (key == 'upload') handle_upload(el);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user