Renames the repo directory and every podpuddle/PODPUDDLE reference across code, config, and docs to podsteadr/PODSTEADR (package names, Docker Compose project/service/volume names, env var names, UI/RSS strings). Existing Docker volume data (uploaded blobs, mediamtx recordings, the server's sqlite DB and its nostr identity key) was migrated to new podsteadr_-prefixed volumes with matching filenames so it isn't orphaned by the rename.
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
// Thin fetch wrapper for the podsteadr API (session cookie auth).
|
|
|
|
export class ApiError extends Error {
|
|
constructor(public status: number, message: string) {
|
|
super(message);
|
|
}
|
|
}
|
|
|
|
async function request<T>(method: string, path: string, body?: unknown, headers?: Record<string, string>): Promise<T> {
|
|
const res = await fetch(path, {
|
|
method,
|
|
credentials: 'same-origin',
|
|
headers: {
|
|
...(body !== undefined ? { 'content-type': 'application/json' } : {}),
|
|
...headers,
|
|
},
|
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
});
|
|
if (!res.ok) {
|
|
let message = res.statusText;
|
|
try {
|
|
message = ((await res.json()) as { error?: string }).error ?? message;
|
|
} catch {
|
|
/* keep statusText */
|
|
}
|
|
throw new ApiError(res.status, message);
|
|
}
|
|
return (await res.json()) as T;
|
|
}
|
|
|
|
export const api = {
|
|
get: <T>(path: string) => request<T>('GET', path),
|
|
post: <T>(path: string, body?: unknown, headers?: Record<string, string>) =>
|
|
request<T>('POST', path, body, headers),
|
|
put: <T>(path: string, body?: unknown) => request<T>('PUT', path, body),
|
|
delete: <T>(path: string) => request<T>('DELETE', path),
|
|
};
|