Add static dir, add ModDownload

master
rubenwardy 2017-01-22 20:35:15 +00:00
parent c40adba111
commit 5618a6f645
3 changed files with 58 additions and 26 deletions

View File

@ -17,6 +17,7 @@ router.get("/", function(req, res) {
}) })
}) })
router.use("/static", express.static("static"))
router.use(require("./mods")) router.use(require("./mods"))
router.use("/workers", require("./workerapi")) router.use("/workers", require("./workerapi"))

View File

@ -38,7 +38,7 @@ router.get("/mod/:author/:modname", function(req, res) {
include: [{ include: [{
model: db.User, model: db.User,
where: { username: req.params.author } where: { username: req.params.author }
}, db.Work] }, db.Work, db.ModDownload]
}).then(function(mod) { }).then(function(mod) {
if (mod) { if (mod) {
var mod_c = db.convertRowToMod(mod) var mod_c = db.convertRowToMod(mod)

View File

@ -25,19 +25,25 @@ var Mod = sequelize.define("mod", {
description: Sequelize.STRING(900), description: Sequelize.STRING(900),
forum_id: Sequelize.STRING(40), 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_url: Sequelize.STRING(250),
repo_hash: Sequelize.STRING(250), repo_hash: Sequelize.STRING(250),
approved: Sequelize.BOOLEAN approved: Sequelize.BOOLEAN,
}) })
User.hasMany(Mod) User.hasMany(Mod)
Mod.belongsTo(User) Mod.belongsTo(User)
var ModDownload = sequelize.define("moddownload", {
url: Sequelize.STRING(250),
hash: Sequelize.STRING(256),
size: Sequelize.INTEGER,
approved: Sequelize.BOOLEAN,
})
Mod.hasMany(ModDownload)
ModDownload.belongsTo(Mod)
var Worker = sequelize.define("worker", { var Worker = sequelize.define("worker", {
token: Sequelize.STRING(128) token: Sequelize.STRING(128)
}) })
@ -60,11 +66,23 @@ function convertRowToMod(row) {
mod.description = row.description mod.description = row.description
mod.forum_id = row.forum_id mod.forum_id = row.forum_id
mod.forum_url = mod.getForumURL() mod.forum_url = mod.getForumURL()
mod.download = { mod.downloads = []
url: row.download_url, mod.download = null
hash: row.download_hash || "",
size: row.download_size || -1 if (row.moddownloads) {
mod.downloads = row.moddownloads.map((download) => {
return {
url: download.url,
hash: download.hash || "",
size: download.size || -1
}
})
if (mod.downloads.length > 0) {
mod.download = mod.downloads[0]
}
} }
mod.repo = { mod.repo = {
url: row.repo, url: row.repo,
hash: row.repo_hash hash: row.repo_hash
@ -77,6 +95,7 @@ function convertRowToMod(row) {
async.parallel([ async.parallel([
function(callback) { User.sync().then(callback) }, function(callback) { User.sync().then(callback) },
function(callback) { Mod.sync().then(callback) }, function(callback) { Mod.sync().then(callback) },
function(callback) { ModDownload.sync().then(callback) },
function(callback) { Worker.sync().then(callback) }, function(callback) { Worker.sync().then(callback) },
function(callback) { Work.sync().then(callback) }, function(callback) { Work.sync().then(callback) },
function() { function() {
@ -103,10 +122,6 @@ async.parallel([
description: "Adds awards to minetest", description: "Adds awards to minetest",
forum_id: "4870", 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_url: "https://github.com/minetest-mods/awards/",
repo_hash: "c994978683355417783586262914d4be128cbdf0", repo_hash: "c994978683355417783586262914d4be128cbdf0",
@ -115,24 +130,39 @@ async.parallel([
}).then(function(mod) { }).then(function(mod) {
mod = mod[0] mod = mod[0]
Worker.findOrCreate({ ModDownload.findOrCreate({
where: { where: {
token: "foobar" modId: mod.id
}, },
defaults: {} defaults: {
}).then(function(worker) { mod: mod,
worker = worker[0]
Work.findOrCreate({ url: "https://github.com/minetest-mods/awards/zipball/master",
hash: "",
size: -1,
approved: true
}
}).then(function(moddownload) {
Worker.findOrCreate({
where: { where: {
modId: mod.id token: "foobar"
}, },
defaults: { defaults: {}
mod: mod, }).then(function(worker) {
work_type: "fetch" worker = worker[0]
}
}).then(function(mod) {
Work.findOrCreate({
where: {
modId: mod.id
},
defaults: {
mod: mod,
work_type: "fetch"
}
}).then(function(mod) {
})
}) })
}) })
}) })
@ -142,6 +172,7 @@ async.parallel([
module.exports = { module.exports = {
User: User, User: User,
Mod: Mod, Mod: Mod,
ModDownload: ModDownload,
Work: Work, Work: Work,
Worker: Worker, Worker: Worker,
convertRowToMod: convertRowToMod convertRowToMod: convertRowToMod