generated from azures04/Base-REST-API
Refactor API for game file download and listing
Removed user registration and user info endpoints, along with related schemas, services, and tests. Added new routes and service for listing and downloading game files. Updated README to reflect new API purpose. Refactored logger and utils for improved modularity.
This commit is contained in:
10
routes/download.js
Normal file
10
routes/download.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const gameFilesService = require("../services/gameDataService")
|
||||
|
||||
router.get(/.*/, async (req, res) => {
|
||||
const fileRequest = await gameFilesService.getFile(req.baseUrl.replace("/download/", ""))
|
||||
return res.status(fileRequest.code).sendFile(fileRequest.path)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
10
routes/gamefiles.js
Normal file
10
routes/gamefiles.js
Normal file
@@ -0,0 +1,10 @@
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const gameFilesService = require("../services/gameDataService")
|
||||
|
||||
router.get("", async (req, res) => {
|
||||
const gameIndex = await gameFilesService.getGameFiles()
|
||||
return res.status(200).json(gameIndex)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -1,15 +0,0 @@
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const registerService = require("../services/register")
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
const { email, username, password } = req.body
|
||||
const registerResult = registerService.register({ email, username, password })
|
||||
return res.status(200).json({
|
||||
code: 200,
|
||||
message: "User successfully registered",
|
||||
data: registerResult
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -1,17 +0,0 @@
|
||||
const express = require("express")
|
||||
const DefaultError = require("../../errors/DefaultError")
|
||||
const router = express.Router()
|
||||
|
||||
router.get("", async (req, res) => {
|
||||
const bearer = req.headers.authorization
|
||||
if (bearer == "Bearer token") {
|
||||
return res.status(200).json({
|
||||
id: req.params.id,
|
||||
username: "johndoe"
|
||||
})
|
||||
} else {
|
||||
throw new DefaultError(403, "Invalid token", "", "InvalidTokenException")
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user