feat(container): add CRUD operations for container management

- Implemented routes for listing, retrieving, updating, and deleting containers.
- Added ContainerModel with necessary fields and methods for data handling.
- Created utility functions for fetching container data by ID.

feat(page): enhance page management with CRUD and publish functionality

- Developed routes for managing pages, including listing, updating, and deleting.
- Integrated caching and zip file generation for page exports.
- Added publish functionality to manage app versions and file uploads.

feat(prompts): implement prompt management with CRUD operations

- Created routes for listing, updating, and deleting prompts.
- Added pagination and search capabilities for prompt listing.

test: add common query utilities and prompt tests

- Implemented common query utilities for API interactions.
- Added tests for prompt listing functionality.
This commit is contained in:
2025-12-30 13:28:50 +08:00
parent 27e5fb5e82
commit 8731801b52
28 changed files with 411 additions and 103 deletions

View File

@@ -0,0 +1,42 @@
CREATE TABLE "cf_prompts" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"uid" uuid,
"parents" jsonb DEFAULT '[]'::jsonb NOT NULL,
"data" jsonb DEFAULT '{}'::jsonb NOT NULL,
"title" text DEFAULT '',
"description" text DEFAULT '',
"summary" text DEFAULT '',
"tags" jsonb DEFAULT '[]'::jsonb NOT NULL,
"link" text DEFAULT '',
"createdAt" timestamp DEFAULT now() NOT NULL,
"updatedAt" timestamp DEFAULT now() NOT NULL,
"deletedAt" timestamp
);
--> statement-breakpoint
DROP TABLE "TestPromptTools" CASCADE;--> statement-breakpoint
DROP TABLE "ai_agent" CASCADE;--> statement-breakpoint
DROP TABLE "apps_trades" CASCADE;--> statement-breakpoint
DROP TABLE "cf_orgs" CASCADE;--> statement-breakpoint
DROP TABLE "cf_router_code" CASCADE;--> statement-breakpoint
DROP TABLE "cf_user" CASCADE;--> statement-breakpoint
DROP TABLE "cf_user_secrets" CASCADE;--> statement-breakpoint
DROP TABLE "chat_histories" CASCADE;--> statement-breakpoint
DROP TABLE "chat_prompts" CASCADE;--> statement-breakpoint
DROP TABLE "chat_sessions" CASCADE;--> statement-breakpoint
DROP TABLE "file_sync" CASCADE;--> statement-breakpoint
DROP TABLE "kv_ai_chat_history" CASCADE;--> statement-breakpoint
DROP TABLE "kv_app" CASCADE;--> statement-breakpoint
DROP TABLE "kv_app_domain" CASCADE;--> statement-breakpoint
DROP TABLE "kv_app_list" CASCADE;--> statement-breakpoint
DROP TABLE "kv_config" CASCADE;--> statement-breakpoint
DROP TABLE "kv_container" CASCADE;--> statement-breakpoint
DROP TABLE "kv_github" CASCADE;--> statement-breakpoint
DROP TABLE "kv_packages" CASCADE;--> statement-breakpoint
DROP TABLE "kv_page" CASCADE;--> statement-breakpoint
DROP TABLE "kv_resource" CASCADE;--> statement-breakpoint
DROP TABLE "kv_vip" CASCADE;--> statement-breakpoint
DROP TABLE "micro_apps_upload" CASCADE;--> statement-breakpoint
DROP TABLE "micro_mark" CASCADE;--> statement-breakpoint
DROP TABLE "prompts" CASCADE;--> statement-breakpoint
DROP TABLE "work_share_mark" CASCADE;--> statement-breakpoint
DROP TYPE "public"."enum_cf_router_code_type";

View File

@@ -0,0 +1,114 @@
{
"id": "f87c2440-e0ce-4caa-ab13-560d9aac9e8e",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.cf_prompts": {
"name": "cf_prompts",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "gen_random_uuid()"
},
"uid": {
"name": "uid",
"type": "uuid",
"primaryKey": false,
"notNull": false
},
"parents": {
"name": "parents",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'[]'::jsonb"
},
"data": {
"name": "data",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'{}'::jsonb"
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"summary": {
"name": "summary",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"tags": {
"name": "tags",
"type": "jsonb",
"primaryKey": false,
"notNull": true,
"default": "'[]'::jsonb"
},
"link": {
"name": "link",
"type": "text",
"primaryKey": false,
"notNull": false,
"default": "''"
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"deletedAt": {
"name": "deletedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
}
},
"enums": {},
"schemas": {},
"sequences": {},
"roles": {},
"policies": {},
"views": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -8,6 +8,13 @@
"when": 1766803308366,
"tag": "0000_groovy_red_skull",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1767070768620,
"tag": "0001_solid_nocturne",
"breakpoints": true
}
]
}

View File

@@ -68,13 +68,13 @@ export const cfRouterCode = pgTable("cf_router_code", {
key: varchar({ length: 255 }).notNull(),
active: boolean().default(false),
project: varchar({ length: 255 }).default('default'),
code: text().default('),
code: text().default(''),
type: enumCfRouterCodeType().default('route'),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
middleware: varchar({ length: 255 }).array().default(["RRAY[]::character varying[])::character varying(25"]),
next: varchar({ length: 255 }).default('),
exec: text().default('),
next: varchar({ length: 255 }).default(''),
exec: text().default(''),
data: json().default({}),
validator: json().default({}),
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
@@ -107,7 +107,7 @@ export const cfUserSecrets = pgTable("cf_user_secrets", {
status: varchar({ length: 255 }).default('active'),
title: text(),
expiredTime: timestamp({ withTimezone: true, mode: 'string' }),
token: varchar({ length: 255 }).default(').notNull(),
token: varchar({ length: 255 }).default('').notNull(),
userId: uuid(),
data: jsonb().default({}),
orgId: uuid(),
@@ -133,7 +133,7 @@ export const chatPrompts = pgTable("chat_prompts", {
title: varchar({ length: 255 }).notNull(),
description: text(),
data: json(),
key: varchar({ length: 255 }).default(').notNull(),
key: varchar({ length: 255 }).default('').notNull(),
uid: varchar({ length: 255 }),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
@@ -148,7 +148,7 @@ export const chatSessions = pgTable("chat_sessions", {
uid: varchar({ length: 255 }),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
title: varchar({ length: 255 }).default('),
title: varchar({ length: 255 }).default(''),
key: varchar({ length: 255 }),
});
@@ -167,10 +167,10 @@ export const fileSync = pgTable("file_sync", {
export const kvAiChatHistory = pgTable("kv_ai_chat_history", {
id: uuid().primaryKey().notNull(),
username: varchar({ length: 255 }).default(').notNull(),
model: varchar({ length: 255 }).default(').notNull(),
group: varchar({ length: 255 }).default(').notNull(),
title: varchar({ length: 255 }).default(').notNull(),
username: varchar({ length: 255 }).default('').notNull(),
model: varchar({ length: 255 }).default('').notNull(),
group: varchar({ length: 255 }).default('').notNull(),
title: varchar({ length: 255 }).default('').notNull(),
messages: jsonb().default([]).notNull(),
promptTokens: integer("prompt_tokens").default(0),
totalTokens: integer("total_tokens").default(0),
@@ -186,14 +186,14 @@ export const kvAiChatHistory = pgTable("kv_ai_chat_history", {
export const kvApp = pgTable("kv_app", {
id: uuid().primaryKey().notNull(),
data: jsonb().default({}),
version: varchar({ length: 255 }).default('),
version: varchar({ length: 255 }).default(''),
key: varchar({ length: 255 }),
uid: uuid(),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
title: varchar({ length: 255 }).default('),
description: varchar({ length: 255 }).default('),
title: varchar({ length: 255 }).default(''),
description: varchar({ length: 255 }).default(''),
user: varchar({ length: 255 }),
status: varchar({ length: 255 }).default('running'),
pid: uuid(),
@@ -220,7 +220,7 @@ export const kvAppDomain = pgTable("kv_app_domain", {
export const kvAppList = pgTable("kv_app_list", {
id: uuid().primaryKey().notNull(),
data: json().default({}),
version: varchar({ length: 255 }).default('),
version: varchar({ length: 255 }).default(''),
uid: uuid(),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
@@ -231,24 +231,24 @@ export const kvAppList = pgTable("kv_app_list", {
export const kvConfig = pgTable("kv_config", {
id: uuid().primaryKey().notNull(),
title: text().default('),
key: text().default('),
description: text().default('),
title: text().default(''),
key: text().default(''),
description: text().default(''),
tags: jsonb().default([]),
data: jsonb().default({}),
uid: uuid(),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
hash: text().default('),
hash: text().default(''),
});
export const kvContainer = pgTable("kv_container", {
id: uuid().primaryKey().notNull(),
title: text().default('),
description: text().default('),
title: text().default(''),
description: text().default(''),
type: varchar({ length: 255 }).default('render-js'),
code: text().default('),
code: text().default(''),
data: json().default({}),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
@@ -256,13 +256,13 @@ export const kvContainer = pgTable("kv_container", {
publish: json().default({}),
tags: json().default([]),
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
hash: text().default('),
hash: text().default(''),
});
export const kvGithub = pgTable("kv_github", {
id: uuid().primaryKey().notNull(),
title: varchar({ length: 255 }).default('),
githubToken: varchar({ length: 255 }).default('),
title: varchar({ length: 255 }).default(''),
githubToken: varchar({ length: 255 }).default(''),
uid: uuid(),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
@@ -271,8 +271,8 @@ export const kvGithub = pgTable("kv_github", {
export const kvPackages = pgTable("kv_packages", {
id: uuid().primaryKey().notNull(),
title: text().default('),
description: text().default('),
title: text().default(''),
description: text().default(''),
tags: jsonb().default([]),
data: jsonb().default({}),
publish: jsonb().default({}),
@@ -285,9 +285,9 @@ export const kvPackages = pgTable("kv_packages", {
export const kvPage = pgTable("kv_page", {
id: uuid().primaryKey().notNull(),
title: varchar({ length: 255 }).default('),
description: text().default('),
type: varchar({ length: 255 }).default('),
title: varchar({ length: 255 }).default(''),
description: text().default(''),
type: varchar({ length: 255 }).default(''),
data: json().default({}),
uid: uuid(),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
@@ -298,10 +298,10 @@ export const kvPage = pgTable("kv_page", {
export const kvResource = pgTable("kv_resource", {
id: uuid().primaryKey().notNull(),
name: varchar({ length: 255 }).default('),
description: text().default('),
source: varchar({ length: 255 }).default('),
sourceId: varchar({ length: 255 }).default('),
name: varchar({ length: 255 }).default(''),
description: text().default(''),
source: varchar({ length: 255 }).default(''),
sourceId: varchar({ length: 255 }).default(''),
version: varchar({ length: 255 }).default('0.0.0'),
data: json().default({}),
uid: uuid(),
@@ -321,20 +321,20 @@ export const kvVip = pgTable("kv_vip", {
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
title: text().default(').notNull(),
description: text().default(').notNull(),
title: text().default('').notNull(),
description: text().default('').notNull(),
});
export const microAppsUpload = pgTable("micro_apps_upload", {
id: uuid().primaryKey().notNull(),
title: varchar({ length: 255 }).default('),
description: varchar({ length: 255 }).default('),
title: varchar({ length: 255 }).default(''),
description: varchar({ length: 255 }).default(''),
tags: jsonb().default([]),
type: varchar({ length: 255 }).default('),
source: varchar({ length: 255 }).default('),
type: varchar({ length: 255 }).default(''),
source: varchar({ length: 255 }).default(''),
data: jsonb().default({}),
share: boolean().default(false),
uname: varchar({ length: 255 }).default('),
uname: varchar({ length: 255 }).default(''),
uid: uuid(),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
@@ -342,54 +342,41 @@ export const microAppsUpload = pgTable("micro_apps_upload", {
export const microMark = pgTable("micro_mark", {
id: uuid().primaryKey().notNull(),
title: text().default('),
description: text().default('),
title: text().default(''),
description: text().default(''),
tags: jsonb().default([]),
data: jsonb().default({}),
uname: varchar({ length: 255 }).default('),
uname: varchar({ length: 255 }).default(''),
uid: uuid(),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
cover: text().default('),
thumbnail: text().default('),
link: text().default('),
summary: text().default('),
cover: text().default(''),
thumbnail: text().default(''),
link: text().default(''),
summary: text().default(''),
markType: text().default('md'),
config: jsonb().default({}),
puid: uuid(),
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
version: integer().default(1),
fileList: jsonb().default([]),
key: text().default('),
key: text().default(''),
});
export const prompts = pgTable("prompts", {
id: uuid().primaryKey().notNull(),
title: varchar({ length: 255 }).notNull(),
description: text(),
presetData: json(),
key: varchar({ length: 255 }).notNull(),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
}, (table) => [
unique("prompts_key_key").on(table.key),
]);
export const workShareMark = pgTable("work_share_mark", {
id: uuid().primaryKey().notNull(),
title: text().default('),
key: text().default('),
title: text().default(''),
key: text().default(''),
markType: text().default('md'),
description: text().default('),
cover: text().default('),
link: text().default('),
description: text().default(''),
cover: text().default(''),
link: text().default(''),
tags: jsonb().default([]),
summary: text().default('),
summary: text().default(''),
config: jsonb().default({}),
data: jsonb().default({}),
fileList: jsonb().default([]),
uname: varchar({ length: 255 }).default('),
uname: varchar({ length: 255 }).default(''),
version: integer().default(1),
markedAt: timestamp({ withTimezone: true, mode: 'string' }),
uid: uuid(),
@@ -398,3 +385,21 @@ export const workShareMark = pgTable("work_share_mark", {
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
});
export const prompts = pgTable('cf_prompts', {
id: uuid('id').primaryKey().defaultRandom(),
uid: uuid('uid'),
parents: jsonb('parents').notNull().default([]),
data: jsonb('data').notNull().default({}),
title: text('title').default(''),
description: text('description').default(''),
summary: text('summary').default(''),
tags: jsonb('tags').notNull().default([]),
link: text('link').default(''),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow(),
deletedAt: timestamp('deletedAt'),
});

View File

@@ -1,14 +1,3 @@
import { pgTable, serial, text, varchar, uuid, boolean, jsonb, timestamp } from "drizzle-orm/pg-core";
import { InferSelectModel, InferInsertModel } from "drizzle-orm";
export const aiUsages = pgTable('cf_ai_usage_cache', {
id: uuid('id').primaryKey().defaultRandom(),
owner: uuid('owner'),
data: jsonb('data').notNull().default({}),
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt').notNull().defaultNow(),
deletedAt: timestamp('deletedAt'),
});
// 类型推断
export type AiUsage = InferSelectModel<typeof aiUsages>;
import { pgTable, uuid, jsonb, timestamp, text } from "drizzle-orm/pg-core";
import { InferSelectModel, InferInsertModel, desc } from "drizzle-orm";
export * from './drizzle/schema.ts';