tmp
GitOrigin-RevId: 96a5ee58db835d45cc8e0856811951048820f22e
This commit is contained in:
parent
6390bc9e0f
commit
5b62ac0ea8
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@arseny30/tdweb",
|
||||
"version": "0.2.30",
|
||||
"version": "0.2.34",
|
||||
"description": "Javascript interface for TDLib (telegram library)",
|
||||
"main": "dist/tdweb.js",
|
||||
"files": [
|
||||
|
@ -50,9 +50,9 @@ class TdClient {
|
||||
'receive from worker: ',
|
||||
JSON.parse(
|
||||
JSON.stringify(response, (key, value) => {
|
||||
if (key === 'arr') {
|
||||
return undefined;
|
||||
}
|
||||
//if (key === 'arr') {
|
||||
//return undefined;
|
||||
//}
|
||||
return value;
|
||||
})
|
||||
)
|
||||
|
@ -190,17 +190,14 @@ class InboundFileSystem {
|
||||
this.pids.delete(pid);
|
||||
}
|
||||
|
||||
async persist(pid, path) {
|
||||
var arr;
|
||||
async persist(pid, path, arr) {
|
||||
try {
|
||||
arr = this.FS.readFile(path);
|
||||
await this.store.setItem(pid, new Blob([arr]));
|
||||
this.pids.add(pid);
|
||||
this.FS.unlink(path);
|
||||
} catch (e) {
|
||||
log.error('Failed persist ' + path + ' ', e);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -645,20 +642,30 @@ class TdClient {
|
||||
this.callback({ '@type': 'updateFatalError', error: error });
|
||||
}
|
||||
|
||||
async saveFile(pid, file) {
|
||||
saveFile(pid, file) {
|
||||
let isSaving = this.savingFiles.has(pid);
|
||||
this.savingFiles.set(pid, file);
|
||||
if (isSaving) {
|
||||
return;
|
||||
return file;
|
||||
}
|
||||
let arr = await this.tdfs.inboundFileSystem.persist(pid, file.local.path);
|
||||
try {
|
||||
var arr = this.FS.readFile(file.local.path);
|
||||
if (arr) {
|
||||
file.arr = arr;
|
||||
this.doSaveFile(pid, file, arr);
|
||||
}
|
||||
} catch (e) {
|
||||
log.error('Failed to readFile: ', e);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
async doSaveFile(pid, file, arr) {
|
||||
await this.tdfs.inboundFileSystem.persist(pid, file.local.path, arr);
|
||||
file = this.savingFiles.get(pid);
|
||||
file.idb_key = pid;
|
||||
if (arr) {
|
||||
file.arr = arr;
|
||||
}
|
||||
this.callback({ '@type': 'updateFile', file: file }, [arr.buffer]);
|
||||
delete file.arr;
|
||||
this.callback({ '@type': 'updateFile', file: file });
|
||||
|
||||
this.savingFiles.delete(pid);
|
||||
}
|
||||
|
||||
@ -676,7 +683,7 @@ class TdClient {
|
||||
}
|
||||
|
||||
if (file.local.is_downloading_completed) {
|
||||
this.saveFile(pid, file);
|
||||
file = this.saveFile(pid, file);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user