Use header for indicating index.
This commit is contained in:
parent
b9d58652b7
commit
3c375770fb
2 changed files with 18 additions and 23 deletions
src/mami.js/eeprom
|
@ -16,16 +16,6 @@ const MamiEEPROM = function(endPoint, getAuthLine) {
|
||||||
|
|
||||||
let userAborted = false;
|
let userAborted = false;
|
||||||
let abortHandler;
|
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 {
|
return {
|
||||||
abort: () => {
|
abort: () => {
|
||||||
|
@ -33,15 +23,18 @@ const MamiEEPROM = function(endPoint, getAuthLine) {
|
||||||
if(typeof abortHandler === 'function')
|
if(typeof abortHandler === 'function')
|
||||||
abortHandler();
|
abortHandler();
|
||||||
},
|
},
|
||||||
onProgress: handler => {
|
start: async progress => {
|
||||||
if(typeof handler !== 'function')
|
|
||||||
throw 'handler must be a function';
|
|
||||||
progressHandler = handler;
|
|
||||||
},
|
|
||||||
start: async () => {
|
|
||||||
if(userAborted)
|
if(userAborted)
|
||||||
throw 'File upload was cancelled by the user, it cannot be restarted.';
|
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 {
|
try {
|
||||||
const formData = new FormData;
|
const formData = new FormData;
|
||||||
formData.append('src', appId);
|
formData.append('src', appId);
|
||||||
|
|
|
@ -57,11 +57,12 @@ const MamiEEPROMv2 = function(baseUrl, getAuthLine, poolName) {
|
||||||
const offset = size * index;
|
const offset = size * index;
|
||||||
buffer = buffer.subarray(offset, Math.min(buffer.length, offset + size));
|
buffer = buffer.subarray(offset, Math.min(buffer.length, offset + size));
|
||||||
|
|
||||||
let taskUrl = taskInfo.task_url;
|
const { status, body } = await $x.put(taskInfo.task_url, {
|
||||||
if(offset > 0)
|
type: 'json',
|
||||||
taskUrl += `?offset=${offset}`;
|
headers: {
|
||||||
|
'X-Content-Index': index,
|
||||||
const { status, body } = await $x.put(taskUrl, { type: 'json' }, buffer);
|
},
|
||||||
|
}, buffer);
|
||||||
if(status === 202)
|
if(status === 202)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -93,7 +94,7 @@ const MamiEEPROMv2 = function(baseUrl, getAuthLine, poolName) {
|
||||||
throw 'handler must be a function';
|
throw 'handler must be a function';
|
||||||
progressHandler = handler;
|
progressHandler = handler;
|
||||||
},
|
},
|
||||||
start: async () => {
|
start: async progress => {
|
||||||
if(userAborted)
|
if(userAborted)
|
||||||
throw 'File upload was cancelled by the user, it cannot be restarted.';
|
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') {
|
if(task.state === 'complete') {
|
||||||
upload = task.upload;
|
upload = task.upload;
|
||||||
} else if(task.state === 'pending') {
|
} else if(task.state === 'pending') {
|
||||||
|
const chunks = Math.ceil(buffer.length / CHUNK_SIZE);
|
||||||
await MamiRunConcurrent((() => {
|
await MamiRunConcurrent((() => {
|
||||||
const promises = [];
|
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));
|
promises.push(async () => await putChunk(task, buffer, i, CHUNK_SIZE));
|
||||||
return promises;
|
return promises;
|
||||||
})());
|
})());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue