File size: 1,055 Bytes
cfea436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 });
});