Skip to content

Commit

Permalink
fix: #120
Browse files Browse the repository at this point in the history
  • Loading branch information
MuiseDestiny committed Jun 25, 2024
1 parent c26494e commit 9aa7336
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zotero-attanger",
"version": "1.2.3",
"version": "1.2.4",
"description": "Attanger for Zotero",
"config": {
"addonName": "Zotero Attanger",
Expand Down
96 changes: 55 additions & 41 deletions src/modules/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,50 +601,64 @@ export async function moveFile(attItem: Zotero.Item) {
const filename = PathUtils.filename(sourcePath);
let destPath = PathUtils.joinRelative(destDir, filename);
if (sourcePath == destPath) return;
// window.alert(destPath)
if (
(await IOUtils.exists(destPath)) &&
file2md5(sourcePath) != file2md5(destPath)
) {
await Zotero.Promise.delay(1000);
// Click to enter a specified suffix.
const popupWin = new ztoolkit.ProgressWindow("Attanger", {
closeTime: -1,
closeOtherProgressWindows: true,
})
.createLine({
text: "The target file already exists; a numeric suffix will be automatically added to the filename.",
icon: addon.data.icons.moveFile,
if ((await IOUtils.exists(destPath))) {
ztoolkit.log("目标目录存在", file2md5(sourcePath), file2md5(destPath))
window.alert(1)
if (file2md5(sourcePath) != file2md5(destPath)) {
ztoolkit.log("不是同一个文件")
await Zotero.Promise.delay(1000);
// Click to enter a specified suffix.
const popupWin = new ztoolkit.ProgressWindow("Attanger", {
closeTime: -1,
closeOtherProgressWindows: true,
})
.show();
// Zotero.ProgressWindowSet.remove(popupWin)
popupWin.addDescription(
`<a href="https://zotero.org">Click to enter a specified suffix.</a>`,
);
await waitUtilAsync(() =>
// @ts-ignore oriate
Boolean(popupWin.lines && popupWin.lines[0]._itemText),
);
const lock = Zotero.Promise.defer();
const timer = window.setTimeout(() => {
popupWin.close();
lock.resolve();
}, 3e3);
// @ts-ignore private
popupWin.lines[0]._hbox.ownerDocument
.querySelector("label[href]")
.addEventListener("click", async (ev: MouseEvent) => {
ev.stopPropagation();
ev.preventDefault();
window.clearTimeout(timer);
.createLine({
text: "The target file already exists; a numeric suffix will be automatically added to the filename.",
icon: addon.data.icons.moveFile,
})
.show();
// Zotero.ProgressWindowSet.remove(popupWin)
popupWin.addDescription(
`<a href="https://zotero.org">Click to enter a specified suffix.</a>`,
);
await waitUtilAsync(() =>
// @ts-ignore oriate
Boolean(popupWin.lines && popupWin.lines[0]._itemText),
);
const lock = Zotero.Promise.defer();
const timer = window.setTimeout(() => {
popupWin.close();
const suffix = window.prompt("Suffix") as string;
destPath = await addSuffixToFilename(destPath, suffix);
lock.resolve();
});
}, 3e3);
// @ts-ignore private
popupWin.lines[0]._hbox.ownerDocument
.querySelector("label[href]")
.addEventListener("click", async (ev: MouseEvent) => {
ev.stopPropagation();
ev.preventDefault();
window.clearTimeout(timer);
popupWin.close();
const suffix = window.prompt("Suffix") as string;
destPath = await addSuffixToFilename(destPath, suffix);
lock.resolve();
});

await lock.promise;
destPath = await addSuffixToFilename(destPath);
await lock.promise;
destPath = await addSuffixToFilename(destPath);
} else {
ztoolkit.log("是同一个文件")
new ztoolkit.ProgressWindow("Attanger", {
closeTime: 3000,
closeOtherProgressWindows: true,
})
.createLine({
text: "The target file already exists",
icon: addon.data.icons.moveFile,
})
.show();
await attItem.eraseTx()
return attItem
}
}
// 创建中间路径
if (!(await IOUtils.exists(destDir))) {
Expand Down Expand Up @@ -738,7 +752,7 @@ function removeFile(file: any, force = false) {
}

function file2md5(filepath: string) {
Zotero.Utilities.Internal.md5(Zotero.File.pathToFile(filepath));
return Zotero.Utilities.Internal.md5(Zotero.File.pathToFile(filepath));
}
/**
* 获取Item的分类路径
Expand Down

0 comments on commit 9aa7336

Please sign in to comment.