Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ async function run(options: RunOptions = {}) {
},
});
// Add async preHandler hook for authentication
server.addHook("preHandler", async (req, reply) => {
return new Promise((resolve, reject) => {
server.addHook("preHandler", async (req: any, reply: any) => {
return new Promise<void>((resolve, reject) => {
const done = (err?: Error) => {
if (err) reject(err);
else resolve();
Expand All @@ -104,7 +104,7 @@ async function run(options: RunOptions = {}) {
apiKeyAuth(config)(req, reply, done).catch(reject);
});
});
server.addHook("preHandler", async (req, reply) => {
server.addHook("preHandler", async (req: any, reply: any) => {
if(req.url.startsWith("/v1/messages")) {
router(req, reply, config)
}
Expand Down
8 changes: 4 additions & 4 deletions src/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const apiKeyAuth =
}

// If API key is set, check authentication
const authKey: string =
req.headers.authorization || req.headers["x-api-key"];
const authKey: string | undefined =
(req.headers.authorization || req.headers["x-api-key"]) as string | undefined;

if (!authKey) {
(req as any).accessLevel = "restricted";
Expand Down Expand Up @@ -89,8 +89,8 @@ export const apiKeyAuth =
return done();
}

const authKey: string =
req.headers.authorization || req.headers["x-api-key"];
const authKey: string | undefined =
(req.headers.authorization || req.headers["x-api-key"]) as string | undefined;
if (!authKey) {
reply.status(401).send("APIKEY is missing");
return;
Expand Down
10 changes: 5 additions & 5 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const createServer = (config: any): Server => {
const server = new Server(config);

// Add endpoint to read config.json with access control
server.app.get("/api/config", async (req, reply) => {
server.app.get("/api/config", async (req: any, reply: any) => {
// Get access level from request (set by auth middleware)
const accessLevel = (req as any).accessLevel || "restricted";

Expand All @@ -36,7 +36,7 @@ export const createServer = (config: any): Server => {
});

// Add endpoint to save config.json with access control
server.app.post("/api/config", async (req, reply) => {
server.app.post("/api/config", async (req: any, reply: any) => {
// Only allow full access users to save config
const accessLevel = (req as any).accessLevel || "restricted";
if (accessLevel !== "full") {
Expand All @@ -58,7 +58,7 @@ export const createServer = (config: any): Server => {
});

// Add endpoint for testing full access without modifying config
server.app.post("/api/config/test", async (req, reply) => {
server.app.post("/api/config/test", async (req: any, reply: any) => {
// Only allow full access users to test config access
const accessLevel = (req as any).accessLevel || "restricted";
if (accessLevel !== "full") {
Expand All @@ -71,7 +71,7 @@ export const createServer = (config: any): Server => {
});

// Add endpoint to restart the service with access control
server.app.post("/api/restart", async (req, reply) => {
server.app.post("/api/restart", async (req: any, reply: any) => {
// Only allow full access users to restart service
const accessLevel = (req as any).accessLevel || "restricted";
if (accessLevel !== "full") {
Expand All @@ -96,7 +96,7 @@ export const createServer = (config: any): Server => {
});

// Redirect /ui to /ui/ for proper static file serving
server.app.get("/ui", async (_, reply) => {
server.app.get("/ui", async (_: any, reply: any) => {
return reply.redirect("/ui/");
});

Expand Down
8 changes: 8 additions & 0 deletions src/types/musistudio__llms.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module '@musistudio/llms' {
export default class Server {
app: any;
constructor(config: any);
start(): void;
addHook(name: string, handler: any): void;
}
}