migrate from hono

This commit is contained in:
JCEEE
2026-08-17 07:41:26 +01:00
parent e2b99c45b6
commit 5204e7bdbc
56 changed files with 1815 additions and 3357 deletions
+55
View File
@@ -0,0 +1,55 @@
export type ChatActor = {
id: string;
type: 'admin' | 'member';
name: string;
color: string;
};
export async function chatMe(pb: any, famId: string, actor: ChatActor) {
return { famId, actor };
}
export async function send(
pb: any,
famId: string,
actor: ChatActor,
body: { content?: string; clientId?: string }
) {
const content = (body.content || '').trim();
if (!content) throw new Error('content required');
return pb.collection('messages').create({
famId,
authorType: actor.type,
authorId: actor.id,
authorName: actor.name,
authorColor: actor.color,
content,
createdAt: new Date().toISOString(),
clientId: body.clientId ? String(body.clientId).slice(0, 64) : ''
});
}
export async function typing(
pb: any,
famId: string,
actor: ChatActor,
body: { typing?: boolean }
) {
const existing = await pb.collection('chat_typing').getFullList({
filter: `famId = '${famId}' && actorId = '${actor.id}' && actorType = '${actor.type}'`
});
const row = {
famId,
actorId: actor.id,
actorType: actor.type,
authorName: actor.name,
authorColor: actor.color,
typing: !!body.typing
};
if (existing?.length) {
await pb.collection('chat_typing').update(existing[0].id, row);
} else {
await pb.collection('chat_typing').create(row);
}
return { ok: true };
}