Files
cozsweet-frontend-nextjs/src/data/services/api/private_zone_post_api.ts
T
Codex 0d5b5c17fa
Docker Image / Build and Push Docker Image (push) Successful in 2m5s
feat(private-zone): add paid video moments
2026-07-24 20:19:49 +08:00

50 lines
1.4 KiB
TypeScript

import {
PrivateZonePostsResponseSchema,
PrivateZonePostUnlockResponseSchema,
type PrivateZonePostsResponse,
type PrivateZonePostUnlockResponse,
type UnlockPrivateZonePostRequest,
} from "@/data/schemas/private-zone";
import { ApiPath } from "./api_path";
import { httpClient } from "./http_client";
import { type ApiEnvelope, unwrap } from "./response_helper";
export interface GetPrivateZonePostsInput {
characterId: string;
limit?: number;
cursor?: string | null;
}
export class PrivateZonePostApi {
async getPosts(
input: GetPrivateZonePostsInput,
): Promise<PrivateZonePostsResponse> {
const env = await httpClient<ApiEnvelope<unknown>>(
ApiPath.privateZonePosts,
{
query: {
characterId: input.characterId,
limit: input.limit ?? 20,
cursor: input.cursor || undefined,
},
},
);
return PrivateZonePostsResponseSchema.parse(unwrap(env));
}
async unlockPost(
postId: string,
body: UnlockPrivateZonePostRequest,
): Promise<PrivateZonePostUnlockResponse> {
const env = await httpClient<ApiEnvelope<unknown>>(
ApiPath.privateZonePostUnlock(postId),
{ method: "POST", body },
);
const parsed = PrivateZonePostUnlockResponseSchema.parse(unwrap(env));
return parsed.postId ? parsed : { ...parsed, postId };
}
}
export const privateZonePostApi = new PrivateZonePostApi();