Skip to content

Commit 5f5b8d4

Browse files
committed
Address ObsidianReviewBot feedback for community plugin submission
- settings: replace HTML heading with Setting().setHeading() pattern; sentence-case "GitHub personal access token" - push: read configDir from Vault instead of hardcoding ".obsidian" - pull/push/seed/main: drop "Vault Sync:" prefix from Notice strings (sentence case + Obsidian style) - pull/seed: omit unused catch params Bumps version to 1.0.3.
1 parent 29baa45 commit 5f5b8d4

7 files changed

Lines changed: 55 additions & 58 deletions

File tree

main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "vault-sync-rest",
33
"name": "Vault Sync (REST)",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"minAppVersion": "1.4.0",
66
"description": "Two-way sync with a GitHub repo via REST API. Works on iOS for vaults of any size including images, where git-protocol plugins crash from WebView memory limits.",
77
"author": "Andrew Boldi",

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class VaultSyncPlugin extends Plugin {
2121
this.statusBar = this.addStatusBarItem();
2222
this.updateStatusBar("idle");
2323

24-
this.addRibbonIcon("refresh-cw", "Vault Sync: Sync now", () => {
24+
this.addRibbonIcon("refresh-cw", "Sync vault now", () => {
2525
void this.runWithErrorNotice("sync", () => this.runSync(false));
2626
});
2727

src/pull.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function ensureDir(plugin: VaultSyncPlugin, dirPath: string): Promise<void
1818
if (!dirPath || dirPath === "/" || dirPath === ".") return;
1919
try {
2020
await plugin.app.vault.adapter.mkdir(dirPath);
21-
} catch (_e) {
21+
} catch {
2222
/* exists */
2323
}
2424
}
@@ -41,7 +41,7 @@ async function ensureParentDirs(
4141
async function safeRemove(plugin: VaultSyncPlugin, path: string): Promise<void> {
4242
try {
4343
await plugin.app.vault.adapter.remove(path);
44-
} catch (_e) {
44+
} catch {
4545
/* already gone */
4646
}
4747
}
@@ -78,50 +78,50 @@ export async function pullFromGitHub(
7878
if (!repoUrl) throw new Error("Set a repo URL in Vault Sync settings.");
7979
if (!lastCommitSha) {
8080
throw new Error(
81-
"No baseline commit recorded. Run 'Vault Sync: Seed from GitHub' first."
81+
"No baseline commit recorded. Run 'Seed from GitHub' first."
8282
);
8383
}
8484

8585
const ref = parseRepoUrl(repoUrl);
8686
const notice = opts.silent
8787
? null
88-
: new Notice("Vault Sync: checking remote…", 0);
88+
: new Notice("Checking remote…", 0);
8989

9090
const headSha = await getBranchSha(ref, branch || "main", pat);
9191
if (headSha === lastCommitSha) {
9292
if (notice) {
93-
notice?.setMessage("Vault Sync: already up to date");
93+
notice?.setMessage("Already up to date");
9494
setTimeout(() => notice?.hide(), 4000);
9595
}
9696
return;
9797
}
9898

99-
notice?.setMessage(`Vault Sync: comparing ${lastCommitSha.slice(0, 7)}${headSha.slice(0, 7)}`);
99+
notice?.setMessage(`Comparing ${lastCommitSha.slice(0, 7)}${headSha.slice(0, 7)}`);
100100

101101
const cmp = await compareCommits(ref, lastCommitSha, headSha, pat);
102102

103103
if (cmp.status === "diverged") {
104104
notice?.setMessage(
105-
"Vault Sync: remote diverged from local baseline. Manual resolution needed (Phase 3 push will detect this)."
105+
"Remote diverged from local baseline. Manual resolution needed (push will detect this)."
106106
);
107107
setTimeout(() => notice?.hide(), 10000);
108108
throw new Error(
109-
`Remote and local have diverged (ahead ${cmp.ahead_by}, behind ${cmp.behind_by}). Vault Sync can only fast-forward in Phase 2.`
109+
`Remote and local have diverged (ahead ${cmp.ahead_by}, behind ${cmp.behind_by}). Pull only supports fast-forward updates.`
110110
);
111111
}
112112

113113
const files = cmp.files ?? [];
114114
if (files.length === 0) {
115115
plugin.settings.lastCommitSha = headSha;
116116
await plugin.saveSettings();
117-
notice?.setMessage("Vault Sync: pull complete (no file changes)");
117+
notice?.setMessage("Pull complete (no file changes)");
118118
setTimeout(() => notice?.hide(), 4000);
119119
return;
120120
}
121121

122122
if (files.length === 300) {
123123
new Notice(
124-
"Vault Sync: compare returned exactly 300 files (GitHub's per-call cap). Some changes may be missing — re-seed if pull seems incomplete.",
124+
"Compare returned exactly 300 files (GitHub's per-call cap). Some changes may be missing — re-seed if pull seems incomplete.",
125125
10000
126126
);
127127
}
@@ -150,7 +150,7 @@ export async function pullFromGitHub(
150150
}
151151

152152
notice?.setMessage(
153-
`Vault Sync: ${toFetch.length} to fetch, ${toRemove.length} to remove…`
153+
`${toFetch.length} to fetch, ${toRemove.length} to remove…`
154154
);
155155

156156
// Apply removals first (cheap, sequential).
@@ -171,7 +171,7 @@ export async function pullFromGitHub(
171171
bytes += content.byteLength;
172172
if (done % 5 === 0) {
173173
notice?.setMessage(
174-
`Vault Sync: ${done}/${toFetch.length} files, ${formatBytes(bytes)}`
174+
`${done}/${toFetch.length} files, ${formatBytes(bytes)}`
175175
);
176176
}
177177
});
@@ -181,7 +181,7 @@ export async function pullFromGitHub(
181181
await plugin.saveSettings();
182182

183183
notice?.setMessage(
184-
`Vault Sync: pull complete — ${toFetch.length} updated, ${toRemove.length} removed @ ${headSha.slice(0, 7)}`
184+
`Pull complete — ${toFetch.length} updated, ${toRemove.length} removed @ ${headSha.slice(0, 7)}`
185185
);
186186
setTimeout(() => notice?.hide(), 6000);
187187
}

src/push.ts

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,28 @@ import {
1111
type TreeUpdateEntry,
1212
} from "./github";
1313

14-
const SKIP_PATHS = new Set<string>([
15-
".obsidian/workspace.json",
16-
".obsidian/workspace-mobile.json",
17-
".obsidian/cache",
18-
".obsidian/appearance.json",
19-
".DS_Store",
20-
"_GIT-DEBUG-ERROR.md",
21-
]);
22-
23-
const SKIP_PREFIXES = [
24-
".trash/",
14+
function buildSkipFn(configDir: string): (path: string) => boolean {
15+
const skipPaths = new Set<string>([
16+
`${configDir}/workspace.json`,
17+
`${configDir}/workspace-mobile.json`,
18+
`${configDir}/cache`,
19+
`${configDir}/appearance.json`,
20+
".DS_Store",
21+
"_GIT-DEBUG-ERROR.md",
22+
]);
2523
// Plugin installs are per-device. Each Obsidian install pulls plugin code
2624
// from its own source (community store, BRAT, etc). Syncing plugin folders
2725
// bloats the repo and risks leaking credentials stored in plugin data.json.
28-
// The list of *which* plugins to enable still syncs via .obsidian/community-plugins.json.
29-
".obsidian/plugins/",
30-
];
31-
32-
function shouldSkip(path: string): boolean {
33-
if (SKIP_PATHS.has(path)) return true;
34-
if (path.endsWith(".tmp")) return true;
35-
for (const p of SKIP_PREFIXES) if (path.startsWith(p)) return true;
36-
if (path.startsWith(".obsidian/workspace")) return true;
37-
return false;
26+
// The list of *which* plugins to enable still syncs via community-plugins.json.
27+
const skipPrefixes = [".trash/", `${configDir}/plugins/`];
28+
const workspacePrefix = `${configDir}/workspace`;
29+
return (path: string) => {
30+
if (skipPaths.has(path)) return true;
31+
if (path.endsWith(".tmp")) return true;
32+
for (const p of skipPrefixes) if (path.startsWith(p)) return true;
33+
if (path.startsWith(workspacePrefix)) return true;
34+
return false;
35+
};
3836
}
3937

4038
async function gitBlobSha(content: ArrayBuffer): Promise<string> {
@@ -86,23 +84,24 @@ export async function pushToGitHub(
8684
const ref = parseRepoUrl(repoUrl);
8785
const notice = opts.silent
8886
? null
89-
: new Notice("Vault Sync: scanning local changes…", 0);
87+
: new Notice("Scanning local changes…", 0);
9088

9189
// 1. Detect divergence — refuse if remote moved.
9290
const remoteHead = await getBranchSha(ref, branch || "main", pat);
9391
if (remoteHead !== lastCommitSha) {
9492
notice?.hide();
9593
throw new Error(
96-
`Remote advanced (${remoteHead.slice(0, 7)} vs local baseline ${lastCommitSha.slice(0, 7)}). Run 'Vault Sync: Pull from GitHub' first.`
94+
`Remote advanced (${remoteHead.slice(0, 7)} vs local baseline ${lastCommitSha.slice(0, 7)}). Run 'Pull from GitHub' first.`
9795
);
9896
}
9997

10098
// 2. Walk vault, hash every non-skipped file, compare to fileShaMap.
99+
const shouldSkip = buildSkipFn(plugin.app.vault.configDir);
101100
const allPaths = await listAllVaultFiles(plugin);
102101
const localFiles = allPaths.filter((p) => !shouldSkip(p));
103102
const localSet = new Set(localFiles);
104103

105-
notice?.setMessage(`Vault Sync: hashing ${localFiles.length} files…`);
104+
notice?.setMessage(`Hashing ${localFiles.length} files…`);
106105

107106
type Change = { path: string; kind: "add" | "modify"; content: ArrayBuffer };
108107
const changes: Change[] = [];
@@ -121,7 +120,7 @@ export async function pushToGitHub(
121120
scanned++;
122121
if (scanned % 50 === 0) {
123122
notice?.setMessage(
124-
`Vault Sync: hashed ${scanned}/${localFiles.length}…`
123+
`Hashed ${scanned}/${localFiles.length}…`
125124
);
126125
}
127126
}
@@ -131,14 +130,14 @@ export async function pushToGitHub(
131130
}
132131

133132
if (changes.length === 0 && deletions.length === 0) {
134-
notice?.setMessage("Vault Sync: nothing to push");
133+
notice?.setMessage("Nothing to push");
135134
setTimeout(() => notice?.hide(), 4000);
136135
return;
137136
}
138137

139138
// 3. Upload blobs for changed files (sequential to keep memory bounded for large files).
140139
notice?.setMessage(
141-
`Vault Sync: uploading ${changes.length} blobs (${deletions.length} deletions)…`
140+
`Uploading ${changes.length} blobs (${deletions.length} deletions)…`
142141
);
143142

144143
const treeEntries: TreeUpdateEntry[] = [];
@@ -156,7 +155,7 @@ export async function pushToGitHub(
156155
bytes += c.content.byteLength;
157156
if (uploaded % 5 === 0) {
158157
notice?.setMessage(
159-
`Vault Sync: uploaded ${uploaded}/${changes.length} (${formatBytes(bytes)})`
158+
`Uploaded ${uploaded}/${changes.length} (${formatBytes(bytes)})`
160159
);
161160
}
162161
}
@@ -166,12 +165,12 @@ export async function pushToGitHub(
166165
}
167166

168167
// 4. Build new tree on top of the last commit's tree.
169-
notice?.setMessage("Vault Sync: creating tree…");
168+
notice?.setMessage("Creating tree…");
170169
const baseTreeSha = await getCommitTreeSha(ref, lastCommitSha, pat);
171170
const newTreeSha = await createTree(ref, baseTreeSha, treeEntries, pat);
172171

173172
// 5. Create commit.
174-
notice?.setMessage("Vault Sync: creating commit…");
173+
notice?.setMessage("Creating commit…");
175174
const message = `Vault Sync: ${changes.length} changed, ${deletions.length} deleted from mobile`;
176175
const newCommitSha = await createCommit(
177176
ref,
@@ -182,7 +181,7 @@ export async function pushToGitHub(
182181
);
183182

184183
// 6. Update branch ref.
185-
notice?.setMessage("Vault Sync: updating branch…");
184+
notice?.setMessage("Updating branch…");
186185
const upd = await updateRef(ref, branch || "main", newCommitSha, pat);
187186
if (!upd.ok) {
188187
notice?.hide();
@@ -204,7 +203,7 @@ export async function pushToGitHub(
204203
await plugin.saveSettings();
205204

206205
notice?.setMessage(
207-
`Vault Sync: pushed ${changes.length} changes (${formatBytes(bytes)}) → ${newCommitSha.slice(0, 7)}`
206+
`Pushed ${changes.length} changes (${formatBytes(bytes)}) → ${newCommitSha.slice(0, 7)}`
208207
);
209208
setTimeout(() => notice?.hide(), 6000);
210209
}

src/seed.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function ensureDir(plugin: VaultSyncPlugin, dirPath: string): Promise<void
1919
if (!dirPath || dirPath === "/" || dirPath === ".") return;
2020
try {
2121
await plugin.app.vault.adapter.mkdir(dirPath);
22-
} catch (_e) {
22+
} catch {
2323
// already exists
2424
}
2525
}
@@ -73,7 +73,7 @@ export async function seedFromGitHub(plugin: VaultSyncPlugin): Promise<void> {
7373
if (!repoUrl) throw new Error("Set a repo URL in Vault Sync settings.");
7474

7575
const ref = parseRepoUrl(repoUrl);
76-
const notice = new Notice("Vault Sync: resolving branch…", 0);
76+
const notice = new Notice("Resolving branch…", 0);
7777

7878
let sha: string;
7979
try {
@@ -83,7 +83,7 @@ export async function seedFromGitHub(plugin: VaultSyncPlugin): Promise<void> {
8383
throw e;
8484
}
8585

86-
notice.setMessage(`Vault Sync: listing ${ref.owner}/${ref.repo}@${sha.slice(0, 7)}…`);
86+
notice.setMessage(`Listing ${ref.owner}/${ref.repo}@${sha.slice(0, 7)}…`);
8787

8888
let tree: TreeEntry[];
8989
try {
@@ -97,7 +97,7 @@ export async function seedFromGitHub(plugin: VaultSyncPlugin): Promise<void> {
9797
const blobs = tree.filter((e) => e.type === "blob");
9898

9999
notice.setMessage(
100-
`Vault Sync: ${blobs.length} files, ${dirs.length} dirs — preparing…`
100+
`${blobs.length} files, ${dirs.length} dirs — preparing…`
101101
);
102102

103103
// Pre-create all directories sequentially (cheap, prevents race conditions).
@@ -118,7 +118,7 @@ export async function seedFromGitHub(plugin: VaultSyncPlugin): Promise<void> {
118118
byteCount += content.byteLength;
119119
if (fileCount % PROGRESS_EVERY === 0) {
120120
notice.setMessage(
121-
`Vault Sync: ${fileCount}/${blobs.length} files, ${formatBytes(byteCount)}`
121+
`${fileCount}/${blobs.length} files, ${formatBytes(byteCount)}`
122122
);
123123
}
124124
});
@@ -128,7 +128,7 @@ export async function seedFromGitHub(plugin: VaultSyncPlugin): Promise<void> {
128128
await plugin.saveSettings();
129129

130130
notice.setMessage(
131-
`Vault Sync: seed complete — ${fileCount} files, ${formatBytes(byteCount)} @ ${sha.slice(0, 7)}`
131+
`Seed complete — ${fileCount} files, ${formatBytes(byteCount)} @ ${sha.slice(0, 7)}`
132132
);
133133
setTimeout(() => notice.hide(), 6000);
134134
}

src/settings.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ export class VaultSyncSettingTab extends PluginSettingTab {
3131
const { containerEl } = this;
3232
containerEl.empty();
3333

34-
containerEl.createEl("h2", { text: "Vault Sync (REST)" });
35-
3634
new Setting(containerEl)
37-
.setName("GitHub Personal Access Token")
35+
.setName("GitHub personal access token")
3836
.setDesc(
3937
"Fine-grained or classic PAT with repo (contents: read/write) scope on the target repo."
4038
)
@@ -50,7 +48,7 @@ export class VaultSyncSettingTab extends PluginSettingTab {
5048

5149
new Setting(containerEl)
5250
.setName("Repository URL")
53-
.setDesc("e.g. https://github.com/owner/repo")
51+
.setDesc("For example, https://github.com/owner/repo")
5452
.addText((text) =>
5553
text
5654
.setPlaceholder("https://github.com/owner/repo")

0 commit comments

Comments
 (0)