Download src/api/images.ts from ghuser1/pl: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/ghuser1/pl/resolve/main/src/api/images.ts
- Command line
-
hf download hf://spaces/ghuser1/pl/src/api/images.ts
-
curl -L -o images.ts https://huggingface.co/spaces/ghuser1/pl/resolve/main/src/api/images.ts
1.06 kB
| import { Hono } from 'hono'; | |
| import { desc, eq } from 'drizzle-orm'; | |
| import { images, prompts } from '../db/schema'; | |
| import type { Env, Variables } from '../index'; | |
| export const imagesApi = new Hono<{ Bindings: Env; Variables: Variables }>(); | |
| // 全部生成历史,关联 prompt title,按时间倒序 | |
| imagesApi.get('/', async (c) => { | |
| const db = c.var.db; | |
| const rows = await db | |
| .select({ | |
| id: images.id, | |
| promptId: images.promptId, | |
| b64: images.b64, | |
| model: images.model, | |
| size: images.size, | |
| quality: images.quality, | |
| generationDuration: images.generationDuration, | |
| promptUsed: images.promptUsed, | |
| createdAt: images.createdAt, | |
| promptTitle: prompts.title, | |
| }) | |
| .from(images) | |
| .leftJoin(prompts, eq(images.promptId, prompts.id)) | |
| .orderBy(desc(images.createdAt)); | |
| return c.json(rows); | |
| }); | |
| // 删除单张历史 | |
| imagesApi.delete('/:id', async (c) => { | |
| const db = c.var.db; | |
| await db.delete(images).where(eq(images.id, c.req.param('id'))); | |
| return c.json({ ok: true }); | |
| }); | |