Skip to content

Commit

Permalink
fix: incorporate requested changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Dec 5, 2023
1 parent 510cd21 commit 2f10f57
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
1 change: 0 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
"author": "xeroc",
"authorUrl": "https://chainsquad.com",
"fundingUrl": "https://www.buymeacoffee.com/fabian.schuh",
"repo": "relay-md/relay-md-obsidian-plugin",
"isDesktopOnly": false
}
45 changes: 24 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
requestUrl,
TFile,
TAbstractFile,
TFolder,
normalizePath
} from 'obsidian';

Expand Down Expand Up @@ -43,8 +44,8 @@ export default class RelayMdPLugin extends Plugin {
});

this.addCommand({
id: "relay-md-send-current-active-file",
name: "Relay.md: Send current open file",
id: "send-current-active-file",
name: "Send current open file",
callback: async () => {
new Notice("Sending document to relay.md");
const activeFile = this.app.workspace.getActiveFile();
Expand All @@ -53,25 +54,25 @@ export default class RelayMdPLugin extends Plugin {
});

this.addCommand({
id: "relay-md-fetch-documents",
name: "Relay.md: Retreive recent files",
id: "fetch-documents",
name: "Retreive recent files",
callback: async () => {
new Notice("Retreiving documents from relay.md");
await this.get_recent_documents();
}
});

// We look into all documents that are modified
this.app.vault.on('modify', (file: TAbstractFile) => {
this.registerEvent(this.app.vault.on('modify', (file: TAbstractFile) => {
if(file instanceof TFile) {
this.send_document(file);
}
});
this.app.vault.on('create', (file: TAbstractFile) => {
}));
this.registerEvent(this.app.vault.on('create', (file: TAbstractFile) => {
if(file instanceof TFile) {
this.send_document(file);
}
});
}));


// Additionally, we register a timer to fetch documents for us
Expand All @@ -95,19 +96,21 @@ export default class RelayMdPLugin extends Plugin {
}

async upsert_document(folder: string, filename: string, body: string) {
// FIXME: There is no way to check if a folder exists, so we just try create them
folder.split('/').reduce(
(directories, directory) => {
directories += `${directory}/`;
try {
this.app.vault.createFolder(directories);
} catch(e) {
// do nothing
}
return directories;
},
'',
);
// Does the folder exist? If not, create it "recusrively"
if (!(this.app.vault.getAbstractFileByPath(folder) instanceof TFolder)) {
folder.split('/').reduce(
(directories, directory) => {
directories += `${directory}/`;
try {
this.app.vault.createFolder(directories);
} catch(e) {
// do nothing
}
return directories;
},
'',
);
}
const full_path_to_file = normalizePath(folder + "/" + filename);
const fileRef = this.app.vault.getAbstractFileByPath(full_path_to_file);
if(fileRef === undefined || fileRef === null) {
Expand Down

0 comments on commit 2f10f57

Please sign in to comment.