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.
22 lines
645 B
JavaScript
22 lines
645 B
JavaScript
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 |