Skip to content

Commit

Permalink
V5.2.4 - Added biome.json, Linted, Formatted, Bumped File Versions
Browse files Browse the repository at this point in the history
  • Loading branch information
xbubbo committed Jun 16, 2024
1 parent 4ece1dc commit 5bd869e
Show file tree
Hide file tree
Showing 26 changed files with 4,004 additions and 257 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ node_modules
.idea
.DS_Store
.hintrc
.gitpod.yml
pnpm-lock.yaml
package-lock.json
bun.lockb
.gitpod.yml
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
Expand Down
21 changes: 17 additions & 4 deletions Masqr.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "node:fs"
import path from "node:path"
import fs from "fs"
import fetch from "node-fetch"

const LICENSE_SERVER_URL = "https://masqr.gointerstellar.app/validate?license="
Expand All @@ -14,11 +14,13 @@ export function setupMasqr(app) {

const authheader = req.headers.authorization

// biome-ignore lint/complexity/useLiteralKeys: <explanation>
if (req.cookies["authcheck"]) {
next()
return
}

// biome-ignore lint/complexity/useLiteralKeys: <explanation>
if (req.cookies["refreshcheck"] !== "true") {
res.cookie("refreshcheck", "true", { maxAge: 10000 })
MasqFail(req, res)
Expand All @@ -36,11 +38,20 @@ export function setupMasqr(app) {
const pass = auth[1]

try {
const licenseCheckResponse = await fetch(LICENSE_SERVER_URL + pass + "&host=" + req.headers.host)
const licenseCheckResponse = await fetch(
// biome-ignore lint/style/useTemplate: <explanation>
LICENSE_SERVER_URL + pass + "&host=" + req.headers.host
)
// biome-ignore lint/complexity/useLiteralKeys: <explanation>
const licenseCheck = (await licenseCheckResponse.json())["status"]
console.log(LICENSE_SERVER_URL + pass + "&host=" + req.headers.host + " returned " + licenseCheck)
console.log(
// biome-ignore lint/style/useTemplate: <explanation>
LICENSE_SERVER_URL + pass + "&host=" + req.headers.host + " returned " + licenseCheck
)
if (licenseCheck === "License valid") {
res.cookie("authcheck", "true", { expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000) })
res.cookie("authcheck", "true", {
expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000),
})
res.send("<script> window.location.href = window.location.href </script>")
return
}
Expand All @@ -57,8 +68,10 @@ async function MasqFail(req, res) {
if (!req.headers.host) {
return
}
// biome-ignore lint/style/useTemplate: <explanation>
const unsafeSuffix = req.headers.host + ".html"
const safeSuffix = path.normalize(unsafeSuffix).replace(/^(\.\.(\/|\\|$))+/, "")
// biome-ignore lint/style/useTemplate: <explanation>
const safeJoin = path.join(process.cwd() + "/Masqrd", safeSuffix)
try {
await fs.promises.access(safeJoin)
Expand Down
15 changes: 15 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json",
"files": {
"ignore": ["static/dy/**", "static/assets/-/"]
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import http from "node:http"
import path from "node:path"
import { createBareServer } from "@tomphttp/bare-server-node"
import chalk from "chalk"
import cookieParser from "cookie-parser"
import cors from "cors"
import express from "express"
import basicAuth from "express-basic-auth"
import cookieParser from "cookie-parser"
import mime from "mime"
import fetch from "node-fetch"
import config from "./config.js"
import { setupMasqr } from "./Masqr.js"
import chalk from "chalk"
import config from "./config.js"

console.log(chalk.yellow("🚀 Starting server..."))

Expand All @@ -23,6 +23,7 @@ const CACHE_TTL = 30 * 24 * 60 * 60 * 1000 // Cache for 30 Days

if (config.challenge) {
console.log(chalk.green("🔒 Password protection is enabled! Listing logins below"))
// biome-ignore lint/complexity/noForEach:
Object.entries(config.users).forEach(([username, password]) => {
console.log(chalk.blue(`Username: ${username}, Password: ${password}`))
})
Expand Down Expand Up @@ -101,8 +102,9 @@ const routes = [
{ path: "/privacy", file: "privacy.html" },
]

// biome-ignore lint/complexity/noForEach:
routes.forEach((route) => {
app.get(route.path, (req, res) => {
app.get(route.path, (_req, res) => {
res.sendFile(path.join(__dirname, "static", route.file))
})
})
Expand Down
Loading

0 comments on commit 5bd869e

Please sign in to comment.