f7bdedf7d2
Co-authored-by: Copilot <copilot@github.com>
75 lines
1.7 KiB
TypeScript
75 lines
1.7 KiB
TypeScript
// server/utils/promptPresets.ts - 预设提示词数据库查询:为前端提供可分页展示的预设列表。
|
|
import type {
|
|
IPromptPresetItem,
|
|
IPromptPresetListData
|
|
} from "#shared/types/openai";
|
|
import { prisma } from "~~/server/utils/prisma";
|
|
|
|
export const listPromptPresets = async ({
|
|
page,
|
|
pageSize
|
|
}: {
|
|
page: number;
|
|
pageSize: number;
|
|
}): Promise<IPromptPresetListData> => {
|
|
const where = {
|
|
enabled: true
|
|
};
|
|
|
|
const [total, records] = await Promise.all([
|
|
prisma.promptPreset.count({ where }),
|
|
prisma.promptPreset.findMany({
|
|
where,
|
|
orderBy: [
|
|
{
|
|
sortOrder: "asc"
|
|
},
|
|
{
|
|
id: "asc"
|
|
}
|
|
],
|
|
skip: (page - 1) * pageSize,
|
|
take: pageSize
|
|
})
|
|
]);
|
|
|
|
return {
|
|
page,
|
|
pageSize,
|
|
total,
|
|
items: records.map(mapPromptPresetItem)
|
|
};
|
|
};
|
|
|
|
const mapPromptPresetItem = (record: {
|
|
id: bigint;
|
|
sourceId: string;
|
|
name: string;
|
|
promptRaw: string;
|
|
prompt: string;
|
|
negativePrompt: string;
|
|
category: string;
|
|
tags: unknown;
|
|
aspectRatio: string;
|
|
previewUrl: string;
|
|
compressedPreviewUrl: string;
|
|
sortOrder: number;
|
|
}): IPromptPresetItem => {
|
|
return {
|
|
id: record.id.toString(),
|
|
sourceId: record.sourceId,
|
|
name: record.name,
|
|
promptRaw: record.promptRaw,
|
|
prompt: record.prompt,
|
|
negativePrompt: record.negativePrompt,
|
|
category: record.category,
|
|
tags: Array.isArray(record.tags)
|
|
? record.tags.filter((tag): tag is string => typeof tag === "string")
|
|
: [],
|
|
aspectRatio: record.aspectRatio,
|
|
previewUrl: record.previewUrl,
|
|
compressedPreviewUrl: record.compressedPreviewUrl,
|
|
sortOrder: record.sortOrder
|
|
};
|
|
};
|