diff --git a/main.ts b/main.ts index 23de926..981efec 100644 --- a/main.ts +++ b/main.ts @@ -1,5 +1,4 @@ import { Notice, Platform, Plugin } from 'obsidian'; -import { ComputeFileLocalShaModal } from 'src/pluginModal'; import { Fit } from 'src/fit'; import { FitPull } from 'src/fitPull'; import { FitPush } from 'src/fitPush'; @@ -135,22 +134,6 @@ export default class FitPlugin extends Plugin { // add class to ribbon element to afford styling, refer to styles.css this.fitPushRibbonIconEl.addClass('fit-push-ribbon-el'); - // This adds a status bar item to the bottom of the app. Does not work on mobile apps. - const statusBarItemEl = this.addStatusBarItem(); - statusBarItemEl.setText('Status Bar Text'); - - // Command for computing an inputed file path's local sha for debugging purposes - this.addCommand({ - id: 'compute-file-local-sha', - name: 'Compute local sha for file (Debug)', - callback: () => { - new ComputeFileLocalShaModal( - this.app, - async (queryFile) => console.log(await this.fit.computeFileLocalSha(queryFile)) - ).open(); - } - }); - // This adds a settings tab so the user can configure various aspects of the plugin this.addSettingTab(new FitSettingTab(this.app, this)); diff --git a/src/fitPull.ts b/src/fitPull.ts index 8db763b..1162670 100644 --- a/src/fitPull.ts +++ b/src/fitPull.ts @@ -1,5 +1,5 @@ import { VaultOperations } from "./vaultOps"; -import { ChangeType, compareSha, getFileEncoding } from "./utils"; +import { ChangeType, compareSha } from "./utils"; import { Fit } from "./fit"; import { Notice } from "obsidian"; import { LocalStores } from "main"; @@ -89,11 +89,8 @@ export class FitPull implements IFitPull { // Get changes from remote, pathShaMap is coupled to the Fit plugin design async getRemoteNonDeletionChangesContent(pathShaMap: Record) { const remoteChanges = Object.entries(pathShaMap).map(async ([path, file_sha]) => { - const encoding = getFileEncoding(path) const content = await this.fit.getBlob(file_sha); - const isBinary = encoding == "base64" - const decodedContent = isBinary ? content : atob(content); - return {path, content: decodedContent, encoding}; + return {path, content}; }) return await Promise.all(remoteChanges) } diff --git a/src/vaultOps.ts b/src/vaultOps.ts index 5c6b614..f8a1054 100644 --- a/src/vaultOps.ts +++ b/src/vaultOps.ts @@ -1,6 +1,5 @@ import { warn } from "console"; import { Notice, TFile, Vault, base64ToArrayBuffer } from "obsidian"; -import { getFileEncoding } from "./utils"; export interface IVaultOperations { vault: Vault @@ -30,8 +29,8 @@ export class VaultOperations implements IVaultOperations { } async ensureFolderExists(path: string): Promise { - // extract folder path, return empty string is no folder path is matched - const folderPath = path.match(/^(.*\/)/)?.[1] || ''; + // extract folder path, return empty string is no folder path is matched (exclude the last /) + const folderPath = path.match(/^(.*)\//)?.[1] || ''; if (folderPath != "" && !(this.vault.getFolderByPath(folderPath))) { await this.vault.createFolder(folderPath) } @@ -41,28 +40,18 @@ export class VaultOperations implements IVaultOperations { // adopted getAbstractFileByPath for mobile compatiability, TODO: check whether additional checks needed to validate instance of TFile // temporary fix that works temporarily since path are garanteed to be for files not folders const file = this.vault.getAbstractFileByPath(path) as TFile - const encoding = getFileEncoding(path) - const isBinary = encoding === "base64" if (file) { - if (isBinary) { - await this.vault.modifyBinary(file, base64ToArrayBuffer(content)) - } else { - await this.vault.modify(file, content) - } + await this.vault.modifyBinary(file, base64ToArrayBuffer(content)) } else { this.ensureFolderExists(path) - if (isBinary) { - await this.vault.createBinary(path, base64ToArrayBuffer(content)) - } else { - await this.vault.create(path, content) - } + await this.vault.createBinary(path, base64ToArrayBuffer(content)) } new Notice(`${path} ${file ? 'updated' : 'copied'} to local drive.`, this.noticeDuration); return } async updateLocalFiles( - addToLocal: {path: string, content: string, encoding: string}[], + addToLocal: {path: string, content: string}[], deleteFromLocal: Array) { // Process file additions or updates const writeOperations = addToLocal.map(async ({path, content}) => {