Skip to content

Commit

Permalink
chore(release): 1.3.0 [skip ci]
Browse files Browse the repository at this point in the history
# [1.3.0](1.2.0...1.3.0) (2023-12-02)

### Bug Fixes

* deal with errors on api differently ([30cd942](30cd942))

### Features

* allow to obtain access-key via click of a button in settings ([01687b1](01687b1))
* regularily try to fetch documents from api ([169077f](169077f))
* regularily try to fetch documents from api ([5cc849c](5cc849c))
  • Loading branch information
semantic-release-bot committed Dec 2, 2023
1 parent b426566 commit c8b0204
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 2 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# [1.3.0](https://github.com/relay-md/relay-md-obsidian-plugin/compare/1.2.0...1.3.0) (2023-12-02)


### Bug Fixes

* deal with errors on api differently ([30cd942](https://github.com/relay-md/relay-md-obsidian-plugin/commit/30cd942d42d6041b4f76084e8a64324999d152c6))


### Features

* allow to obtain access-key via click of a button in settings ([01687b1](https://github.com/relay-md/relay-md-obsidian-plugin/commit/01687b1c6ce09d2d3bfcf0f92e7ed98dd3255f4a))
* regularily try to fetch documents from api ([169077f](https://github.com/relay-md/relay-md-obsidian-plugin/commit/169077fdb8127c3229674cf4007cec766709cfb2))
* regularily try to fetch documents from api ([5cc849c](https://github.com/relay-md/relay-md-obsidian-plugin/commit/5cc849c853047e211a2dd873f90511ce48c002a2))

# [1.2.0](https://github.com/relay-md/relay-md-obsidian-plugin/compare/1.1.8...1.2.0) (2023-12-01)


Expand Down
240 changes: 240 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/

var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/main.ts
var main_exports = {};
__export(main_exports, {
default: () => RelayMdPLugin
});
module.exports = __toCommonJS(main_exports);
var import_obsidian = require("obsidian");
var DEFAULT_SETTINGS = {
base_uri: "https://api.relay.md",
api_key: "00000000-0000-0000-0000-000000000000",
vault_base_folder: "relay.md"
};
var RelayMdPLugin = class extends import_obsidian.Plugin {
async onload() {
await this.loadSettings();
this.registerObsidianProtocolHandler("relay.md:access-token", (params) => {
if (!params.token) {
return;
}
this.settings.api_key = params.token;
this.settings.base_uri = DEFAULT_SETTINGS.base_uri;
this.saveSettings();
new import_obsidian.Notice("Access credentials for relay.md have been succesfully installed!");
});
this.addCommand({
id: "relay-md-send-current-active-file",
name: "Relay.md: Send current open file",
callback: async () => {
new import_obsidian.Notice("Sending document to relay.md");
const activeFile = this.app.workspace.getActiveFile();
if (!activeFile) {
return;
}
if (activeFile.extension !== "md") {
new import_obsidian.Notice(
"The current file is not a markdown file. Please open a markdown file and try again."
);
return;
}
if (activeFile.path.startsWith(this.settings.vault_base_folder)) {
new import_obsidian.Notice(
"Files from the relay.md base folder cannot be sent."
);
} else {
await this.send_document(activeFile);
}
}
});
this.addCommand({
id: "relay-md-fetch-documents",
name: "Relay.md: Retreive recent files",
callback: async () => {
new import_obsidian.Notice("Retreiving documents from relay.md");
await this.get_recent_documents();
}
});
this.registerInterval(window.setInterval(() => {
this.get_recent_documents();
}, 5 * 60 * 1e3));
this.addSettingTab(new RelayMDSettingTab(this.app, this));
}
onunload() {
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
async upsert_document(folder, filename, body) {
folder.split("/").reduce(
(directories, directory) => {
directories += `${directory}/`;
try {
this.app.vault.createFolder(directories);
} catch (e) {
}
return directories;
},
""
);
const full_path_to_file = (0, import_obsidian.normalizePath)(folder + "/" + filename);
const fileRef = this.app.vault.getAbstractFileByPath(full_path_to_file);
if (fileRef === void 0 || fileRef === null) {
await this.app.vault.create(full_path_to_file, body);
new import_obsidian.Notice("File " + full_path_to_file + " has been created!");
} else if (fileRef instanceof import_obsidian.TFile) {
await this.app.vault.modify(fileRef, body);
new import_obsidian.Notice("File " + full_path_to_file + " has been modified!");
}
}
async load_document(id) {
const options = {
url: this.settings.base_uri + "/v1/doc/" + id,
method: "GET",
headers: {
"X-API-KEY": this.settings.api_key,
"Content-Type": "text/markdown"
}
};
const response = await (0, import_obsidian.requestUrl)(options);
try {
const filename = response.headers["x-relay-filename"];
const relay_to = JSON.parse(response.headers["x-relay-to"]);
const body = response.text;
for (const to of relay_to) {
const tos = to.split("@", 2);
const team = tos[1];
const topic = tos[0];
let full_path_to_file = this.settings.vault_base_folder + "/";
if (team != "_")
full_path_to_file += team + "/";
full_path_to_file += topic;
this.upsert_document(full_path_to_file, filename, body);
}
} catch (e) {
console.log(JSON.stringify(e));
throw e;
}
}
async get_recent_documents() {
const options = {
url: this.settings.base_uri + "/v1/docs",
method: "GET",
headers: {
"X-API-KEY": this.settings.api_key,
"Content-Type": "application/json"
}
};
const response = await (0, import_obsidian.requestUrl)(options);
if (response.json.error) {
console.error("API server returned an error");
new import_obsidian.Notice("Relay.md returned an error: " + response.json.error.message);
return;
}
try {
response.json.result.map(async (item) => {
console.log(item);
new import_obsidian.Notice("Obtaining " + item["relay-filename"]);
await this.load_document(item["relay-document"]);
});
} catch (e) {
console.log(JSON.stringify(e));
throw e;
}
}
// TODO: might want to make the interface clear to get rid of "any" type
async send_document(activeFile) {
const body = await this.app.vault.cachedRead(activeFile);
const metadata = this.app.metadataCache.getCache(activeFile.path);
if (metadata === null || metadata === void 0) {
return;
}
if (metadata.frontmatter === null || metadata.frontmatter === void 0) {
return;
}
const id = metadata.frontmatter["relay-document"];
let method = "POST";
let url = this.settings.base_uri + "/v1/doc?filename=" + encodeURIComponent(activeFile.name);
if (id) {
method = "PUT";
url = this.settings.base_uri + "/v1/doc/" + id;
}
const options = {
url,
method,
headers: {
"X-API-KEY": this.settings.api_key,
"Content-Type": "text/markdown"
},
body
};
const response = await (0, import_obsidian.requestUrl)(options);
if (response.json.error) {
console.error("API server returned an error");
new import_obsidian.Notice("Relay.md returned an error: " + response.json.error.message);
return;
}
const doc_id = response.json.result["relay-document"];
app.fileManager.processFrontMatter(activeFile, (frontmatter) => {
frontmatter["relay-document"] = doc_id;
});
}
};
var RelayMDSettingTab = class extends import_obsidian.PluginSettingTab {
constructor(app2, plugin) {
super(app2, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
new import_obsidian.Setting(containerEl).setName("Base API URI").setDesc("Base URL for API access").addText((text) => text.setPlaceholder("Enter your API url").setValue(this.plugin.settings.base_uri).onChange(async (value) => {
this.plugin.settings.base_uri = value;
await this.plugin.saveSettings();
}));
if (this.plugin.settings.api_key == DEFAULT_SETTINGS.api_key) {
new import_obsidian.Setting(containerEl).setName("API Access").setDesc("Authenticate against the relay.md API").addButton(
(button) => button.setButtonText("Obtain access to relay.md").onClick(async () => {
window.open("localhost:5000/configure/obsidian");
})
);
} else {
new import_obsidian.Setting(containerEl).setName("API Access").setDesc("Authenticate against the relay.md API").addButton(
(button) => button.setButtonText("reset").onClick(async () => {
this.plugin.settings.api_key = DEFAULT_SETTINGS.api_key;
await this.plugin.saveSettings();
this.display();
})
);
}
new import_obsidian.Setting(containerEl).setName("Vault relay.md inbox").setDesc("Base folder to synchronize into").addText((text) => text.setPlaceholder("relay.md").setValue(this.plugin.settings.vault_base_folder).onChange(async (value) => {
this.plugin.settings.vault_base_folder = value;
await this.plugin.saveSettings();
}));
}
};
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "relay-md",
"name": "Relay.md",
"version": "1.2.0",
"version": "1.3.0",
"minAppVersion": "0.15.0",
"description": "Markdown workflows for teams.",
"author": "xeroc",
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"1.1.6": "0.15.0",
"1.1.7": "0.15.0",
"1.1.8": "0.15.0",
"1.2.0": "0.15.0"
"1.2.0": "0.15.0",
"1.3.0": "0.15.0"
}

0 comments on commit c8b0204

Please sign in to comment.