124 lines
2.8 KiB
TypeScript
124 lines
2.8 KiB
TypeScript
/**
|
|
* 图片生成 API 客户端
|
|
* /api/v1/image
|
|
*/
|
|
|
|
import { fetchWithAuth } from "./client";
|
|
|
|
// ============================================================
|
|
// 类型定义
|
|
// ============================================================
|
|
|
|
export interface ImageResult {
|
|
url: string;
|
|
width: number;
|
|
height: number;
|
|
prompt: string;
|
|
platform: string;
|
|
task_id: string;
|
|
}
|
|
|
|
export interface GenerateCoverRequest {
|
|
title: string;
|
|
platform: string;
|
|
image_type?: "cover" | "inline";
|
|
style?: string;
|
|
layout?: string;
|
|
custom_prompt?: string;
|
|
}
|
|
|
|
export interface ImageSpecs {
|
|
width: number;
|
|
height: number;
|
|
ratio: string;
|
|
}
|
|
|
|
export interface PlatformImageSpecs {
|
|
cover: ImageSpecs;
|
|
inline?: ImageSpecs;
|
|
}
|
|
|
|
export interface StyleOption {
|
|
value: string;
|
|
name: string;
|
|
}
|
|
|
|
export interface LayoutOption {
|
|
value: string;
|
|
name: string;
|
|
}
|
|
|
|
export interface ImageConfig {
|
|
platforms: string[];
|
|
styles: StyleOption[];
|
|
layouts: LayoutOption[];
|
|
}
|
|
|
|
// ============================================================
|
|
// API 函数
|
|
// ============================================================
|
|
|
|
export const imageApi = {
|
|
/**
|
|
* 生成封面图
|
|
*/
|
|
generateCover: async (
|
|
request: GenerateCoverRequest,
|
|
token?: string
|
|
): Promise<ImageResult> => {
|
|
return fetchWithAuth(
|
|
"/api/v1/image/generate-cover",
|
|
{
|
|
method: "POST",
|
|
body: JSON.stringify(request),
|
|
},
|
|
token
|
|
) as Promise<ImageResult>;
|
|
},
|
|
|
|
/**
|
|
* 获取支持的平台列表
|
|
*/
|
|
getSupportedPlatforms: async (): Promise<string[]> => {
|
|
return fetchWithAuth("/api/v1/image/platforms", {}) as Promise<string[]>;
|
|
},
|
|
|
|
/**
|
|
* 获取平台图片规格
|
|
*/
|
|
getPlatformSpecs: async (
|
|
platform: string,
|
|
token?: string
|
|
): Promise<{ platform: string; specs: PlatformImageSpecs }> => {
|
|
return fetchWithAuth(
|
|
`/api/v1/image/platforms/${platform}/specs`,
|
|
{},
|
|
token
|
|
) as Promise<{ platform: string; specs: PlatformImageSpecs }>;
|
|
},
|
|
|
|
/**
|
|
* 获取图片生成配置(风格、排版选项等)
|
|
*/
|
|
getConfig: async (): Promise<ImageConfig> => {
|
|
return fetchWithAuth("/api/v1/image/config", {}) as Promise<ImageConfig>;
|
|
},
|
|
};
|
|
|
|
// 图片生成配置常量
|
|
export const IMAGE_GENERATION_CONFIG = {
|
|
platforms: ["zhihu", "wechat", "xiaohongshu", "toutiao", "baijiahao", "weibo", "bilibili", "jianshu", "juejin", "douyin"],
|
|
styles: [
|
|
{ value: "modern", label: "现代简约" },
|
|
{ value: "tech", label: "科技感" },
|
|
{ value: "elegant", label: "优雅商务" },
|
|
{ value: "creative", label: "创意活力" },
|
|
{ value: "minimal", label: "极简主义" },
|
|
],
|
|
layouts: [
|
|
{ value: "centered", label: "居中排版" },
|
|
{ value: "left_text", label: "左文右图" },
|
|
{ value: "top_text", label: "上文下图" },
|
|
{ value: "text_overlay", label: "文字叠加" },
|
|
],
|
|
}; |