mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
client.ts had grown to 1835 lines of types and calls for every page. In six months it changed in 71 commits, more than any other source file, so almost every dashboard change had to edit one oversized file. The transport now lives in http.ts, and each domain has its own call module and type file. client.ts stays as a barrel that composes the same api object. The 124 exported names and 145 api keys are unchanged, so importers and the tests that mock api/client need no edits. Domain modules import from http.ts, not from client.ts, which avoids an import cycle through the barrel.
62 lines
2.7 KiB
TypeScript
62 lines
2.7 KiB
TypeScript
import { apiFetch } from './http';
|
|
import type { ExtensionInfo, Extra, ExtraDiffResult, ExtrasSyncResult } from './types/extras';
|
|
|
|
export const extrasApi = {
|
|
listExtras: () => apiFetch<{ extras: Extra[] }>('/extras'),
|
|
diffExtras: (name?: string) =>
|
|
apiFetch<{ extras: ExtraDiffResult[] }>(`/extras/diff${name ? '?name=' + encodeURIComponent(name) : ''}`),
|
|
createExtra: (data: {
|
|
name: string;
|
|
source?: string;
|
|
folder?: string; // a folder in the shared extras folder; the server stores it as the source
|
|
file?: string; // single-file extra: the file in the source folder
|
|
targets: Array<{ path: string; mode: string; flatten?: boolean; extension?: string; as?: string }>;
|
|
}) =>
|
|
apiFetch<{ success: boolean }>('/extras', {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
}),
|
|
syncExtras: (opts?: { name?: string; dry_run?: boolean; force?: boolean }) =>
|
|
apiFetch<{ extras: ExtrasSyncResult[] }>('/extras/sync', {
|
|
method: 'POST',
|
|
body: JSON.stringify(opts ?? {}),
|
|
}),
|
|
deleteExtra: (name: string) =>
|
|
apiFetch<{ success: boolean }>(`/extras/${encodeURIComponent(name)}`, { method: 'DELETE' }),
|
|
listExtraExtensions: () => apiFetch<{ extensions: string[] }>('/extras/extensions'),
|
|
// Extensions management (Config page)
|
|
listExtensions: () => apiFetch<{ extensions: ExtensionInfo[] }>('/extensions'),
|
|
installExtension: (name: string) =>
|
|
apiFetch<{ success: boolean; name: string }>('/extensions/install', {
|
|
method: 'POST',
|
|
body: JSON.stringify({ name }),
|
|
}),
|
|
openExtensionsDir: () =>
|
|
apiFetch<{ path: string }>('/extensions/open', { method: 'POST' }),
|
|
removeExtension: (name: string) =>
|
|
apiFetch<{ success: boolean; name: string }>(`/extensions/${encodeURIComponent(name)}`, {
|
|
method: 'DELETE',
|
|
}),
|
|
// extension: undefined = leave unchanged; '' = clear; name = set (forces copy mode)
|
|
setExtraMode: (name: string, target: string, mode: string, flatten?: boolean, extension?: string) =>
|
|
apiFetch<{ success: boolean }>(`/extras/${encodeURIComponent(name)}/mode`, {
|
|
method: 'PATCH',
|
|
body: JSON.stringify({
|
|
target,
|
|
mode,
|
|
...(flatten !== undefined && { flatten }),
|
|
...(extension !== undefined && { extension }),
|
|
}),
|
|
}),
|
|
addExtraTarget: (name: string, target: { path: string; mode?: string; flatten?: boolean; as?: string }) =>
|
|
apiFetch<{ success: boolean }>(`/extras/${encodeURIComponent(name)}/targets`, {
|
|
method: 'POST',
|
|
body: JSON.stringify(target),
|
|
}),
|
|
removeExtraTarget: (name: string, path: string) =>
|
|
apiFetch<{ success: boolean }>(`/extras/${encodeURIComponent(name)}/targets`, {
|
|
method: 'DELETE',
|
|
body: JSON.stringify({ path }),
|
|
}),
|
|
};
|