Structured libs
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { version } from "@/../package.json";
|
||||
import testAuth from "../auth";
|
||||
import testAuth from "../../../lib/server/auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { read } from "@/app/api/file";
|
||||
import { NodeJsonTemplate } from "../types";
|
||||
import { read } from "@/lib/server/file";
|
||||
import { NodeJsonTemplate } from "../../../lib/server/types";
|
||||
import osName from "os-name";
|
||||
|
||||
export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
@@ -12,7 +12,7 @@ export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import testAuth from "../auth";
|
||||
import testAuth from "../../../lib/server/auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { getDocker, removeContainer } from "@/core/docker";
|
||||
import { Docker } from "@/lib/types";
|
||||
@@ -10,7 +10,7 @@ export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,14 +30,14 @@ export async function DELETE(req: NextRequest): Promise<NextResponse> {
|
||||
if (!id) {
|
||||
return NextResponse.json(
|
||||
{ message: "Invalid containerId param" },
|
||||
{ status: StatusCodes.BAD_REQUEST }
|
||||
{ status: StatusCodes.BAD_REQUEST },
|
||||
);
|
||||
}
|
||||
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import testAuth from "../../auth";
|
||||
import testAuth from "../../../../lib/server/auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { startContainer, stopContainer } from "@/core/docker";
|
||||
|
||||
@@ -10,14 +10,14 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
if (!id) {
|
||||
return NextResponse.json(
|
||||
{ message: "Invalid containerId param" },
|
||||
{ status: StatusCodes.BAD_REQUEST }
|
||||
{ status: StatusCodes.BAD_REQUEST },
|
||||
);
|
||||
}
|
||||
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ export async function DELETE(req: NextRequest): Promise<NextResponse> {
|
||||
if (!id) {
|
||||
return NextResponse.json(
|
||||
{ message: "Invalid containerId param" },
|
||||
{ status: StatusCodes.BAD_REQUEST }
|
||||
{ status: StatusCodes.BAD_REQUEST },
|
||||
);
|
||||
}
|
||||
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import testAuth from "../../auth";
|
||||
import testAuth from "../../../../lib/server/auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { getContainerStats } from "@/core/docker";
|
||||
|
||||
@@ -10,14 +10,14 @@ export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
if (!id) {
|
||||
return NextResponse.json(
|
||||
{ message: "Invalid containerId param" },
|
||||
{ status: StatusCodes.BAD_REQUEST }
|
||||
{ status: StatusCodes.BAD_REQUEST },
|
||||
);
|
||||
}
|
||||
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import testAuth from "../auth";
|
||||
import testAuth from "../../../lib/server/auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { deployApp, toggleDeployment } from "@/core/deployment";
|
||||
import { Application, Port } from "@/lib/types";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import testAuth from "../auth";
|
||||
import testAuth from "../../../lib/server/auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { getDeployments } from "@/core/deployment";
|
||||
|
||||
@@ -10,14 +10,14 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
if (!apps)
|
||||
return NextResponse.json(
|
||||
{ message: "Body should be Application[]" },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
|
||||
const deployments = await getDeployments(apps);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import testAuth from "../auth";
|
||||
import testAuth from "../../../lib/server/auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import { getAllContainerLogs } from "@/core/docker";
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import testAuth from "../auth";
|
||||
import testAuth from "../../../lib/server/auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import si from "systeminformation";
|
||||
import { average } from "@/lib/format";
|
||||
@@ -93,7 +93,7 @@ export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import testAuth from "../auth";
|
||||
import testAuth from "../../../lib/server/auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
import si from "systeminformation";
|
||||
import { NodeLiveData } from "@/lib/types";
|
||||
@@ -10,7 +10,7 @@ export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
{ status: StatusCodes.UNAUTHORIZED },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"use server";
|
||||
import { read, write } from "@/app/api/file";
|
||||
import testAuth from "@/lib/server/auth";
|
||||
import { read, write } from "@/lib/server/file";
|
||||
import { NodeJsonTemplate } from "@/lib/server/types";
|
||||
import axios from "axios";
|
||||
import { createHash } from "crypto";
|
||||
import { cookies } from "next/headers";
|
||||
@@ -20,7 +22,7 @@ export async function getSession(): Promise<
|
||||
const tokens: Record<string, string> = await read(
|
||||
() => ({}),
|
||||
"data",
|
||||
"sessions.json"
|
||||
"sessions.json",
|
||||
);
|
||||
|
||||
const tokenHash = createHash("sha256").update(accessToken).digest("hex");
|
||||
@@ -36,7 +38,7 @@ export async function getSession(): Promise<
|
||||
|
||||
// Test the token
|
||||
const users = Object.keys(
|
||||
await read<Users>(() => ({}), "data", "users.json")
|
||||
await read<Users>(() => ({}), "data", "users.json"),
|
||||
);
|
||||
|
||||
if (!users.includes(String(userId))) {
|
||||
@@ -44,8 +46,10 @@ export async function getSession(): Promise<
|
||||
await write(
|
||||
{ [userId]: { roles: ["admin"] } } as Users, // First user is always an admin
|
||||
"data",
|
||||
"users.json"
|
||||
"users.json",
|
||||
);
|
||||
const { key } = await read(NodeJsonTemplate, "data", "node.json");
|
||||
console.log(`Node key: ${key}\ncwd: ${process.cwd()}`);
|
||||
} else {
|
||||
throw new Error("Invalid user");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { verifySession } from "../../core/auth/session";
|
||||
import { Env, EnvVariable, Application } from "@/lib/types";
|
||||
import { read, write } from "@/app/api/file";
|
||||
import { read, write } from "@/lib/server/file";
|
||||
import { randomUUID } from "crypto";
|
||||
|
||||
export async function getApps(): Promise<Application[]> {
|
||||
@@ -19,7 +19,7 @@ export async function getApp(appId: string): Promise<Application | undefined> {
|
||||
}
|
||||
|
||||
return (await read<Application[]>(() => [], "data", "apps.json")).find(
|
||||
(app) => app.id === appId
|
||||
(app) => app.id === appId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ export async function getEnv(): Promise<Record<string, Env>> {
|
||||
|
||||
export async function setEnv(
|
||||
appId: string,
|
||||
variables: Record<string, EnvVariable>
|
||||
variables: Record<string, EnvVariable>,
|
||||
) {
|
||||
if (await verifySession()) {
|
||||
throw new Error("Unauthorized");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use server";
|
||||
|
||||
import { read, write } from "@/app/api/file";
|
||||
import { read, write } from "@/lib/server/file";
|
||||
import { Node, NodeLiveData } from "@/lib/types";
|
||||
import axios from "axios";
|
||||
import { verifySession } from "../../core/auth/session";
|
||||
@@ -30,7 +30,7 @@ export async function getLiveNodes(): Promise<(NodeLiveData & Node)[]> {
|
||||
headers: { Authorization: `ApiKey ${node.key}` },
|
||||
})
|
||||
).data.liveData,
|
||||
}))
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { read } from "@/app/api/file";
|
||||
import { NodeJsonTemplate } from "@/app/api/types";
|
||||
import { read } from "@/lib/server/file";
|
||||
import { NodeJsonTemplate } from "@/lib/server/types";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export default async function testAuth(
|
||||
req: NextRequest
|
||||
req: NextRequest,
|
||||
): Promise<null | string> {
|
||||
const auth = req.headers
|
||||
.get("Authorization")
|
||||
Reference in New Issue
Block a user