21 lines
583 B
TypeScript
21 lines
583 B
TypeScript
|
|
import { mockDelay } from "./mockAi";
|
||
|
|
import { newId } from "./id";
|
||
|
|
|
||
|
|
export type GeneratedImage = {
|
||
|
|
id: string;
|
||
|
|
url: string;
|
||
|
|
prompt: string;
|
||
|
|
};
|
||
|
|
|
||
|
|
/** mock 產圖:用 dicebear 當可顯示縮圖 */
|
||
|
|
export async function mockGenerateImage(prompt: string): Promise<GeneratedImage> {
|
||
|
|
await mockDelay(700);
|
||
|
|
const p = prompt.trim() || "threads post visual";
|
||
|
|
const seed = encodeURIComponent(p.slice(0, 48) || "harbor");
|
||
|
|
return {
|
||
|
|
id: newId("img"),
|
||
|
|
url: `https://api.dicebear.com/9.x/shapes/svg?seed=${seed}&backgroundColor=b6e3f4,c0aede,ffd5dc`,
|
||
|
|
prompt: p,
|
||
|
|
};
|
||
|
|
}
|