Skip to content

Commit

Permalink
feat(project): migrate to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
ckt1031 committed Oct 9, 2024
1 parent f941eb4 commit c37003b
Show file tree
Hide file tree
Showing 19 changed files with 264 additions and 226 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
15 changes: 0 additions & 15 deletions .eslintrc.json

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
- name: Build and Publish head Docker image
uses: VaultVulp/gp-docker-action@1.6.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
image-name: discord-captcha-site
image-tag: ${{ github.ref_name }}
github-token: ${{ secrets.GITHUB_TOKEN }}
image-name: discord-captcha-bot
image-tag: ${{ github.ref_name }}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ replit.nix
.env.test.local
.env.production.local
/cache/
package-lock.json
bun.lockb
dist
23 changes: 19 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
FROM node:lts-alpine
FROM node:lts-alpine AS build

WORKDIR /app

COPY package.json package-lock.json ./

RUN npm ci

COPY . .

RUN npm install --omit=dev
RUN npm run build

FROM node:lts-alpine AS production

WORKDIR /app

COPY --from=build /app/package.json /app/package-lock.json ./

RUN npm ci --omit=dev

EXPOSE ${PORT}
# COPY assets and html
COPY --from=build /app/assets ./assets
COPY --from=build /app/html ./html
COPY --from=build /app/dist ./dist

CMD ["npm", "start"]
CMD ["node", "dist/index.js"]
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ A powerful, advanced captcha verification system for new members in a Discord se
## Docker setup

If you want to run this application without installing Node.js or other tools, you can use Docker to run it. Usage:

```
docker run \
-e VERIFIED_ROLE_ID=x \
Expand All @@ -34,13 +35,13 @@ docker run \
-e CALLBACK_URL=x \
-e CLIENT_SECRET=x \
-e TOKEN=x \
ghcr.io/ckt1031/discord-captcha-site
ghcr.io/ckt1031/discord-captcha-bot
```

## Installation

1. Clone the repository
2. Install the dependencies with `npm install` or `yarn`
2. Install the dependencies with `npm install`

## Environment Variables

Expand Down Expand Up @@ -76,15 +77,14 @@ ghcr.io/ckt1031/discord-captcha-site
6. The user will have to complete the captcha
7. After the user completes the captcha, they will be given the `Verified` role and notified in the DMs

## Production Deployment

1. Install [PM2](https://pm2.keymetrics.io) with `npm install pm2 -g` or `yarn global add pm2`
2. Start the server with `pm2 start ecosystem.config.js`
3. Run command `pm2 start --max-memory-restart 300M --attach npm -- run start`
4. (Optional) Run command `pm2 startup` to enable startup on boot

# Screenshots

## Captcha Verification Page

![Captcha Verification Page](./screenshots/verify-page.png)
Light Mode:

![Captcha Verification Page](https://imgur.com/VnCbk5V.png)

Dark Mode:

![Captcha Verification Page (Dark)](https://imgur.com/ory13FX.png)
39 changes: 0 additions & 39 deletions assets/style.css

This file was deleted.

10 changes: 10 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import ts_eslint from 'typescript-eslint';

export default [
{ files: ['**/*.{js,mjs,cjs,ts}'] },
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
...ts_eslint.configs.recommended,
];
51 changes: 32 additions & 19 deletions html/captcha.html
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
<html>
<html lang="en">
<head>
<title>Verification</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<script src="<%= captcha_provider_script %>" async defer></script>
<link rel="stylesheet" href="../style.css" />
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
// Use system dark mode
darkMode: 'media',
};
</script>
</head>

<body>
<div class="main">
<h1>Verification</h1>
<h4>
Please solve the <%= captcha_provider %> following below to make sure you are not a
robot.
<body class="dark:bg-black">
<div class="h-screen flex flex-col items-center p-3">
<h1 class="mt-5 text-3xl font-bold dark:text-white">Verification</h1>
<h4 class="text-xl text-gray-600 dark:text-gray-400">
Please solve the <%= captcha_provider %> following below to make sure
you are not a robot.
</h4>
<form action="/verify/solve" method="POST" id="captcha_verification">
<center>
<div
class="g-recaptcha h-captcha cf-turnstile"
data-sitekey="<%= captcha_sitekey %>"
data-callback="onPassed"
data-expired-callback="onExpired"></div>
</center>
<form
action="/verify/solve"
method="POST"
id="captcha_verification"
class="mt-5">
<div
class="g-recaptcha h-captcha cf-turnstile"
data-sitekey="<%= captcha_sitekey %>"
data-callback="onPassed"
data-expired-callback="onExpired"></div>
</form>
</div>
<div class="footer">
<a href="../verify/logout">Logout</a>
<div class="mt-5">
<a
href="../verify/logout"
class="text-blue-500 dark:text-blue-400 hover:underline">
Logout
</a>
</div>
</div>
<script>
function onPassed() {
document.getElementById('captcha_verification').submit();
}

function onExpired() {
location.reload();
}
Expand Down
28 changes: 16 additions & 12 deletions html/error.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<html>
<html lang="en">
<head>
<title>Error Occured!</title>
<title>Error Occurred!</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" href="../style.css" />
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
// Use system dark mode
darkMode: 'media',
};
</script>
</head>

<body>
<div class="error_success">
<center>
<img
src="../cross.png"
alt="Verified"
style="width: 100px; height: 100px" />
<h1><%= messageText %></h1>
</center>
<body class="dark:bg-black">
<div class="h-screen flex flex-col justify-center items-center">
<img
src="../cross.png"
alt="Verified"
class="w-[100px] h-[100px] mb-10" />
<h1 class="text-3xl font-bold text-red-500"><%= messageText %></h1>
</div>
</body>
</html>
26 changes: 15 additions & 11 deletions html/success.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<html>
<html lang="en">
<head>
<title>Success!</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="../style.css" />
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
// Use system dark mode
darkMode: 'media',
};
</script>
</head>

<body>
<div class="error_success">
<center>
<img
src="../tick-label.png"
alt="Success"
style="width: 100px; height: 100px" />
<h1><%= messageText %></h1>
</center>
<body class="dark:bg-black">
<div class="h-screen flex flex-col justify-center items-center">
<img
src="../tick-label.png"
alt="Success"
class="w-[100px] h-[100px] mb-10" />
<h1 class="text-3xl font-bold text-green-500"><%= messageText %></h1>
</div>
</body>
</html>
26 changes: 15 additions & 11 deletions html/verified.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<html>
<html lang="en">
<head>
<title>Verified!</title>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="../style.css" />
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
// Use system dark mode
darkMode: 'media',
};
</script>
</head>

<body>
<div class="verified">
<center>
<img
src="../tick-label.png"
alt="Verified"
style="width: 100px; height: 100px" />
<h1>Verified</h1>
</center>
<body class="dark:bg-black">
<div class="h-screen flex flex-col justify-center items-center">
<img
src="../tick-label.png"
alt="Verified"
class="w-[100px] h-[100px] mb-10" />
<h1 class="text-3xl font-bold text-green-500"><%= messageText %></h1>
</div>
</body>
</html>
Loading

0 comments on commit c37003b

Please sign in to comment.