11import { Notice , Plugin , parseYaml , stringifyYaml } from "obsidian" ;
22import * 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" ;
89import {
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
2020export 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` ) ;
0 commit comments