feat: CalDAV-Integration für Admin-Kalender
- Neue CalDAV-Route mit PROPFIND und GET-Endpoints - ICS-Format-Generator für Buchungsdaten - Token-basierte Authentifizierung für CalDAV-Zugriff - Admin-Interface mit CalDAV-Link-Generator - Schritt-für-Schritt-Anleitung für Kalender-Apps - 24h-Token-Ablaufzeit für Sicherheit - Unterstützung für Outlook, Google Calendar, Apple Calendar, Thunderbird Fixes: Admin kann jetzt Terminkalender in externen Apps abonnieren
This commit is contained in:
79
server-dist/rpc/demo/ai.js
Normal file
79
server-dist/rpc/demo/ai.js
Normal file
@@ -0,0 +1,79 @@
|
||||
import OpenAI from "openai";
|
||||
import { os } from "@orpc/server";
|
||||
import { z } from "zod";
|
||||
import { zodResponseFormat } from "../../lib/openai";
|
||||
if (!process.env.OPENAI_BASE_URL) {
|
||||
throw new Error("OPENAI_BASE_URL is not set");
|
||||
}
|
||||
if (!process.env.OPENAI_API_KEY) {
|
||||
throw new Error("OPENAI_API_KEY is not set");
|
||||
}
|
||||
const openai = new OpenAI({
|
||||
baseURL: process.env.OPENAI_BASE_URL,
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
});
|
||||
if (!process.env.OPENAI_DEFAULT_MODEL) {
|
||||
throw new Error("OPENAI_DEFAULT_MODEL is not set");
|
||||
}
|
||||
const DEFAULT_MODEL = process.env.OPENAI_DEFAULT_MODEL;
|
||||
const ChatCompletionInputSchema = z.object({
|
||||
message: z.string(),
|
||||
systemPrompt: z.string().optional(),
|
||||
});
|
||||
const GeneratePersonInputSchema = z.object({
|
||||
prompt: z.string(),
|
||||
});
|
||||
const complete = os
|
||||
.input(ChatCompletionInputSchema)
|
||||
.handler(async ({ input }) => {
|
||||
const { message, systemPrompt } = input;
|
||||
const completion = await openai.chat.completions.create({
|
||||
model: DEFAULT_MODEL,
|
||||
messages: [
|
||||
...(systemPrompt
|
||||
? [{ role: "system", content: systemPrompt }]
|
||||
: []),
|
||||
{ role: "user", content: message },
|
||||
],
|
||||
});
|
||||
return {
|
||||
response: completion.choices[0]?.message?.content || "",
|
||||
};
|
||||
});
|
||||
// Object generation schemas only support nullability, not optionality.
|
||||
// Use .nullable() instead of .optional() for fields that may not have values.
|
||||
const DemoSchema = z.object({
|
||||
name: z.string().describe("The name of the person"),
|
||||
age: z.number().describe("The age of the person"),
|
||||
occupation: z.string().describe("The occupation of the person"),
|
||||
bio: z.string().describe("The bio of the person"),
|
||||
nickname: z
|
||||
.string()
|
||||
.nullable()
|
||||
.describe("The person's nickname, if they have one"),
|
||||
});
|
||||
const generate = os
|
||||
.input(GeneratePersonInputSchema)
|
||||
.handler(async ({ input }) => {
|
||||
const completion = await openai.chat.completions.parse({
|
||||
model: DEFAULT_MODEL,
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: `Generate a person based on this prompt: ${input.prompt}`,
|
||||
},
|
||||
],
|
||||
response_format: zodResponseFormat(DemoSchema, "person"),
|
||||
});
|
||||
const person = completion.choices[0]?.message?.parsed;
|
||||
if (!person) {
|
||||
throw new Error("No parsed data received from OpenAI");
|
||||
}
|
||||
return {
|
||||
person,
|
||||
};
|
||||
});
|
||||
export const router = {
|
||||
complete,
|
||||
generate,
|
||||
};
|
4
server-dist/rpc/demo/index.js
Normal file
4
server-dist/rpc/demo/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import { router as storageRouter } from "./storage.js";
|
||||
export const demo = {
|
||||
storage: storageRouter,
|
||||
};
|
42
server-dist/rpc/demo/storage.js
Normal file
42
server-dist/rpc/demo/storage.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { call, os } from "@orpc/server";
|
||||
import { z } from "zod";
|
||||
import { randomUUID } from "crypto";
|
||||
import { createKV } from "../../lib/create-kv.js";
|
||||
const DemoSchema = z.object({
|
||||
id: z.string(),
|
||||
value: z.string(),
|
||||
});
|
||||
// createKV provides simple key-value storage with publisher/subscriber support
|
||||
// perfect for live queries and small amounts of data
|
||||
const kv = createKV("demo");
|
||||
// Handler with input validation using .input() and schema
|
||||
const create = os
|
||||
.input(DemoSchema.omit({ id: true }))
|
||||
.handler(async ({ input }) => {
|
||||
const id = randomUUID();
|
||||
const item = { id, value: input.value };
|
||||
await kv.setItem(id, item);
|
||||
});
|
||||
const remove = os.input(z.string()).handler(async ({ input }) => {
|
||||
await kv.removeItem(input);
|
||||
});
|
||||
// Handler without input - returns all items
|
||||
const list = os.handler(async () => {
|
||||
return kv.getAllItems();
|
||||
});
|
||||
// Live data stream using generator function
|
||||
// Yields initial data, then subscribes to changes for real-time updates
|
||||
const live = {
|
||||
list: os.handler(async function* ({ signal }) {
|
||||
yield call(list, {}, { signal });
|
||||
for await (const _ of kv.subscribe()) {
|
||||
yield call(list, {}, { signal });
|
||||
}
|
||||
}),
|
||||
};
|
||||
export const router = {
|
||||
create,
|
||||
remove,
|
||||
list,
|
||||
live,
|
||||
};
|
Reference in New Issue
Block a user