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