Compare commits

..

1 Commits

Author SHA1 Message Date
Olivier 'reivilibre
698a6c7e19 Replace config: use Valibot and allow multiple forges of one type
Signed-off-by: Olivier 'reivilibre <git.contact@librepush.net>
2025-09-30 15:08:22 +01:00
6 changed files with 7 additions and 10 deletions

View File

@ -16,10 +16,7 @@
"enabled": true, "enabled": true,
"includes": ["src/**", "!src/types/openapi.d.ts"], "includes": ["src/**", "!src/types/openapi.d.ts"],
"rules": { "rules": {
"recommended": true, "recommended": true
"style": {
"noNonNullAssertion": "off"
}
} }
}, },
"javascript": { "javascript": {

View File

@ -1,6 +1,6 @@
import * as v from "valibot"; import { ConfigSchema, CONFIG_SCHEMA_KEYS, type Config } from "./schema";
import { CONFIG_SCHEMA_KEYS, type Config, ConfigSchema } from "./schema";
import { transformEnvToConfig } from "./transformer"; import { transformEnvToConfig } from "./transformer";
import * as v from "valibot";
function createConfig(): Config { function createConfig(): Config {
const rawConfig = transformEnvToConfig( const rawConfig = transformEnvToConfig(

View File

@ -26,7 +26,7 @@ export function transformEnvToConfig<Keys extends string[]>(
// descend into the deeper layers // descend into the deeper layers
// (following keyPath) // (following keyPath)
let current: Record<string, unknown> = config; let current: Record<string, unknown> = config;
for (const part of keyPathParts.slice(0, -1)) { for (let part of keyPathParts.slice(0, -1)) {
if (!(part in current)) { if (!(part in current)) {
current[part] = {}; current[part] = {};
} }

View File

@ -18,7 +18,7 @@ authRouter.get("/login/:forgeId", (req: Request, res: Response) => {
} }
const forgeId = parseInt(forgeIdParam, 10); const forgeId = parseInt(forgeIdParam, 10);
if (Number.isNaN(forgeId)) { if (isNaN(forgeId)) {
res.status(400).json({ error: "Invalid forgeId" }); res.status(400).json({ error: "Invalid forgeId" });
return; return;
} }

View File

@ -1,8 +1,8 @@
import express from "express"; import express from "express";
import session from "express-session"; import session from "express-session";
import { createOpenAPIBackend, createOpenAPIMiddleware } from "./api/openapi"; import { createOpenAPIBackend, createOpenAPIMiddleware } from "./api/openapi";
import { config } from "./config";
import { connectDB } from "./config/db"; import { connectDB } from "./config/db";
import { config } from "./config";
import authRouter from "./routes/auth"; import authRouter from "./routes/auth";
import { seedForges } from "./util/seedforges"; import { seedForges } from "./util/seedforges";

View File

@ -1,9 +1,9 @@
import * as arctic from "arctic"; import * as arctic from "arctic";
import type { ForgeInstanceConfig } from "../../config/schema";
import type { Forge } from "../../types/forge"; import type { Forge } from "../../types/forge";
import type { ForgeUser } from "../../types/forgeuser"; import type { ForgeUser } from "../../types/forgeuser";
import type { GiteaRepo } from "../../types/gitearepo"; import type { GiteaRepo } from "../../types/gitearepo";
import type { Repository } from "../../types/openapi"; import type { Repository } from "../../types/openapi";
import { ForgeInstanceConfig } from "../../config/schema";
export class GiteaForge implements Forge { export class GiteaForge implements Forge {
private gitea: arctic.Gitea; private gitea: arctic.Gitea;
private forgeId: number; private forgeId: number;