small cleanup
This commit is contained in:
parent
0f731976c0
commit
1e5b1c78e7
|
@ -125,49 +125,36 @@ export function sendFileMessage(
|
||||||
uploadQueue[uploadPath].then(async response => {
|
uploadQueue[uploadPath].then(async response => {
|
||||||
// If response is all good...
|
// If response is all good...
|
||||||
if (response.respInfo.status >= 200 && response.respInfo.status < 400) {
|
if (response.respInfo.status >= 200 && response.respInfo.status < 400) {
|
||||||
try {
|
const json = response.json();
|
||||||
const json = response.json();
|
let content;
|
||||||
let content;
|
if (getContent) {
|
||||||
if (getContent) {
|
content = await getContent(json.file._id, json.file.url);
|
||||||
content = await getContent(json.file._id, json.file.url);
|
}
|
||||||
}
|
await fetch(`${server}/api/v1/rooms.mediaConfirm/${rid}/${json.file._id}`, {
|
||||||
await fetch(`${server}/api/v1/rooms.mediaConfirm/${rid}/${json.file._id}`, {
|
method: 'POST',
|
||||||
method: 'POST',
|
headers: {
|
||||||
headers: {
|
...headers,
|
||||||
...headers,
|
'Content-Type': 'application/json'
|
||||||
'Content-Type': 'application/json'
|
},
|
||||||
},
|
body: JSON.stringify({
|
||||||
body: JSON.stringify({
|
// msg: '', TODO: backwards compatibility
|
||||||
// msg: '', TODO: backwards compatibility
|
tmid,
|
||||||
tmid,
|
description: fileInfo.description,
|
||||||
description: fileInfo.description,
|
t: 'e2e',
|
||||||
t: 'e2e',
|
content
|
||||||
content
|
})
|
||||||
})
|
});
|
||||||
});
|
|
||||||
|
|
||||||
await db.write(async () => {
|
await db.write(async () => {
|
||||||
await uploadRecord.destroyPermanently();
|
await uploadRecord.destroyPermanently();
|
||||||
});
|
});
|
||||||
resolve(response);
|
resolve(response);
|
||||||
} catch (e) {
|
|
||||||
log(e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
await db.write(async () => {
|
||||||
await db.write(async () => {
|
await uploadRecord.update(u => {
|
||||||
await uploadRecord.update(u => {
|
u.error = true;
|
||||||
u.error = true;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
});
|
||||||
log(e);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
reject(response);
|
|
||||||
} catch (e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -181,22 +168,18 @@ export function sendFileMessage(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e);
|
log(e);
|
||||||
}
|
}
|
||||||
reject(error);
|
throw error;
|
||||||
});
|
});
|
||||||
|
|
||||||
uploadQueue[uploadPath].uploadProgress(async (loaded: number, total: number) => {
|
uploadQueue[uploadPath].uploadProgress(async (loaded: number, total: number) => {
|
||||||
try {
|
await db.write(async () => {
|
||||||
await db.write(async () => {
|
await uploadRecord.update(u => {
|
||||||
await uploadRecord.update(u => {
|
u.progress = Math.floor((loaded / total) * 100);
|
||||||
u.progress = Math.floor((loaded / total) * 100);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
});
|
||||||
log(e);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e);
|
reject(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue