Initial project structure and core files
Add base project files including environment example, license, README, .gitignore, error classes, ESLint config, database modules, texture assets, repositories, routes, schemas, services, and server entry point. This establishes the foundational structure for a Yggdrasil-compatible REST API with modular error handling, database setup, and route organization.
This commit is contained in:
22
routes/textures/texture/[hash].js
Normal file
22
routes/textures/texture/[hash].js
Normal file
@@ -0,0 +1,22 @@
|
||||
const express = require("express")
|
||||
const router = express.Router({ mergeParams: true })
|
||||
const path = require("node:path")
|
||||
const fs = require("node:fs")
|
||||
const { DefaultError } = require("../../../errors/errors")
|
||||
|
||||
const TEXTURES_DIR = path.join(process.cwd(), "data", "textures")
|
||||
|
||||
router.get("/", async (req, res, next) => {
|
||||
try {
|
||||
const hash = req.params.hash
|
||||
const filePath = path.join(TEXTURES_DIR, hash)
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new DefaultError(404, "Texture not found")
|
||||
}
|
||||
res.sendFile(filePath)
|
||||
} catch (err) {
|
||||
return next(err)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user