This commit is contained in:
shenyutao 2023-08-25 15:44:44 +08:00
parent e9b9e7ef46
commit 309447ca68
2 changed files with 27 additions and 10 deletions

View File

@ -100,7 +100,7 @@ function onLoad() {
}
function noNotifyDeleteItem(ids: (string | number)[]) {
tldrs.modify(data => {
tldrs.modify((data) => {
ids.forEach((id) => {
delete data[id];
});
@ -128,7 +128,7 @@ function onUpdateItems(items: Zotero.Item[], forceFetch: boolean = false) {
return false;
}
if (!forceFetch) {
return tldrs.get()[item.id] === undefined
return tldrs.get()[item.id] === undefined;
}
return true;
});
@ -139,7 +139,9 @@ function onUpdateItems(items: Zotero.Item[], forceFetch: boolean = false) {
return new ztoolkit.ProgressWindow(config.addonName, {
closeOnClick: closeOnClick,
}).createLine({
text: `${getString("popWindow-waiting")}: ${items.length}; ${getString("popWindow-succeed")}: 0; ${getString("popWindow-failed")}: 0`,
text: `${getString("popWindow-waiting")}: ${items.length}; ${getString(
"popWindow-succeed",
)}: 0; ${getString("popWindow-failed")}: 0`,
type: "default",
progress: 0,
});
@ -158,7 +160,11 @@ function onUpdateItems(items: Zotero.Item[], forceFetch: boolean = false) {
ztoolkit.ItemBox.refresh();
popupWin.changeLine({
progress: (index * 100) / count,
text: `${getString("popWindow-waiting")}: ${count - index - 1}; ${getString("popWindow-succeed")}: ${succeedItems.length}; ${getString("popWindow-failed")}: ${failedItems.length}`,
text: `${getString("popWindow-waiting")}: ${
count - index - 1
}; ${getString("popWindow-succeed")}: ${
succeedItems.length
}; ${getString("popWindow-failed")}: ${failedItems.length}`,
});
}
})();
@ -167,7 +173,9 @@ function onUpdateItems(items: Zotero.Item[], forceFetch: boolean = false) {
popupWin.changeLine({
type: "success",
progress: 100,
text: `${getString("popWindow-succeed")}: ${succeedItems.length}; ${getString("popWindow-failed")}: ${failedItems.length}`,
text: `${getString("popWindow-succeed")}: ${
succeedItems.length
}; ${getString("popWindow-failed")}: ${failedItems.length}`,
});
popupWin.startCloseTimer(3000);
})();

View File

@ -19,7 +19,9 @@ export class Data<K extends string | number | symbol, V> {
return this.data;
}
async modify(action: (data: Record<K, V>) => Record<K, V> | Promise<Record<K, V>>) {
async modify(
action: (data: Record<K, V>) => Record<K, V> | Promise<Record<K, V>>,
) {
await this.initDataIfNeed();
const data = this.data;
const newData = await action(data);
@ -54,7 +56,9 @@ export class Data<K extends string | number | symbol, V> {
}
private async initDataIfNeed() {
if (this.inited) { return; }
if (this.inited) {
return;
}
this.inited = true;
try {
this.data = await IOUtils.readJSON(this.filePath, { decompress: false });
@ -74,7 +78,9 @@ export class DataStorage {
private static shared = new DataStorage();
static instance<K extends string | number | symbol, V>(dataType: string): Data<K, V> {
static instance<K extends string | number | symbol, V>(
dataType: string,
): Data<K, V> {
const path = PathUtils.join(this.shared.dataDir, dataType);
if (this.shared.dataMap[dataType] === undefined) {
const data = new Data<K, V>(path);
@ -86,10 +92,13 @@ export class DataStorage {
}
private constructor() {
IOUtils.makeDirectory(this.dataDir, { createAncestors: true, ignoreExisting: true });
IOUtils.makeDirectory(this.dataDir, {
createAncestors: true,
ignoreExisting: true,
});
}
}
export const TLDRUnrelated = "tldr-unrelated"; // semantic scholar 找到了该item但是该item没有tldr
export const TLDRItemNotFound = "tldr-itemnotfound"; // semantic scholar 找不到该item
export const tldrs = DataStorage.instance<string | number, string>('TLDR.json');
export const tldrs = DataStorage.instance<string | number, string>("TLDR.json");