Skip to content

Commit

Permalink
reality mergish huh?
Browse files Browse the repository at this point in the history
  • Loading branch information
hUwUtao committed Aug 15, 2023
1 parent 4585e70 commit fe7e1f5
Show file tree
Hide file tree
Showing 20 changed files with 519 additions and 205 deletions.
45 changes: 20 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
FROM debian:stable-slim as base
FROM debian:11.6-slim as builder

RUN useradd -md /app bao
WORKDIR /app
ENV PATH "/app/.bun/bin:$PATH"
RUN apt-get update -y
RUN apt-get install -y openssl

FROM base as basenv
# please don't haunt me
RUN apt-get install curl unzip nodejs -y
RUN apt update
RUN apt install curl unzip -y

FROM basenv as init
RUN curl -fsSL https://bun.sh/install | bash
RUN curl https://bun.sh/install | bash

FROM basenv as benv
COPY package.json .
COPY bun.lockb .

COPY --from=init --chown=bao /root /app
USER bao
RUN /root/.bun/bin/bun install --production

FROM benv as build
# ? -------------------------
FROM gcr.io/distroless/base

COPY --chown=bao . .
RUN bun install \
&& bun run init \
&& bun run build
WORKDIR /app

COPY --from=builder /root/.bun/bin/bun bun
COPY --from=builder /app/node_modules node_modules

COPY src src
# COPY public public
# COPY tsconfig.json .

FROM base as runtime
ENV ENV production
CMD ["./bun", "src/index.ts"]

COPY --from=init --chown=bao /root /app
COPY --from=build --chown=bao /app/package.json /app/dist /app/node_modules/.prisma/client/*.node ./
COPY --chown=bao prisma ./
USER bao
# RUN bun install -p
CMD ["/app/.bun/bin/bun", "index.js"]
EXPOSE 3000
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion client.ts

This file was deleted.

142 changes: 0 additions & 142 deletions main.ts

This file was deleted.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"typescript": "^5.1.6"
},
"dependencies": {
"@elysiajs/bearer": "^0.6.0",
"@elysiajs/cors": "^0.6.0",
"@elysiajs/eden": "^0.6.0",
"@elysiajs/swagger": "^0.6.0",
"elysia": "0.6.2",
"mysql2": "^3.6.0",
"serdebin": "1.2.3"
},
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ export module protocol {

export function de(de: string) {
return protocol.deserialize(new Deserialization(en8(atob(de.split(".")[0]))))
}
}

export * from "@prisma/client"
134 changes: 134 additions & 0 deletions src/api/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { Elysia, t } from "elysia";
import { saltcheck } from "../../utils/cipher";
import { protocol } from "../../shared";
import { tokener } from "../../trusted";
import { prisma } from "../func/db";

const mgex = /^[a-zA-Z0-9_]{2,16}$/;

export default (app: Elysia) =>
app.group("/auth", (app) =>
app.post(
"/",
async ({ body: { username, password: ipassword }, set }) => {
const fetch = await prisma.credential.findUnique({
where: {
username: username,
},
select: {
password: true,
realname: true,
pf: {
select: {
id: true,
},
},
},
});
if (fetch) {
const { password, realname } = fetch;
if (saltcheck(ipassword, password)) {
const f = protocol.serialize(username, fetch.pf?.id);
return {
success: true,
msg: "Authenticated as " + realname,
token: tokener.sign(f),
};
}
// return new ErrorResponse(
else {
set.status = 400;
return "Fail password";
}
// 401
// );
} else {
set.status = 404;
return "User not found";
}
},
{
body: t.Object({
username: t.String({
default: "Console",
// format: "regex",
// pattern: "/^[a-zA-Z0-9_]{2,16}$/",
minLength: 2,
maxLength: 16,
}),
password: t.String({
default: "f".repeat(64),
description:
"The password, hashed with SHA256 Digest once, encode in Hex and lowercased.",
// format: "regex",
// pattern: "/^[0-9a-f]*$/",
minLength: 64,
maxLength: 64,
}),
}),
response: {
200: t.Object({
success: t.Boolean({
default: true,
}),
msg: t.String(),
token: t.String(),
}),
401: t.String({
default: "Fail password",
description: "At this point if you tried to bruteforce your own brain to find the correct password, well the server would exaust!"
}),
404: t.String({
default: "User not found",
description: "At this point you realize your keyboard sucks."
})
},
}
)
);

// async ({ body: { username, password: ipassword } }) => {
// if (!mgex.test(username))
// return new ErrorResponse(
// {
// success: false,
// msg: "Wrong username format?",
// },
// 400
// );
// const fetch = await prisma.credential.findUnique({
// where: {
// username: username,
// },
// select: {
// password: true,
// realname: true,
// pf: {
// select: {
// id: true,
// },
// },
// },
// });
// if (fetch) {
// const { password, realname } = fetch;
// if (saltcheck(ipassword, password)) {
// const f = protocol.serialize(username, fetch.pf?.id);
// // return {
// // success: true,
// // msg: "Authenticated as " + realname,
// // token: tokener.sign(f),
// // };
// }
// // else
// // return new ErrorResponse(
// // { success: false, msg: "Password check failed!", code: "fpwd" },
// // 401
// // );
// } else {
// return new ErrorResponse(
// { success: false, msg: "User not found?", code: "nusr" },
// 404
// );
// }
// };
Loading

0 comments on commit fe7e1f5

Please sign in to comment.