bump, add /info endpoint, cleanup

This commit is contained in:
Aidan 2025-07-08 20:49:30 -04:00
parent 0ceb0b61b4
commit da82475262
4 changed files with 74 additions and 12 deletions

6
server/.gitignore vendored
View file

@ -38,3 +38,9 @@ bun.lock*
# Files
serve/
# db
dev.db
# config
config/config.ts

View file

@ -0,0 +1,25 @@
export const config: Config = {
name: "Example Server", // what your server should be named in BeeSrv
author: "example", // who owns this server?
channelLink: "https://t.me/example", // telegram channel link
currentBox: {
enabled: true, // if you want to serve the box, set to true
name: "Example Beebox", // what your box should be named in BeeSrv
originalAuthor: "Author", // who originally shared the beebox, if applicable
},
}
// don't change this
export interface Config {
name: string
author: string
channelLink: string
currentBox: {
enabled: boolean
name: string
originalAuthor: string
}
}

View file

@ -8,17 +8,17 @@
"start": "bun run src/index.ts"
},
"devDependencies": {
"@types/bun": "^1.2.9",
"@types/bun": "^1.2.18",
"drizzle-kit": "^0.30.6"
},
"peerDependencies": {
"typescript": "^5.8.3"
},
"dependencies": {
"@types/express": "^5.0.1",
"better-sqlite3": "^11.9.1",
"@types/express": "^5.0.3",
"better-sqlite3": "^11.10.0",
"chalk": "^5.4.1",
"dotenv": "^16.5.0",
"dotenv": "^16.6.1",
"drizzle-orm": "^0.41.0",
"express": "^5.1.0"
}

View file

@ -8,6 +8,7 @@ import { eq, and, gte } from "drizzle-orm"
import chalk from "chalk"
import * as schema from './db/schema'
import path from 'path'
import { config } from '../config/config'
const app = express()
const sqlite = new Database(process.env.DB_FILE_NAME || 'dev.db')
@ -43,6 +44,36 @@ function checkRateLimit(email: string): boolean {
return true
}
app.get("/info", (async (req, res) => {
const info: Record<string, any> = {
name: config.name,
author: config.author,
channelLink: config.channelLink,
};
if (config.currentBox.enabled) {
info.currentBox = config.currentBox;
try {
const beebox = await Bun.file(path.join(__dirname, '../serve/beebox.xml'))
const bbxContent = await beebox.text()
if (!bbxContent) {
console.log(chalk.red(`[INFO]`) + ` Error reading beebox file`)
info.error = "Unable to find beebox file on server"
} else {
const hasher = new Bun.CryptoHasher("sha256")
const bbxHash = await hasher.update(bbxContent).digest()
const bbxHashHex = bbxHash.toString('hex')
info.currentBox.hash = bbxHashHex
}
} catch (error) {
console.log(chalk.red(`[INFO]`) + ` Error reading beebox file`)
info.error = "Unable to find beebox file on server"
}
}
res.json(info);
}) as RequestHandler)
app.post("/bee-req", (async (req, res) => {
const { deviceID, version, email } = req.body
const requestID = randomUUID()