Skip to content
Merged
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
8 changes: 7 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"extends": ["@bravo68web"]
"extends": ["@bravo68web"],
"rules": {
"sonarjs/cognitive-complexity": "off",
"unicorn/no-array-reduce": "off",
"unicorn/filename-case": "off",
"@typescript-eslint/no-empty-interface": "off"
}
}
28 changes: 28 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
api:
- packages/api/**/*

cli:
- apps/cli/**/*

# discord:
# - apps/bot/**/*

web:
- apps/web/**/*

github-actions:
- .github/workflows/*

github-meta:
- .github/**/*

dependencies:
- package.json
- yarn.lock
- packages/*/package.json
- apps/*/package.json

readme:
- README.md
- apps/*/README.md
- packages/*/README.md
14 changes: 14 additions & 0 deletions .github/workflows/auto-label.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Labeler
on: [pull_request_target]

jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write

steps:
- uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
34 changes: 34 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: CI

on:
push:
pull_request:
types: [opened, synchronize]

jobs:
build:
name: Build and Test
timeout-minutes: 15
runs-on: ubuntu-latest
# To use Remote Caching, uncomment the next lines and follow the steps below.
# env:
# TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
# TURBO_TEAM: ${{ vars.TURBO_TEAM }}

steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'yarn'

- name: Install dependencies
run: yarn

- name: Build
run: yarn build
30 changes: 30 additions & 0 deletions .github/workflows/todo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Create issues from TODOs

on:
workflow_dispatch:
inputs:
importAll:
default: 'false'
required: false
type: boolean
description: Enable, if you want to import all TODOs. Runs on checked out branch! Only use if you're sure what you are doing.
push:

permissions:
issues: write
repository-projects: read
contents: read

jobs:
todos:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Run Issue Bot
uses: derjuulsn/todo-issue@main
with:
excludePattern: '^(node_modules/)'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
"@bravo68web/eslint-config": "^1.2.2",
"@bravo68web/prettier-config": "^1.2.2",
"@bravo68web/tsconfig": "^1.2.2",
"nodemon": "^3.0.2",
"prettier": "^3.1.0",
"turbo": "latest"
},
"packageManager": "pnpm@8.9.0",
"engines": {
"node": ">=18"
}
},
"workspaces": [
"packages/*",
"apps/*"
]
}
11 changes: 11 additions & 0 deletions packages/api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
HASURA_GRAPHQL_ENDPOINT=
HASURA_GRAPHQL_ADMIN_SECRET=
MAIL_HOST=
MAIL_PORT=
MAIL_USER=
MAIL_PASS=
MAIL_LOGGER=
MAIL_FROM_EMAIL=
MAIL_FROM_NAME=
PORT=
NODE_ENV=
24 changes: 24 additions & 0 deletions packages/api/config/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { z } from "zod";
declare global {
namespace NodeJS {
interface ProcessEnv extends z.infer<typeof ZodEnvironmentVariables> {}
}
}

const ZodEnvironmentVariables = z.object({
PORT: z.string(),
NODE_ENV: z.string(),
HASURA_GRAPHQL_ADMIN_SECRET: z.string(),
HASURA_GRAPHQL_ENDPOINT: z.string(),
MAIL_HOST: z.string(),
MAIL_PORT: z.string(),
MAIL_USER: z.string(),
MAIL_PASS: z.string(),
MAIL_LOGGER: z.string(),
MAIL_FROM_EMAIL: z.string(),
MAIL_FROM_NAME: z.string(),
});

ZodEnvironmentVariables.parse(process.env);

console.log("✅ Environment variables verified!");
72 changes: 72 additions & 0 deletions packages/api/controllers/challenges.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Context } from "hono";
import { ChallengeService } from "../services/challenges.service";

export class ChallengeController extends ChallengeService {
public createMachine = async (ctx: Context) => {
try {
const reqBody = await ctx.req.json();
const data = await this.createMachineS(reqBody);
return ctx.json(data);
}
catch (error: any) {
return ctx.json({
error: error.message
});
}
};

public getMachineById = async (ctx: Context) => {
try {
const machineId = ctx.req.param("machineId");
const data = await this.getMachineByIdS(machineId);
return ctx.json(data);
}
catch (error: any) {
return ctx.json({
error: error.message
});
}
};

public getMachines = async (ctx: Context) => {
try {
const data = await this.getMachinesS();
return ctx.json(data);
}
catch (error: any) {
return ctx.json({
error: error.message
});
}
}

public sumbitFlag = async (ctx: Context) => {
try {
const reqBody = await ctx.req.json();
const challengeId = ctx.req.param("challengeId");
const user = ctx.get("user");
const userTeamID = ctx.get("team_id");
if(!userTeamID) {
throw new Error("User not in team");
}
const data = await this.submitFlagS({
submited_flag: reqBody.flag,
user_id: user.id,
team_id: userTeamID,
challenge_id: challengeId
});
return ctx.json(data);
}
catch (error: any) {
if(error.response) {
return ctx.json({
error: error.response.errors[0].message
});
}
else
return ctx.json({
error: error.message
});
}
}
}
91 changes: 91 additions & 0 deletions packages/api/controllers/teams.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Context } from "hono";
import { TeamService } from "../services/teams.service";

export class TeamController extends TeamService {
public createTeam = async (ctx: Context) => {
try {
const reqBody = await ctx.req.json();
const data = await this.createTeamS(reqBody);
return ctx.json(data);
}
catch (error: any) {
return ctx.json({
error: error.message
});
}
};

public getTeamById = async (ctx: Context) => {
try {
const teamId = ctx.req.param("teamId");
const data = await this.getTeamByIdS(teamId);
return ctx.json(data);
}
catch (error: any) {
return ctx.json({
error: error.message
});
}
};

public joinTeam = async (ctx: Context) => {
try {
const reqBody = await ctx.req.json();
const user = ctx.get("user");
const data = await this.joinTeamS({
join_code: reqBody.join_code,
user_id: user.id
});
return ctx.json(data);
}
catch (error: any) {
return ctx.json({
error: error.message
});
}
}



public getTeams = async (ctx: Context) => {
try {
const data = await this.getTeamsS();
return ctx.json(data);
}
catch (error: any) {
return ctx.json({
error: error.message
});
}
}

public whoami = async (ctx: Context) => {
try {
const userTeamID = await ctx.get("team_id");
const data = await this.whomaiS(userTeamID);
return ctx.json(data);
}
catch (error: any) {
return ctx.json({
error: error.message
});
}
}

public getProgress = async (ctx: Context) => {
try {
const userTeamID = await ctx.get("team_id");
const mechineID = ctx.req.param("machineId");
const data = await this.getTeamMachineProgress(
userTeamID,
mechineID
);
return ctx.json(data);
}
catch (error: any) {
return ctx.json({
error: error.message
});
}
}
}
Loading