mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-12 22:42:13 +02:00
feat(podcasts): add frontend contracts and lifecycle api service
This commit is contained in:
parent
c84525897b
commit
64b36f2622
2 changed files with 178 additions and 0 deletions
58
surfsense_web/lib/apis/podcasts-api.service.ts
Normal file
58
surfsense_web/lib/apis/podcasts-api.service.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import { z } from "zod";
|
||||
import {
|
||||
type PodcastSpec,
|
||||
podcastDetail,
|
||||
updateSpecRequest,
|
||||
voiceOption,
|
||||
} from "@/contracts/types/podcast.types";
|
||||
import { ValidationError } from "../error";
|
||||
import { baseApiService } from "./base-api.service";
|
||||
|
||||
const BASE = "/api/v1/podcasts";
|
||||
|
||||
const voiceOptionList = z.array(voiceOption);
|
||||
|
||||
class PodcastsApiService {
|
||||
// Full state including the deserialized brief and transcript; thin lifecycle
|
||||
// fields (status, spec, spec_version) also arrive live via Zero.
|
||||
getDetail = async (podcastId: number) => {
|
||||
return baseApiService.get(`${BASE}/${podcastId}`, podcastDetail);
|
||||
};
|
||||
|
||||
// Guarded by the version the caller last saw; the backend answers 409 when
|
||||
// the brief changed underneath them.
|
||||
updateSpec = async (podcastId: number, spec: PodcastSpec, expectedVersion: number) => {
|
||||
const parsed = updateSpecRequest.safeParse({ spec, expected_version: expectedVersion });
|
||||
if (!parsed.success) {
|
||||
throw new ValidationError(
|
||||
`Invalid request: ${parsed.error.issues.map((i) => i.message).join(", ")}`
|
||||
);
|
||||
}
|
||||
return baseApiService.patch(`${BASE}/${podcastId}/spec`, podcastDetail, {
|
||||
body: parsed.data,
|
||||
});
|
||||
};
|
||||
|
||||
approveBrief = async (podcastId: number) => {
|
||||
return baseApiService.post(`${BASE}/${podcastId}/brief/approve`, podcastDetail);
|
||||
};
|
||||
|
||||
approveTranscript = async (podcastId: number) => {
|
||||
return baseApiService.post(`${BASE}/${podcastId}/transcript/approve`, podcastDetail);
|
||||
};
|
||||
|
||||
regenerateTranscript = async (podcastId: number) => {
|
||||
return baseApiService.post(`${BASE}/${podcastId}/transcript/regenerate`, podcastDetail);
|
||||
};
|
||||
|
||||
cancel = async (podcastId: number) => {
|
||||
return baseApiService.post(`${BASE}/${podcastId}/cancel`, podcastDetail);
|
||||
};
|
||||
|
||||
listVoices = async (language?: string) => {
|
||||
const qs = language ? `?${new URLSearchParams({ language })}` : "";
|
||||
return baseApiService.get(`${BASE}/voices${qs}`, voiceOptionList);
|
||||
};
|
||||
}
|
||||
|
||||
export const podcastsApiService = new PodcastsApiService();
|
||||
Loading…
Add table
Add a link
Reference in a new issue