Add Mod, database, and other initial improvements
parent
009bdddd0c
commit
a9d2bb4ab9
|
@ -5,6 +5,7 @@ downloads.txt
|
||||||
reports.json
|
reports.json
|
||||||
downloads.json
|
downloads.json
|
||||||
/data
|
/data
|
||||||
|
*.sqlite
|
||||||
|
|
||||||
|
|
||||||
# Created by https://www.gitignore.io/api/node,linux
|
# Created by https://www.gitignore.io/api/node,linux
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
"use strict"
|
||||||
|
|
||||||
|
var ModType = {
|
||||||
|
mod: "mod",
|
||||||
|
modpack: "modpack",
|
||||||
|
game: "game"
|
||||||
|
}
|
||||||
|
|
||||||
|
class Mod {
|
||||||
|
constructor(author) {
|
||||||
|
this.author = author || null
|
||||||
|
this.type = "1"
|
||||||
|
this.basename = null
|
||||||
|
this.title = null
|
||||||
|
this.description = ""
|
||||||
|
this.forum_id = null
|
||||||
|
this.forum_url = null
|
||||||
|
|
||||||
|
this.download = null
|
||||||
|
this.repo = null
|
||||||
|
this.approved = false
|
||||||
|
}
|
||||||
|
|
||||||
|
getForumURL() {
|
||||||
|
return "https://forum.minetest.net/viewtopic.php?t=" + this.forum_id
|
||||||
|
}
|
||||||
|
|
||||||
|
getIssues() {
|
||||||
|
var problems = []
|
||||||
|
|
||||||
|
if (!this.author) {
|
||||||
|
problems.append("needs forum author name")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.basename) {
|
||||||
|
problems.append("needs basename")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.title) {
|
||||||
|
problems.append("needs title (this should never happen)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.download_link) {
|
||||||
|
problems.append("needs download link")
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
problems: problems,
|
||||||
|
suggestions: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toPlainDictionary() {
|
||||||
|
function isFunction(obj) {
|
||||||
|
return !!(obj && obj.constructor && obj.call && obj.apply)
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = {}
|
||||||
|
for (var key in this) {
|
||||||
|
if (this.hasOwnProperty(key) && !isFunction(this[key])) {
|
||||||
|
res[key] = this[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Mod
|
|
@ -20,6 +20,8 @@
|
||||||
"apicache": "^0.7.4",
|
"apicache": "^0.7.4",
|
||||||
"body-parser": "^1.15.2",
|
"body-parser": "^1.15.2",
|
||||||
"express": "^4.14.0",
|
"express": "^4.14.0",
|
||||||
"express-liquid": "^0.2.6"
|
"express-liquid": "^0.2.6",
|
||||||
|
"sequelize": "^3.28.0",
|
||||||
|
"sqlite3": "^3.1.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
// Index controller - puts all the controllers together
|
// Index controller - puts all the controllers together
|
||||||
"use strict";
|
"use strict"
|
||||||
|
|
||||||
const express = require("express")
|
const express = require("express")
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.get("/", function(req, res) {
|
router.get("/", function(req, res) {
|
||||||
res.render("index", {
|
var db = req.app.get("db")
|
||||||
title: "Mod Developer Panel",
|
db.Mod.findAll({
|
||||||
mods: []
|
limit: 10,
|
||||||
|
include: [ db.User ]
|
||||||
|
}).then(function(mods) {
|
||||||
|
res.render("index", {
|
||||||
|
title: "Minetest Mod Database",
|
||||||
|
mods: mods.map(db.convertRowToMod)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"use strict";
|
"use strict"
|
||||||
|
|
||||||
require("process").chdir(__dirname)
|
require("process").chdir(__dirname)
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ var expressLiquid = require("express-liquid")
|
||||||
var options = {
|
var options = {
|
||||||
// read file handler, optional
|
// read file handler, optional
|
||||||
includeFile: function (filename, callback) {
|
includeFile: function (filename, callback) {
|
||||||
var fs = require("fs");
|
var fs = require("fs")
|
||||||
fs.readFile(filename, "utf8", callback);
|
fs.readFile(filename, "utf8", callback)
|
||||||
},
|
},
|
||||||
// the base context, optional
|
// the base context, optional
|
||||||
context: expressLiquid.newContext(),
|
context: expressLiquid.newContext(),
|
||||||
|
@ -28,15 +28,19 @@ var options = {
|
||||||
customTags: {},
|
customTags: {},
|
||||||
// if an error occurred while rendering, show detail or not, default to false
|
// if an error occurred while rendering, show detail or not, default to false
|
||||||
traceError: false
|
traceError: false
|
||||||
};
|
}
|
||||||
app.set("view engine", "liquid");
|
app.set("view engine", "liquid")
|
||||||
app.engine("liquid", expressLiquid(options));
|
app.engine("liquid", expressLiquid(options))
|
||||||
app.use(expressLiquid.middleware);
|
app.use(expressLiquid.middleware)
|
||||||
|
|
||||||
|
// Database
|
||||||
|
const db = require("./models/database")
|
||||||
|
app.set("db", db)
|
||||||
|
|
||||||
// Controllers
|
// Controllers
|
||||||
app.use(require("./controllers"))
|
app.use(require("./controllers"))
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
app.listen(8080, "127.0.0.1", function () {
|
app.listen(8080, "127.0.0.1", function () {
|
||||||
console.log("Minetest Mod Database listening on port 8080!");
|
console.log("Minetest Mod Database listening on port 8080!")
|
||||||
});
|
})
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
var Sequelize = require("sequelize")
|
||||||
|
var async = require("async")
|
||||||
|
|
||||||
|
var sequelize = new Sequelize("database", "", "", {
|
||||||
|
dialect: "sqlite",
|
||||||
|
pool: {
|
||||||
|
max: 5,
|
||||||
|
min: 0,
|
||||||
|
idle: 10000
|
||||||
|
},
|
||||||
|
|
||||||
|
// SQLite only
|
||||||
|
storage: "../db.sqlite"
|
||||||
|
})
|
||||||
|
|
||||||
|
var User = sequelize.define("user", {
|
||||||
|
username: { type: Sequelize.STRING(100), unique: true }
|
||||||
|
})
|
||||||
|
|
||||||
|
var Mod = sequelize.define("mod", {
|
||||||
|
basename: Sequelize.STRING(100),
|
||||||
|
|
||||||
|
title: Sequelize.STRING(100),
|
||||||
|
description: Sequelize.STRING(900),
|
||||||
|
forum_id: Sequelize.STRING(40),
|
||||||
|
|
||||||
|
download_url: Sequelize.STRING(250),
|
||||||
|
download_hash: Sequelize.STRING(256),
|
||||||
|
download_size: Sequelize.INTEGER,
|
||||||
|
|
||||||
|
repo_url: Sequelize.STRING(250),
|
||||||
|
repo_hash: Sequelize.STRING(250),
|
||||||
|
|
||||||
|
approved: Sequelize.BOOLEAN
|
||||||
|
})
|
||||||
|
|
||||||
|
User.hasMany(Mod)
|
||||||
|
Mod.belongsTo(User)
|
||||||
|
|
||||||
|
const CMod = require("./../../common/mod")
|
||||||
|
function convertRowToMod(row) {
|
||||||
|
var mod = new CMod(row.user.username)
|
||||||
|
mod.basename = row.basename
|
||||||
|
mod.title = row.title
|
||||||
|
mod.description = row.description
|
||||||
|
mod.forum_id = row.forum_id
|
||||||
|
mod.forum_url = mod.getForumURL()
|
||||||
|
mod.download = {
|
||||||
|
url: row.download_url,
|
||||||
|
hash: row.download_hash || "",
|
||||||
|
size: row.download_size || -1
|
||||||
|
}
|
||||||
|
mod.repo = {
|
||||||
|
url: row.repo,
|
||||||
|
hash: row.repo_hash
|
||||||
|
}
|
||||||
|
mod.approved = row.approved
|
||||||
|
|
||||||
|
return mod
|
||||||
|
}
|
||||||
|
|
||||||
|
async.parallel([
|
||||||
|
function(callback) { User.sync().then(callback) },
|
||||||
|
function(callback) { Mod.sync().then(callback) },
|
||||||
|
function() {
|
||||||
|
User.findOrCreate({
|
||||||
|
where: {
|
||||||
|
username: "rubenwardy"
|
||||||
|
},
|
||||||
|
defaults: {}
|
||||||
|
}).then(function(user) {
|
||||||
|
user = user[0]
|
||||||
|
|
||||||
|
var assert = require("assert")
|
||||||
|
assert(user.id)
|
||||||
|
Mod.findOrCreate({
|
||||||
|
where: {
|
||||||
|
basename: "awards",
|
||||||
|
userId: user.id
|
||||||
|
},
|
||||||
|
defaults: {
|
||||||
|
user: user,
|
||||||
|
|
||||||
|
title: "Awards",
|
||||||
|
description: "Adds awards to minetest",
|
||||||
|
forum_id: "4870",
|
||||||
|
|
||||||
|
download_url: "https://github.com/minetest-mods/awards/zipball/master",
|
||||||
|
download_hash: "",
|
||||||
|
download_size: -1,
|
||||||
|
|
||||||
|
repo_url: "https://github.com/minetest-mods/awards/",
|
||||||
|
repo_hash: "c994978683355417783586262914d4be128cbdf0",
|
||||||
|
|
||||||
|
approved: true
|
||||||
|
}
|
||||||
|
}).then(function(mod) {
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}])
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
User: User,
|
||||||
|
Mod: Mod,
|
||||||
|
convertRowToMod: convertRowToMod
|
||||||
|
}
|
|
@ -15,13 +15,18 @@
|
||||||
{% for mod in mods %}
|
{% for mod in mods %}
|
||||||
<li>
|
<li>
|
||||||
<span style="padding-right:10px">{{ forloop.index }})</span>
|
<span style="padding-right:10px">{{ forloop.index }})</span>
|
||||||
<a href="{{ mod.forum_url }}">{{ mod.title }}</a> by {{ mod.author }}<br />
|
|
||||||
|
<a href="/mod/{{ mod.author }}/{{ mod.basename }}/">{{ mod.title }}</a>
|
||||||
|
by
|
||||||
|
{{ mod.author }}
|
||||||
|
<br />
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{{ mod.description | truncate: 100, '…' }}
|
{{ mod.description | truncate: 100, '…' }}
|
||||||
</p>
|
</p>
|
||||||
<a href="{{ mod.download_link }}">Download</a> [{{ mod.downloads }}] |
|
<a href="{{ mod.download.url }}">Download</a> |
|
||||||
<a href="{{ mod.forum_url }}">Forum Topic</a> |
|
<a href="{{ mod.forum_url }}">Forum Topic</a> |
|
||||||
<a href="/status/?a={{ mod.author }}">{{ mod.author }}'s mods</a>
|
<a href="/mods/?a={{ mod.author }}">{{ mod.author }}'s mods</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in New Issue