mirror of
https://github.com/Zandercraft/TechnicFlux.git
synced 2026-10-29 04:39:20 +00:00
Add API key validation route.
This commit is contained in:
2
app.js
2
app.js
@@ -5,7 +5,6 @@ const cookieParser = require('cookie-parser')
|
|||||||
const logger = require('morgan')
|
const logger = require('morgan')
|
||||||
|
|
||||||
const indexRouter = require('./routes/index')
|
const indexRouter = require('./routes/index')
|
||||||
const usersRouter = require('./routes/users')
|
|
||||||
const apiRouter = require('./routes/api')
|
const apiRouter = require('./routes/api')
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
@@ -21,7 +20,6 @@ app.use(cookieParser())
|
|||||||
app.use(express.static(path.join(__dirname, 'public')))
|
app.use(express.static(path.join(__dirname, 'public')))
|
||||||
|
|
||||||
app.use('/', indexRouter)
|
app.use('/', indexRouter)
|
||||||
app.use('/users', usersRouter)
|
|
||||||
app.use('/api', apiRouter)
|
app.use('/api', apiRouter)
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
const pckg = require('../package.json')
|
const pckg = require('../package.json')
|
||||||
const branchName = require('current-git-branch');
|
const branchName = require('current-git-branch')();
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.get('/', (req, res) => {
|
router.get('/', (req, res) => {
|
||||||
res.json({
|
res.json({
|
||||||
"api": pckg.prettyName,
|
"api": pckg.prettyName,
|
||||||
"version": pckg.version,
|
"version": pckg.version,
|
||||||
"stream": branchName()
|
"stream": branchName
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get('/mod/:modname', (req, res) => {
|
router.get('/mod/:modname/:modversion?', (req, res) => {
|
||||||
// Found
|
// Found mod
|
||||||
res.json({
|
res.json({
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"name": "example",
|
"name": "example",
|
||||||
@@ -26,14 +26,7 @@ router.get('/mod/:modname', (req, res) => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
// Not Found
|
// Found mod version
|
||||||
// res.status(404).json({
|
|
||||||
// "error": "Mod does not exist"
|
|
||||||
// })
|
|
||||||
})
|
|
||||||
|
|
||||||
router.get('/mod/:modname/:modversion', (req, res) => {
|
|
||||||
// Found
|
|
||||||
res.json({
|
res.json({
|
||||||
"id": 0,
|
"id": 0,
|
||||||
"md5": "51c1305b56249804926e38fcf3e46640",
|
"md5": "51c1305b56249804926e38fcf3e46640",
|
||||||
@@ -41,15 +34,15 @@ router.get('/mod/:modname/:modversion', (req, res) => {
|
|||||||
"url": "https://example.com/file.zip",
|
"url": "https://example.com/file.zip",
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mod Not Found
|
|
||||||
// res.status(404).json({
|
|
||||||
// "error": "Mod does not exist"
|
|
||||||
// })
|
|
||||||
|
|
||||||
// Version Not Found
|
// Version Not Found
|
||||||
// res.status(404).json({
|
// res.status(404).json({
|
||||||
// "error": "Mod version does not exist"
|
// "error": "Mod version does not exist"
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
// Mod Not Found
|
||||||
|
// res.status(404).json({
|
||||||
|
// "error": "Mod does not exist"
|
||||||
|
// })
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get('/modpack', (req, res) => {
|
router.get('/modpack', (req, res) => {
|
||||||
@@ -62,7 +55,7 @@ router.get('/modpack', (req, res) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get('/modpack/:slug', (req, res) => {
|
router.get('/modpack/:slug/:build?', (req, res) => {
|
||||||
// With Slug
|
// With Slug
|
||||||
res.json({
|
res.json({
|
||||||
"name": "examplepack",
|
"name": "examplepack",
|
||||||
@@ -75,13 +68,6 @@ router.get('/modpack/:slug', (req, res) => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
// Modpack Not Found
|
|
||||||
// res.status(404).json({
|
|
||||||
// "error": "Modpack does not exist"
|
|
||||||
// })
|
|
||||||
})
|
|
||||||
|
|
||||||
router.get('/modpack/:slug/:build', (req, res) => {
|
|
||||||
// Build found
|
// Build found
|
||||||
res.json({
|
res.json({
|
||||||
"minecraft": "1.20.1",
|
"minecraft": "1.20.1",
|
||||||
@@ -99,15 +85,33 @@ router.get('/modpack/:slug/:build', (req, res) => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Build Not Found
|
||||||
|
// res.status(404).json({
|
||||||
|
// "error": "Build does not exist"
|
||||||
|
// })
|
||||||
|
|
||||||
// Modpack Not Found
|
// Modpack Not Found
|
||||||
// res.status(404).json({
|
// res.status(404).json({
|
||||||
// "error": "Modpack does not exist"
|
// "error": "Modpack does not exist"
|
||||||
// })
|
// })
|
||||||
|
})
|
||||||
|
|
||||||
// Build Not Found
|
router.get('/verify/:key?', (req, res) => {
|
||||||
// res.status(404).json({
|
// Key validated
|
||||||
// "error": "Build does not exist"
|
res.json({
|
||||||
|
valid: "Key validated.",
|
||||||
|
name: "API KEY",
|
||||||
|
created_at: "A long time ago"
|
||||||
|
})
|
||||||
|
|
||||||
|
// Invalid key provided
|
||||||
|
// res.json({
|
||||||
|
// error: 'Invalid key provided.'
|
||||||
|
// })
|
||||||
|
|
||||||
|
// No key provided
|
||||||
|
// res.json({
|
||||||
|
// error: 'No API key provided.'
|
||||||
// })
|
// })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user