72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
import type {
|
|
ICommonResponse,
|
|
IImageGenerateData,
|
|
IImageGenerateRequest,
|
|
IImageHistoryListData,
|
|
IImagePublicStateData,
|
|
IPlazaPostListData
|
|
} from "#shared/types";
|
|
|
|
export class ImageService {
|
|
public static basePath = "/api/images";
|
|
|
|
/** 发起生图请求,成功后返回当前可展示的图片地址。 */
|
|
public static GenerateImage(request: IImageGenerateRequest) {
|
|
return $fetch<ICommonResponse<IImageGenerateData>>(
|
|
`${ImageService.basePath}/generate`,
|
|
{
|
|
method: "POST",
|
|
body: request
|
|
}
|
|
);
|
|
}
|
|
|
|
/** 分页读取当前登录用户的生图历史记录。 */
|
|
public static GetImageHistory(page = 1, size = 10) {
|
|
return $fetch<ICommonResponse<IImageHistoryListData>>(
|
|
`${ImageService.basePath}/history`,
|
|
{
|
|
method: "GET",
|
|
query: {
|
|
page,
|
|
size
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
/** 分页读取广场中所有用户可见的公开图片。 */
|
|
public static GetPlazaPosts(page = 1, size = 20) {
|
|
return $fetch<ICommonResponse<IPlazaPostListData>>(
|
|
`${ImageService.basePath}/plaza`,
|
|
{
|
|
method: "GET",
|
|
query: {
|
|
page,
|
|
size
|
|
}
|
|
}
|
|
);
|
|
}
|
|
|
|
/** 将当前用户的一条生图历史发布到广场。 */
|
|
public static PublishHistoryImage(recordId: string) {
|
|
return $fetch<ICommonResponse<IImagePublicStateData>>(
|
|
`${ImageService.basePath}/history/${recordId}/public`,
|
|
{
|
|
method: "POST"
|
|
}
|
|
);
|
|
}
|
|
|
|
/** 取消公开当前用户的一条广场图片,服务端会软隐藏发布记录。 */
|
|
public static HideHistoryImage(recordId: string) {
|
|
return $fetch<ICommonResponse<IImagePublicStateData>>(
|
|
`${ImageService.basePath}/history/${recordId}/public`,
|
|
{
|
|
method: "DELETE"
|
|
}
|
|
);
|
|
}
|
|
}
|