Skip to content

Commit f44fe59

Browse files
committed
feat(api): include shell config and macOS prefs in config responses
Both /[username]/[slug]/config and /api/configs/alias/[alias] endpoints now return shell (oh_my_zsh, theme, plugins) and macos_prefs fields parsed from the snapshot. This enables the CLI sync command to compare and apply shell and macOS preference changes.
1 parent 8760972 commit f44fe59

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

src/routes/[username]/[slug]/config/+server.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export const GET: RequestHandler = async ({ platform, params, request }) => {
4141

4242
const tapsSet = new Set<string>();
4343
const snapshotCasks = new Set<string>();
44+
let shell: { oh_my_zsh: boolean; theme: string; plugins: string[] } | null = null;
45+
let macosPrefs: { domain: string; key: string; value: string; desc: string }[] | null = null;
4446

4547
if (config.snapshot) {
4648
try {
@@ -51,7 +53,27 @@ export const GET: RequestHandler = async ({ platform, params, request }) => {
5153
for (const cask of snapshot.packages?.casks || []) {
5254
snapshotCasks.add(cask);
5355
}
54-
} catch {
56+
if (snapshot.shell) {
57+
shell = {
58+
oh_my_zsh: snapshot.shell.oh_my_zsh ?? false,
59+
theme: snapshot.shell.theme ?? '',
60+
plugins: snapshot.shell.plugins ?? []
61+
};
62+
}
63+
if (Array.isArray(snapshot.macos_prefs) && snapshot.macos_prefs.length > 0) {
64+
const filtered = snapshot.macos_prefs.filter(
65+
(p: unknown): p is { domain: string; key: string; value: string; desc: string } =>
66+
typeof p === 'object' &&
67+
p !== null &&
68+
typeof (p as Record<string, unknown>).domain === 'string' &&
69+
typeof (p as Record<string, unknown>).key === 'string' &&
70+
typeof (p as Record<string, unknown>).value === 'string' &&
71+
typeof (p as Record<string, unknown>).desc === 'string'
72+
);
73+
if (filtered.length > 0) macosPrefs = filtered;
74+
}
75+
} catch (err) {
76+
console.error(`[config] failed to parse snapshot for ${params.username}/${params.slug}:`, err);
5577
}
5678
}
5779

@@ -99,6 +121,8 @@ export const GET: RequestHandler = async ({ platform, params, request }) => {
99121
dotfiles_repo: config.dotfiles_repo || '',
100122
post_install: config.custom_script
101123
? config.custom_script.split('\n').map((s: string) => s.trim()).filter((s: string) => s.length > 0)
102-
: []
124+
: [],
125+
shell,
126+
macos_prefs: macosPrefs
103127
});
104128
};

src/routes/api/configs/alias/[alias]/+server.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const GET: RequestHandler = async ({ platform, params }) => {
2727

2828
const tapsSet = new Set<string>();
2929
const snapshotCasks = new Set<string>();
30+
let shell: { oh_my_zsh: boolean; theme: string; plugins: string[] } | null = null;
31+
let macosPrefs: { domain: string; key: string; value: string; desc: string }[] | null = null;
3032

3133
if (config.snapshot) {
3234
try {
@@ -37,7 +39,27 @@ export const GET: RequestHandler = async ({ platform, params }) => {
3739
for (const cask of snapshot.packages?.casks || []) {
3840
snapshotCasks.add(cask);
3941
}
40-
} catch {
42+
if (snapshot.shell) {
43+
shell = {
44+
oh_my_zsh: snapshot.shell.oh_my_zsh ?? false,
45+
theme: snapshot.shell.theme ?? '',
46+
plugins: snapshot.shell.plugins ?? []
47+
};
48+
}
49+
if (Array.isArray(snapshot.macos_prefs) && snapshot.macos_prefs.length > 0) {
50+
const filtered = snapshot.macos_prefs.filter(
51+
(p: unknown): p is { domain: string; key: string; value: string; desc: string } =>
52+
typeof p === 'object' &&
53+
p !== null &&
54+
typeof (p as Record<string, unknown>).domain === 'string' &&
55+
typeof (p as Record<string, unknown>).key === 'string' &&
56+
typeof (p as Record<string, unknown>).value === 'string' &&
57+
typeof (p as Record<string, unknown>).desc === 'string'
58+
);
59+
if (filtered.length > 0) macosPrefs = filtered;
60+
}
61+
} catch (err) {
62+
console.error(`[config] failed to parse snapshot for alias ${params.alias}:`, err);
4163
}
4264
}
4365

@@ -85,6 +107,8 @@ export const GET: RequestHandler = async ({ platform, params }) => {
85107
dotfiles_repo: config.dotfiles_repo || '',
86108
post_install: config.custom_script
87109
? config.custom_script.split('\n').map((s: string) => s.trim()).filter((s: string) => s.length > 0)
88-
: []
110+
: [],
111+
shell,
112+
macos_prefs: macosPrefs
89113
});
90114
};

0 commit comments

Comments
 (0)