mirror of
https://github.com/fangface-hub/ObsidianSharedVault.git
synced 2026-07-22 08:33:01 +00:00
- Addressed the bot‑review comments
This commit is contained in:
parent
a4fa60a654
commit
d07945774d
7 changed files with 52 additions and 35 deletions
|
|
@ -1,13 +1,30 @@
|
|||
import esbuild from "esbuild";
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
const production = process.argv.includes("production");
|
||||
|
||||
const emptyNodeEnvPlugin = {
|
||||
name: "empty-node-env",
|
||||
setup(build) {
|
||||
build.onLoad({ filter: /node_modules[\\/]lib0[\\/](environment|storage)\.js$/ }, async (args) => {
|
||||
const source = await readFile(args.path, "utf8");
|
||||
return {
|
||||
contents: source
|
||||
.replaceAll("process.env", "({})")
|
||||
.replaceAll("localStorage", "undefined"),
|
||||
loader: "js"
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const context = await esbuild.context({
|
||||
entryPoints: ["src/main.ts"],
|
||||
bundle: true,
|
||||
external: ["obsidian", "electron", "@codemirror/state", "@codemirror/view", "@codemirror/commands"],
|
||||
format: "cjs",
|
||||
target: "es2020",
|
||||
plugins: [emptyNodeEnvPlugin],
|
||||
logLevel: "info",
|
||||
sourcemap: production ? false : "inline",
|
||||
treeShaking: true,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"id": "shared-vault",
|
||||
"name": "Shared Vault",
|
||||
"version": "0.1.0",
|
||||
"minAppVersion": "1.5.0",
|
||||
"description": "Serverless, conflict-free collaboration layer for Obsidian shared vaults.",
|
||||
"author": "fangface",
|
||||
"authorUrl": "https://github.com/fangface-hub",
|
||||
"isDesktopOnly": true
|
||||
}
|
||||
{
|
||||
"id": "shared-vault",
|
||||
"name": "Shared Vault",
|
||||
"version": "0.1.1",
|
||||
"minAppVersion": "1.5.0",
|
||||
"description": "Serverless, conflict-free collaboration layer for shared vaults.",
|
||||
"author": "fangface",
|
||||
"authorUrl": "https://github.com/fangface-hub",
|
||||
"isDesktopOnly": true
|
||||
}
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "obsidian-shared-vault",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "obsidian-shared-vault",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"dependencies": {
|
||||
"diff-match-patch": "latest",
|
||||
"yjs": "latest"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "obsidian-shared-vault",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"description": "Serverless conflict-free collaboration layer for Obsidian shared vaults.",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
|
@ -29,4 +29,4 @@
|
|||
"diff-match-patch": "latest",
|
||||
"yjs": "latest"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,13 +5,8 @@ export const DEFAULT_CACHE_TTL_DAYS = 30;
|
|||
export const DAY_IN_MS = 24 * 60 * 60 * 1000;
|
||||
export const NODE_REGISTRY_DIR = "node-registry";
|
||||
|
||||
export function getDefaultUserId(): string {
|
||||
const loginUserId = process.env.USERNAME?.trim() || process.env.USER?.trim() || process.env.LOGNAME?.trim();
|
||||
return loginUserId && loginUserId.length > 0 ? loginUserId : FALLBACK_USER_ID;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: SharedVaultSettings = {
|
||||
userId: getDefaultUserId(),
|
||||
userId: FALLBACK_USER_ID,
|
||||
autoSyncIntervalSec: 15,
|
||||
cacheTtlDays: DEFAULT_CACHE_TTL_DAYS,
|
||||
operationCacheDir: "operation-cache",
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ import { SharedVaultSettingTab } from "./shared-vault-settings-tab";
|
|||
import type { NodeListEntry, NodeRegistryEntry, OperationFile, SharedVaultData, SharedVaultSettings } from "./shared-vault-types";
|
||||
import { hashText, safeMkdir } from "./shared-vault-utils";
|
||||
|
||||
const LOCAL_DATA_KEY_PREFIX = "shared-vault:data";
|
||||
|
||||
export default class SharedVaultPlugin extends Plugin {
|
||||
settings: SharedVaultSettings = DEFAULT_SETTINGS;
|
||||
data!: SharedVaultData;
|
||||
|
|
@ -97,7 +95,7 @@ export default class SharedVaultPlugin extends Plugin {
|
|||
...this.settings,
|
||||
userId: nextUserId
|
||||
};
|
||||
this.saveLocalPluginData(this.data);
|
||||
await this.saveLocalPluginData(this.data);
|
||||
|
||||
if (previousUserId !== nextUserId) {
|
||||
await this.migrateUserCache(previousUserId, nextUserId);
|
||||
|
|
@ -122,7 +120,7 @@ export default class SharedVaultPlugin extends Plugin {
|
|||
}
|
||||
|
||||
private async loadPluginData(): Promise<SharedVaultData> {
|
||||
const localRaw = this.loadLocalPluginData();
|
||||
const localRaw = await this.loadLocalPluginData();
|
||||
const sharedRaw = (await this.loadData()) as Partial<SharedVaultData> | null;
|
||||
const raw = {
|
||||
...sharedRaw,
|
||||
|
|
@ -142,31 +140,37 @@ export default class SharedVaultPlugin extends Plugin {
|
|||
};
|
||||
|
||||
if (!localRaw) {
|
||||
this.saveLocalPluginData(data);
|
||||
await this.saveLocalPluginData(data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private loadLocalPluginData(): Partial<SharedVaultData> | null {
|
||||
const raw = window.localStorage.getItem(this.getLocalDataKey());
|
||||
if (!raw) {
|
||||
private async loadLocalPluginData(): Promise<Partial<SharedVaultData> | null> {
|
||||
const path = this.getLocalDataPath();
|
||||
if (!(await this.app.vault.adapter.exists(path))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const raw = await this.app.vault.adapter.read(path);
|
||||
return JSON.parse(raw) as Partial<SharedVaultData>;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private saveLocalPluginData(data: SharedVaultData): void {
|
||||
window.localStorage.setItem(this.getLocalDataKey(), JSON.stringify(data));
|
||||
private async saveLocalPluginData(data: SharedVaultData): Promise<void> {
|
||||
await safeMkdir(this, this.getLocalDataDir());
|
||||
await this.app.vault.adapter.write(this.getLocalDataPath(), JSON.stringify(data, null, 2));
|
||||
}
|
||||
|
||||
private getLocalDataKey(): string {
|
||||
return `${LOCAL_DATA_KEY_PREFIX}:${this.manifest.id}:${this.vaultId}`;
|
||||
private getLocalDataDir(): string {
|
||||
return normalizePath(`${this.app.vault.configDir}/cache/${this.vaultId}`);
|
||||
}
|
||||
|
||||
private getLocalDataPath(): string {
|
||||
return normalizePath(`${this.getLocalDataDir()}/local-plugin-data.json`);
|
||||
}
|
||||
|
||||
private createEngine(userId: string): SharedVaultEngine {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
{
|
||||
"0.1.0": "1.5.0"
|
||||
}
|
||||
{
|
||||
"0.1.0": "1.5.0",
|
||||
"0.1.1": "1.5.0"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue