Use header for indicating index.

This commit is contained in:
flash 2025-01-17 07:12:59 +00:00
parent b9d58652b7
commit 3c375770fb
2 changed files with 18 additions and 23 deletions
src/mami.js/eeprom

View file

@ -16,16 +16,6 @@ const MamiEEPROM = function(endPoint, getAuthLine) {
let userAborted = false;
let abortHandler;
let progressHandler;
const reportProgress = ev => {
if(progressHandler !== undefined)
progressHandler({
loaded: ev.loaded,
total: ev.total,
progress: ev.total <= 0 ? 0 : ev.loaded / ev.total,
});
};
return {
abort: () => {
@ -33,15 +23,18 @@ const MamiEEPROM = function(endPoint, getAuthLine) {
if(typeof abortHandler === 'function')
abortHandler();
},
onProgress: handler => {
if(typeof handler !== 'function')
throw 'handler must be a function';
progressHandler = handler;
},
start: async () => {
start: async progress => {
if(userAborted)
throw 'File upload was cancelled by the user, it cannot be restarted.';
const reportProgress = typeof progress !== 'function' ? undefined : ev => {
progress({
loaded: ev.loaded,
total: ev.total,
progress: ev.total <= 0 ? 0 : ev.loaded / ev.total,
});
};
try {
const formData = new FormData;
formData.append('src', appId);

View file

@ -57,11 +57,12 @@ const MamiEEPROMv2 = function(baseUrl, getAuthLine, poolName) {
const offset = size * index;
buffer = buffer.subarray(offset, Math.min(buffer.length, offset + size));
let taskUrl = taskInfo.task_url;
if(offset > 0)
taskUrl += `?offset=${offset}`;
const { status, body } = await $x.put(taskUrl, { type: 'json' }, buffer);
const { status, body } = await $x.put(taskInfo.task_url, {
type: 'json',
headers: {
'X-Content-Index': index,
},
}, buffer);
if(status === 202)
return;
@ -93,7 +94,7 @@ const MamiEEPROMv2 = function(baseUrl, getAuthLine, poolName) {
throw 'handler must be a function';
progressHandler = handler;
},
start: async () => {
start: async progress => {
if(userAborted)
throw 'File upload was cancelled by the user, it cannot be restarted.';
@ -105,9 +106,10 @@ const MamiEEPROMv2 = function(baseUrl, getAuthLine, poolName) {
if(task.state === 'complete') {
upload = task.upload;
} else if(task.state === 'pending') {
const chunks = Math.ceil(buffer.length / CHUNK_SIZE);
await MamiRunConcurrent((() => {
const promises = [];
for(let i = 0; i < buffer.length / CHUNK_SIZE; ++i)
for(let i = 0; i < chunks; ++i)
promises.push(async () => await putChunk(task, buffer, i, CHUNK_SIZE));
return promises;
})());