Add mods list and mod page

master
rubenwardy 2017-01-19 12:17:37 +00:00
parent a9d2bb4ab9
commit 004de36144
3 changed files with 85 additions and 1 deletions

View File

@ -11,10 +11,12 @@ router.get("/", function(req, res) {
include: [ db.User ]
}).then(function(mods) {
res.render("index", {
title: "Minetest Mod Database",
title: "Welcome",
mods: mods.map(db.convertRowToMod)
})
})
})
router.use(require("./mods"))
module.exports = router

View File

@ -0,0 +1,65 @@
// Index controller - puts all the controllers together
"use strict"
const express = require("express")
const router = express.Router()
router.get("/mods", function(req, res) {
var db = req.app.get("db")
db.Mod.findAll({
limit: 10,
include: [ db.User ]
}).then(function(mods) {
var mod_c = mods.map(db.convertRowToMod)
switch (req.accepts("html", "json")) {
case "html":
res.render("index", {
title: "Mod Search",
mods: mod_c
})
break;
case "json":
res.send(mod_c.map((mod) => { return mod.toPlainDictionary() }))
break;
default:
res.status(406).send("Not acceptable")
break
}
})
})
router.get("/mod/:author/:modname", function(req, res) {
var db = req.app.get("db")
db.Mod.findOne({
limit: 10,
where: {
basename: req.params.modname
},
include: [{
model: db.User,
where: { username: req.params.author }
}]
}).then(function(mod) {
if (mod) {
var mod_c = db.convertRowToMod(mod)
switch (req.accepts("html", "json")) {
case "html":
res.render("mod", {
title: mod.title,
mod: mod_c
})
break
case "json":
res.send(mod_c.toPlainDictionary())
break
default:
res.status(406).send("Not acceptable")
break
}
} else {
res.status(404).send("Not found")
}
})
})
module.exports = router

17
webapp/views/mod.liquid Normal file
View File

@ -0,0 +1,17 @@
{% include "header" %}
<h2>{{ mod.title }}</h2>
<a href="/mod/{{ mod.author }}/{{ mod.basename }}/">{{ mod.title }}</a>
by
{{ mod.author }}
<br />
<p>
{{ mod.description | truncate: 100, '…' }}
</p>
<a href="{{ mod.download.url }}">Download</a> |
<a href="{{ mod.forum_url }}">Forum Topic</a> |
<a href="/mods/?a={{ mod.author }}">{{ mod.author }}'s mods</a>
{% include "footer" %}