reworked file api
This commit is contained in:
parent
9dbfd1ac61
commit
62f8f4edf0
|
|
@ -90,14 +90,14 @@ function DeleteFile() {
|
||||||
cancel: true,
|
cancel: true,
|
||||||
persistent: true
|
persistent: true
|
||||||
}).onOk(() => {
|
}).onOk(() => {
|
||||||
const dialog = Dialog.create({ message: 'Waiting for delete finished...', progress: true, persistent: true, ok: false, style: 'border: none; box-shadow: none;' })
|
const dialog = Dialog.create({ message: `Deleting file "${selected.value[0].name}"...`, progress: true, persistent: true, ok: false, style: 'border: none; box-shadow: none;' })
|
||||||
|
|
||||||
PostData({
|
PostData({
|
||||||
raw_data: {
|
raw_data: {
|
||||||
opertype: 2,
|
opertype: 2,
|
||||||
operphase: 3,
|
part: 0,
|
||||||
|
parts: 1,
|
||||||
mem_object: selected.value[0].name,
|
mem_object: selected.value[0].name,
|
||||||
offset: 0,
|
|
||||||
size: 0
|
size: 0
|
||||||
}
|
}
|
||||||
}, 1, 0, () => { PostData(data, 2, 0, () => { dialog.hide(); }) })
|
}, 1, 0, () => { PostData(data, 2, 0, () => { dialog.hide(); }) })
|
||||||
|
|
|
||||||
42
network.js
42
network.js
|
|
@ -8,15 +8,11 @@ let MessIdCounter = 1;
|
||||||
|
|
||||||
const BLOCK_SIZE = 5120;
|
const BLOCK_SIZE = 5120;
|
||||||
function ReceiveChunk(cur, total, name) {
|
function ReceiveChunk(cur, total, name) {
|
||||||
let foper;
|
|
||||||
if (total == 1) foper = 3;
|
|
||||||
else if (cur == 0) foper = 1;
|
|
||||||
else if (cur == (total - 1)) foper = 2;
|
|
||||||
else foper = 0;
|
|
||||||
let data = {
|
let data = {
|
||||||
raw_data: {
|
raw_data: {
|
||||||
opertype: 1,
|
opertype: 1,
|
||||||
operphase: foper,
|
part: cur,
|
||||||
|
parts: total,
|
||||||
mem_object: name,
|
mem_object: name,
|
||||||
size: BLOCK_SIZE,
|
size: BLOCK_SIZE,
|
||||||
dat: ''
|
dat: ''
|
||||||
|
|
@ -44,13 +40,19 @@ async function GetBlockObject(name, size, buf) {
|
||||||
console.log(`Found ${partsnum} blocks in file ${name}`)
|
console.log(`Found ${partsnum} blocks in file ${name}`)
|
||||||
let i;
|
let i;
|
||||||
let resp;
|
let resp;
|
||||||
const dialog = Dialog.create({ message: 'Downloaded 0%', progress: true, persistent: true, ok: false, style: 'border: none; box-shadow: none;' })
|
const dialog = Dialog.create({ message: `File "${name}" download 0%`, progress: true, persistent: true, ok: false, style: 'border: none; box-shadow: none;' })
|
||||||
for (i = 0; i < partsnum; i++) {
|
for (i = 0; i < partsnum; i++) {
|
||||||
resp = await ReceiveChunk(i, partsnum, name);
|
resp = await ReceiveChunk(i, partsnum, name);
|
||||||
|
if (typeof resp.raw_data === 'string' || resp.raw_data instanceof String) {
|
||||||
|
dialog.hide();
|
||||||
|
Notify.create({ color: "negative", position: "top", message: resp.raw_data, icon: "report_problem", });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let decoded = base64ToArrayBuffer(resp.raw_data.dat);
|
let decoded = base64ToArrayBuffer(resp.raw_data.dat);
|
||||||
for (let k = 0; k < decoded.byteLength; k++)
|
for (let k = 0; k < decoded.byteLength; k++)
|
||||||
buf[i * BLOCK_SIZE + k] = decoded[k];
|
buf[i * BLOCK_SIZE + k] = decoded[k];
|
||||||
dialog.update({ message: `Downloaded ${Math.floor(i * 100 / partsnum)}%` })
|
dialog.update({ message: `File "${name}" download ${Math.floor(i * 100 / partsnum)}%` })
|
||||||
}
|
}
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
}
|
}
|
||||||
|
|
@ -73,17 +75,11 @@ function SendChunk(cur, total, name, buf) {
|
||||||
arr = new Uint8Array(buf, cur * BLOCK_SIZE, BLOCK_SIZE);
|
arr = new Uint8Array(buf, cur * BLOCK_SIZE, BLOCK_SIZE);
|
||||||
let encode = ToBase64(arr);
|
let encode = ToBase64(arr);
|
||||||
let length = encode.length;
|
let length = encode.length;
|
||||||
|
|
||||||
let foper;
|
|
||||||
if (total == 1) foper = 3;
|
|
||||||
else if (cur == 0) foper = 1;
|
|
||||||
else if (cur == (total - 1)) foper = 2;
|
|
||||||
else foper = 0;
|
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
raw_data: {
|
raw_data: {
|
||||||
opertype: 3,
|
opertype: 3,
|
||||||
operphase: foper,
|
part: cur,
|
||||||
|
parts: total,
|
||||||
mem_object: name,
|
mem_object: name,
|
||||||
size: length,
|
size: length,
|
||||||
dat: encode
|
dat: encode
|
||||||
|
|
@ -91,7 +87,7 @@ function SendChunk(cur, total, name, buf) {
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(`Send chunk ${cur} from ${total} length ${arr.byteLength}`)
|
console.log(`Send chunk ${cur} from ${total} length ${arr.byteLength}`)
|
||||||
PostData(data, 1, 0, () => resolve())
|
PostData(data, 1, 0, () => resolve(data))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,10 +97,16 @@ async function PutBlockObject(name, size, buf) {
|
||||||
partsnum++;
|
partsnum++;
|
||||||
console.log(`Found ${partsnum} blocks in file`)
|
console.log(`Found ${partsnum} blocks in file`)
|
||||||
let i;
|
let i;
|
||||||
const dialog = Dialog.create({ message: 'Uploaded 0%', progress: true, persistent: true, ok: false, style: 'border: none; box-shadow: none;' })
|
let resp;
|
||||||
|
const dialog = Dialog.create({ message: `File "${name}" upload 0%`, progress: true, persistent: true, ok: false, style: 'border: none; box-shadow: none;' })
|
||||||
for (i = 0; i < partsnum; i++) {
|
for (i = 0; i < partsnum; i++) {
|
||||||
await SendChunk(i, partsnum, name, buf);
|
resp = await SendChunk(i, partsnum, name, buf);
|
||||||
dialog.update({ message: `Uploaded ${Math.floor(i * 100 / partsnum)}%` })
|
if (typeof resp.raw_data === 'string' || resp.raw_data instanceof String) {
|
||||||
|
dialog.hide();
|
||||||
|
Notify.create({ color: "negative", position: "top", message: resp.raw_data, icon: "report_problem", });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dialog.update({ message: `File "${name}" upload ${Math.floor(i * 100 / partsnum)}%` })
|
||||||
}
|
}
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user