Skip to content

Commit d1a8abc

Browse files
committed
- Restructuring folders.
- Fix type issues - Refactor Storage Accessors - Add support for relative folders on `Anywhere` - Fix importing syntax and ext.
1 parent ba5906f commit d1a8abc

24 files changed

+727
-659
lines changed

RestoreFileInfo.svelte

Lines changed: 0 additions & 115 deletions
This file was deleted.

RestoreFiles.svelte

Lines changed: 0 additions & 63 deletions
This file was deleted.

main.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Notice, Plugin, parseYaml, stringifyYaml } from "obsidian";
22
import * as fflate from "fflate";
3-
import { getStorage, getStorageInstance, getStorageType, type StorageAccessor } from "./storage";
4-
import { RestoreDialog } from "./RestoreView";
5-
import { confirmWithMessage } from "./dialog";
6-
import { Archiver, Extractor } from "./Archive";
7-
import { computeDigest, pieces } from "./util";
3+
import { getStorageForBackup, getStorageForVault, getStorageInstance, getStorageTypeForBackupAccess, getStorageTypeForVaultAccess, StorageAccessorTypes, } from "./src/storage.ts";
4+
import { type StorageAccessor } from "./src/StorageAccessor/StorageAccessor.ts";
5+
import { RestoreDialog } from "./src/RestoreView.ts";
6+
import { confirmWithMessage, askSelectString } from "./src/dialog.ts";
7+
import { Archiver, Extractor } from "./src/Archive.ts";
8+
import { computeDigest, pieces, toArrayBuffer } from "./src/util.ts";
89
import {
910
AutoBackupType,
1011
DEFAULT_SETTINGS,
@@ -13,9 +14,8 @@ import {
1314
type FileInfo,
1415
type FileInfos,
1516
type NoticeWithTimer,
16-
} from "./types";
17-
import { DiffZipSettingTab } from "./DiffZipSettingTab";
18-
import { askSelectString } from "dialog";
17+
} from "./src/types.ts";
18+
import { DiffZipSettingTab } from "./src/DiffZipSettingTab.ts";
1919

2020
export default class DiffZipBackupPlugin extends Plugin {
2121
settings: DiffZipBackupSettings;
@@ -35,17 +35,17 @@ export default class DiffZipBackupPlugin extends Plugin {
3535

3636
_backups: StorageAccessor;
3737
get backups(): StorageAccessor {
38-
const type = getStorageType(this);
38+
const type = getStorageTypeForBackupAccess(this);
3939
if (!this._backups || this._backups.type != type) {
40-
this._backups = getStorage(this);
40+
this._backups = getStorageForBackup(this);
4141
}
4242
return this._backups;
4343
}
4444
_vaultAccess: StorageAccessor;
4545
get vaultAccess(): StorageAccessor {
46-
const type = this.settings.includeHiddenFolder ? "direct" : "normal";
46+
const type = getStorageTypeForVaultAccess(this);
4747
if (!this._vaultAccess || this._vaultAccess.type != type) {
48-
this._vaultAccess = getStorageInstance(type, this, undefined, true);
48+
this._vaultAccess = getStorageForVault(this);
4949
}
5050
return this._vaultAccess;
5151
}
@@ -293,7 +293,7 @@ export default class DiffZipBackupPlugin extends Plugin {
293293
);
294294
pieceCount++;
295295
this.logMessage(`Creating ${outZipFile}...`, `proc-zip-process-write-${pieceCount}`);
296-
const e = await this.backups.writeBinary(outZipFile, chunk);
296+
const e = await this.backups.writeBinary(outZipFile, toArrayBuffer(chunk));
297297
if (!e) {
298298
throw new Error(`Creating ${outZipFile} has been failed!`);
299299
}
@@ -306,8 +306,8 @@ export default class DiffZipBackupPlugin extends Plugin {
306306
if (
307307
!(await this.backups.writeTOC(
308308
tocFilePath,
309-
new TextEncoder().encode(`\`\`\`\n${stringifyYaml(toc)}\n\`\`\`\n`)
310-
))
309+
toArrayBuffer(new TextEncoder().encode(`\`\`\`\n${stringifyYaml(toc)}\n\`\`\`\n`)))
310+
)
311311
) {
312312
throw new Error(`Updating TOC has been failed!`);
313313
}
@@ -378,10 +378,10 @@ export default class DiffZipBackupPlugin extends Plugin {
378378
}
379379
return file.name === extractFiles;
380380
},
381-
async (file: string, dat: Uint8Array) => {
381+
async (file: string, dat: Uint8Array<ArrayBuffer>) => {
382382
const fileName = restoreAs ?? file;
383383
const restoreTo = hasMultipleSupplied ? `${restorePrefix}${fileName}` : fileName;
384-
if (await this.vaultAccess.writeBinary(restoreTo, dat)) {
384+
if (await this.vaultAccess.writeBinary(restoreTo, toArrayBuffer(dat))) {
385385
restored.push(restoreTo);
386386
const files = restored.slice(-5).join("\n");
387387
this.logMessage(`${restored.length} files have been restored! \n${files}\n...`, "proc-zip-extract");
@@ -829,7 +829,6 @@ ${deletingFiles.map((e) => `- ${e}`).join("\n")}
829829
});
830830
this.addSettingTab(new DiffZipSettingTab(this.app, this));
831831
}
832-
833832
async loadSettings() {
834833
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
835834
}
@@ -841,7 +840,7 @@ ${deletingFiles.map((e) => `- ${e}`).join("\n")}
841840
if (
842841
await this.backups.writeTOC(
843842
tocFilePath,
844-
new TextEncoder().encode(`\`\`\`\n${stringifyYaml(toc)}\n\`\`\`\n`)
843+
toArrayBuffer(new TextEncoder().encode(`\`\`\`\n${stringifyYaml(toc)}\n\`\`\`\n`))
845844
)
846845
) {
847846
this.logMessage(`Backup information has been reset`);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@
3737
},
3838
"dependencies": {
3939
"fflate": "^0.8.2",
40-
"octagonal-wheels": "^0.1.30"
40+
"octagonal-wheels": "^0.1.37"
4141
}
4242
}

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
onlyBuiltDependencies:
2+
- esbuild
3+
- svelte-preprocess

0 commit comments

Comments
 (0)