Mod, createMod and About pages, input fields, some more content and a LOT of fixes (including backend)
This commit is contained in:
parent
a7cf958770
commit
534d251852
28 changed files with 909 additions and 52 deletions
|
|
@ -43,7 +43,7 @@ async function getModByName(req, res) {
|
|||
try {
|
||||
// Query
|
||||
const name = req.params.name
|
||||
const query_result = await mod_service.getModByName(name);
|
||||
const query_result = await mod_service.getFullModInfos(name);
|
||||
res.json(query_result);
|
||||
} catch (error) {
|
||||
handleError(error, res);
|
||||
|
|
|
|||
|
|
@ -14,24 +14,25 @@ async function getModByName(name) {
|
|||
|
||||
}
|
||||
|
||||
async function getModFullInfos(name) {
|
||||
async function getFullModInfos(name) {
|
||||
|
||||
// Query
|
||||
const base_infos = db.query(`SELECT * FROM Mods WHERE name = ?`, [name]);
|
||||
const other_infos = db.query(`SELECT full_description, license, links, creation_date, downloads_count
|
||||
FROM ModInfos WHERE name = ?`, [name]);
|
||||
const tags = getModTags(name);
|
||||
FROM ModInfos WHERE mod = ?`, [name]);
|
||||
const tags = listTags(name);
|
||||
|
||||
// Merge
|
||||
const res = {...await base_infos, ...await other_infos, ...tags};
|
||||
|
||||
return res;
|
||||
return [await base_infos, await other_infos, await tags];
|
||||
}
|
||||
|
||||
async function listVersions(mod_name) {
|
||||
return await db.query("SELECT * FROM ModVersions WHERE mod = ?", [mod_name]);
|
||||
}
|
||||
|
||||
async function listTags(mod_name) {
|
||||
return await db.query(`SELECT tag FROM ModTags WHERE mod = ?`, [mod_name]);
|
||||
}
|
||||
|
||||
async function getVersionByNumber(mod_name, version_number) {
|
||||
return await db.query(`SELECT * FROM ModVersions
|
||||
WHERE mod = ?
|
||||
|
|
@ -184,8 +185,8 @@ async function containsTag(name, tag) {
|
|||
|
||||
// --- Exports ---
|
||||
|
||||
module.exports = { getAllMods, getModByName, getModFullInfos,
|
||||
listVersions, getVersionByNumber, getVersion,
|
||||
module.exports = { getAllMods, getModByName, getFullModInfos,
|
||||
listVersions, listTags, getVersionByNumber, getVersion,
|
||||
createMod, addVersion, addTags,
|
||||
updateMod,
|
||||
deleteMod, deleteVersion, deleteTags,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ async function getAllMods() {
|
|||
}
|
||||
|
||||
async function getModByName(name) {
|
||||
const res = model.getModByName(name);
|
||||
const res = await model.getModByName(name);
|
||||
if (res.length == 0) {
|
||||
throw new AppError(404, "Cannot find mod with this name", "Not found");
|
||||
}
|
||||
|
|
@ -20,16 +20,20 @@ async function getModByName(name) {
|
|||
}
|
||||
|
||||
async function getFullModInfos(name) {
|
||||
const res = model.getFullModInfos(name);
|
||||
if (res.length == 0) {
|
||||
throw new AppError(404, "Cannot find mod with this name", "Not found");
|
||||
const [base_infos, other_infos, tags] = await model.getFullModInfos(name);
|
||||
// Check
|
||||
if (base_infos.length == 0 || other_infos.length === 0) {
|
||||
throw new AppError(404, "Cannot find mod with this name", "Not found", "Couldn't retrieve from database correctly");
|
||||
}
|
||||
return res[0];
|
||||
// Merge
|
||||
const mod_infos = {...other_infos[0], tags: tags}
|
||||
const res = {...base_infos[0], mod_infos: mod_infos};
|
||||
return res;
|
||||
}
|
||||
|
||||
async function getModVersion(infos) {
|
||||
const { mod, version_number, game_version, platform, environment} = infos;
|
||||
const res = model.getModVersion(mod, version_number, game_version, platform, environment);
|
||||
const res = await model.getModVersion(mod, version_number, game_version, platform, environment);
|
||||
if (res.length == 0) {
|
||||
throw new AppError(404, "Cannot find mod with this name", "Not found");
|
||||
}
|
||||
|
|
@ -51,7 +55,7 @@ async function createMod(mod_data, author) {
|
|||
mod_infos.full_description = await mdToHtml(mod_infos.full_description); // Convert
|
||||
await sanitizeModData(mod_data); // Sanitize
|
||||
//TODO
|
||||
mod_infos.creation_date = 0
|
||||
mod_infos.creation_date = Date.now();
|
||||
|
||||
// Write changes to database
|
||||
await model.createMod(name, display_name, author, description, mod_infos);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue