From 4255d95c686ab0e098076e43c9c1db2248833aa9 Mon Sep 17 00:00:00 2001 From: Mike Johnston Date: Sat, 28 Feb 2026 00:01:41 -0500 Subject: [PATCH] first commit --- .dockerignore | 6 + .env.example | 13 + .gitea/workflows/rebuild-prod.yaml | 89 ++ .gitignore | 4 + Dockerfile | 15 + README.md | 91 ++ package-lock.json | 2001 ++++++++++++++++++++++++++++ package.json | 23 + prod-compose.yml | 23 + public/css/style.css | 517 +++++++ src/app.js | 150 +++ src/config/database.js | 219 +++ src/middleware/auth.js | 37 + src/models/index.js | 246 ++++ src/routes/admin.js | 96 ++ src/routes/auth.js | 82 ++ src/routes/hunts.js | 41 + src/routes/loot.js | 140 ++ src/setup-admin.js | 55 + src/utils/pdf.js | 80 ++ src/views/admin/create-hunt.ejs | 48 + src/views/admin/dashboard.ejs | 29 + src/views/admin/manage-hunt.ejs | 73 + src/views/auth/login.ejs | 31 + src/views/auth/register.ejs | 39 + src/views/error.ejs | 11 + src/views/home.ejs | 52 + src/views/hunt/leaderboard.ejs | 42 + src/views/hunt/list.ejs | 31 + src/views/hunt/profile.ejs | 65 + src/views/leaderboard/global.ejs | 40 + src/views/loot/expired.ejs | 13 + src/views/loot/profile.ejs | 106 ++ src/views/loot/scanned.ejs | 122 ++ src/views/partials/footer.ejs | 5 + src/views/partials/header.ejs | 30 + 36 files changed, 4665 insertions(+) create mode 100644 .dockerignore create mode 100644 .env.example create mode 100644 .gitea/workflows/rebuild-prod.yaml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 prod-compose.yml create mode 100644 public/css/style.css create mode 100644 src/app.js create mode 100644 src/config/database.js create mode 100644 src/middleware/auth.js create mode 100644 src/models/index.js create mode 100644 src/routes/admin.js create mode 100644 src/routes/auth.js create mode 100644 src/routes/hunts.js create mode 100644 src/routes/loot.js create mode 100644 src/setup-admin.js create mode 100644 src/utils/pdf.js create mode 100644 src/views/admin/create-hunt.ejs create mode 100644 src/views/admin/dashboard.ejs create mode 100644 src/views/admin/manage-hunt.ejs create mode 100644 src/views/auth/login.ejs create mode 100644 src/views/auth/register.ejs create mode 100644 src/views/error.ejs create mode 100644 src/views/home.ejs create mode 100644 src/views/hunt/leaderboard.ejs create mode 100644 src/views/hunt/list.ejs create mode 100644 src/views/hunt/profile.ejs create mode 100644 src/views/leaderboard/global.ejs create mode 100644 src/views/loot/expired.ejs create mode 100644 src/views/loot/profile.ejs create mode 100644 src/views/loot/scanned.ejs create mode 100644 src/views/partials/footer.ejs create mode 100644 src/views/partials/header.ejs diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7556c5a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules +data +.git +.gitea +*.md +.env diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..706c246 --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +# Server +PORT=3000 +NODE_ENV=production +BASE_URL=https://loot-hunt.com + +# Session +SESSION_SECRET=change-me-to-a-random-string + +# Database (SQLite file path) +DB_PATH=./data/loot-hunt.db + +# Uploads directory +UPLOADS_DIR=./data/uploads diff --git a/.gitea/workflows/rebuild-prod.yaml b/.gitea/workflows/rebuild-prod.yaml new file mode 100644 index 0000000..4121af7 --- /dev/null +++ b/.gitea/workflows/rebuild-prod.yaml @@ -0,0 +1,89 @@ +# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions +name: Build Images and Deploy +run-name: ${{ gitea.actor }} is building new PROD images and redeploying the existing stack 🚀 +on: + push: + # not working right now https://github.com/actions/runner/issues/2324 + # paths-ignore: + # - **.yml + branches: + - main + +env: + STACK_NAME: loot-hunt + DOT_ENV: ${{ secrets.PROD_ENV }} + PORTAINER_TOKEN: ${{ vars.PORTAINER_TOKEN }} + PORTAINER_API_URL: https://portainer.dev.nervesocket.com/api + ENDPOINT_NAME: "mini" #sometimes "primary" + IMAGE_TAG: "reg.dev.nervesocket.com/loot-hunt:latest" + +jobs: + Update-PROD-Stack: + runs-on: ubuntu-latest + steps: + # if: contains(github.event.pull_request.head.ref, 'init-stack') + - name: Checkout + uses: actions/checkout@v4 + with: + ref: main + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push PROD Docker image + run: | + echo $DOT_ENV | base64 -d > .env + docker buildx build --push -f Dockerfile -t $IMAGE_TAG . + + - name: Get the endpoint ID + # Usually ID is 1, but you can get it from the API. Only skip this if you are VERY sure. + run: | + ENDPOINT_ID=$(curl -s -H "X-API-Key: $PORTAINER_TOKEN" "$PORTAINER_API_URL/endpoints" | jq -r ".[] | select(.Name==\"$ENDPOINT_NAME\") | .Id") + echo "ENDPOINT_ID=$ENDPOINT_ID" >> $GITHUB_ENV + echo "Got stack Endpoint ID: $ENDPOINT_ID" + + - name: Fetch stack ID from Portainer + run: | + STACK_ID=$(curl -s -H "X-API-Key: $PORTAINER_TOKEN" "$PORTAINER_API_URL/stacks" | jq -r ".[] | select(.Name==\"$STACK_NAME\" and .EndpointId==$ENDPOINT_ID) | .Id") + + echo "STACK_ID=$STACK_ID" >> $GITHUB_ENV + echo "Got stack ID: $STACK_ID matched with Endpoint ID: $ENDPOINT_ID" + + - name: Fetch Stack + run: | + # Get the stack details (including env vars) + STACK_DETAILS=$(curl -s -H "X-API-Key: $PORTAINER_TOKEN" "$PORTAINER_API_URL/stacks/$STACK_ID") + + # Extract environment variables from the stack + echo "$STACK_DETAILS" | jq -r '.Env' > stack_env.json + + echo "Existing stack environment variables:" + cat stack_env.json + + - name: Redeploy stack in Portainer + run: | + # Read stack file content + STACK_FILE_CONTENT=$(echo "$(