Skip to content

Commit

Permalink
Merge branch 'fix-from-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuakto committed Mar 4, 2024
2 parents 53f017c + e9d154e commit df90b61
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
17 changes: 0 additions & 17 deletions main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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));

Expand Down
7 changes: 2 additions & 5 deletions src/fitPull.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<string, string>) {
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)
}
Expand Down
21 changes: 5 additions & 16 deletions src/vaultOps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { warn } from "console";
import { Notice, TFile, Vault, base64ToArrayBuffer } from "obsidian";
import { getFileEncoding } from "./utils";

export interface IVaultOperations {
vault: Vault
Expand Down Expand Up @@ -30,8 +29,8 @@ export class VaultOperations implements IVaultOperations {
}

async ensureFolderExists(path: string): Promise<void> {
// 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)
}
Expand All @@ -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<string>) {
// Process file additions or updates
const writeOperations = addToLocal.map(async ({path, content}) => {
Expand Down

0 comments on commit df90b61

Please sign in to comment.