mirror of
https://github.com/Zandercraft/TechnicFlux.git
synced 2026-10-29 04:39:20 +00:00
Add modpack-related database functions
This commit is contained in:
@@ -6,8 +6,8 @@
|
|||||||
# (Read the README.md file for more detailed instructions)
|
# (Read the README.md file for more detailed instructions)
|
||||||
|
|
||||||
# (REQUIRED) The connection string for your MongoDB instance (including the database)
|
# (REQUIRED) The connection string for your MongoDB instance (including the database)
|
||||||
# Ex. (No SSL): mongodb://myDatabaseUser:D1fficultP%40ssw0rd@127.0.0.1/myDatabaseName
|
# Ex. (No SSL): mongodb://myDatabaseUser:myPassword@127.0.0.1/myDatabaseName
|
||||||
# Ex. (SSL): mongodb+srv://myDatabaseUser:D1fficultP%40ssw0rd@server.example.com/myDatabaseName
|
# Ex. (SSL): mongodb+srv://myDatabaseUser:myPassword@server.example.com/myDatabaseName
|
||||||
# See https://www.mongodb.com/docs/manual/reference/connection-string/
|
# See https://www.mongodb.com/docs/manual/reference/connection-string/
|
||||||
MONGODB_CONN_STRING="mongodb://localhost:27017/technicflux"
|
MONGODB_CONN_STRING="mongodb://localhost:27017/technicflux"
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ HOST="example.com"
|
|||||||
|
|
||||||
# (REQUIRED) Solder API Key
|
# (REQUIRED) Solder API Key
|
||||||
# 1. Go to https://www.technicpack.net/
|
# 1. Go to https://www.technicpack.net/
|
||||||
# 2. Sign into your account and navigate to My Profile
|
# 2. Sign into your account and navigate to Edit My Profile
|
||||||
# 3. Go to Solder Configuration and put your API key here
|
# 3. Go to Solder Configuration and put your API key here
|
||||||
# 4. Put your solder API URL (http[s]://example.com/api/) in and link it.
|
# 4. Put your solder API URL (http[s]://example.com/api/) in and link it.
|
||||||
API_KEY=""
|
API_KEY=""
|
||||||
|
|||||||
92
database.js
92
database.js
@@ -1,3 +1,4 @@
|
|||||||
|
const debug = require('debug')('technicflux:server');
|
||||||
const mongoose = require('mongoose')
|
const mongoose = require('mongoose')
|
||||||
const { SchemaTypes } = require('mongoose')
|
const { SchemaTypes } = require('mongoose')
|
||||||
const bcrypt = require('bcryptjs')
|
const bcrypt = require('bcryptjs')
|
||||||
@@ -56,7 +57,9 @@ const Build = mongoose.model('technicflux_builds', buildSchema)
|
|||||||
// --- Functions ---
|
// --- Functions ---
|
||||||
|
|
||||||
exports.connectToDB = (connectionString) => {
|
exports.connectToDB = (connectionString) => {
|
||||||
|
debug("Connecting to MongoDB database...")
|
||||||
mongoose.connect(connectionString)
|
mongoose.connect(connectionString)
|
||||||
|
debug("Connected to database.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- User-Related Functions ---
|
// --- User-Related Functions ---
|
||||||
@@ -223,10 +226,99 @@ exports.updateUser = (u_username, object) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Modpack-Related Functions ---
|
// --- Modpack-Related Functions ---
|
||||||
|
exports.createModpack = (m_slug, m_display_name, m_owner) => {
|
||||||
|
// Create a modpack object
|
||||||
|
const newModpack = new Modpack({
|
||||||
|
name: m_slug,
|
||||||
|
display_name: m_display_name,
|
||||||
|
owners: [m_owner]
|
||||||
|
})
|
||||||
|
|
||||||
|
// Commit it to the database
|
||||||
|
return newModpack.save().then((modpack) => {
|
||||||
|
// Modpack successfully created
|
||||||
|
debug(`Successfully added new project ${modpack.display_name}: ${modpack.name}\n`)
|
||||||
|
return modpack
|
||||||
|
}).catch((reason) => {
|
||||||
|
// Modpack failed to create
|
||||||
|
debug(`ERROR (DB: when saving new modpack): ${reason}\n`)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getModpackBySlug = (m_slug) => {
|
||||||
|
return Modpack.findOne({ name: m_slug }).populate('owners').populate('collaborators').exec().then((modpack) => {
|
||||||
|
// Modpack found
|
||||||
|
return modpack
|
||||||
|
}).catch((reason) => {
|
||||||
|
// No modpack found with this slug
|
||||||
|
debug(`ERROR (DB): Failed to find a modpack with this slug because of: ${reason}`)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getModpacksByOwner = (m_owner) => {
|
||||||
|
return Modpack.find({ owners: m_owner }).populate('owners').populate('collaborators').exec().then((modpacks) => {
|
||||||
|
// Modpacks found.
|
||||||
|
return modpacks
|
||||||
|
}).catch((reason) => {
|
||||||
|
// No modpacks found for this owner.
|
||||||
|
debug(`ERROR (DB): Failed to find any modpacks with this owner because of: ${reason}`)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getModpacksByCollaborator = (m_collaborator) => {
|
||||||
|
return Modpack.find({ collaborators: m_collaborator }).populate('owners').populate('collaborators').exec().then((modpacks) => {
|
||||||
|
// Modpacks found.
|
||||||
|
return modpacks
|
||||||
|
}).catch((reason) => {
|
||||||
|
// No modpacks found for this collaborator.
|
||||||
|
debug(`ERROR (DB): Failed to find any modpacks with this collaborator because of: ${reason}`)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.getAllModpacks = () => {
|
||||||
|
// Fetch an array of all modpacks
|
||||||
|
return Modpack.find({}).populate('owners').populate('collaborators').exec().then((modpacks) => {
|
||||||
|
// Modpacks found
|
||||||
|
return modpacks
|
||||||
|
}).catch((reason) => {
|
||||||
|
// Failed to get any modpacks.
|
||||||
|
debug(`ERROR (DB): Failed to fetch any modpacks because of: ${reason}`)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.updateModpack = (m_slug, m_object) => {
|
||||||
|
return Modpack.updateOne(
|
||||||
|
{ name: m_slug },
|
||||||
|
{ $set: m_object }
|
||||||
|
).exec().then(() => {
|
||||||
|
// Successfully updated the modpack
|
||||||
|
return true
|
||||||
|
}).catch((reason) => {
|
||||||
|
// Failed to update the modpack
|
||||||
|
debug(`ERROR (DB): Failed to update modpack '${m_slug}' because of: ${reason}`)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.deleteModpack = (m_slug) => {
|
||||||
|
return Modpack.deleteOne({ name: m_slug }).exec().then(() => {
|
||||||
|
// Successfully deleted this modpack
|
||||||
|
return true
|
||||||
|
}).catch((reason) => {
|
||||||
|
// Failed to delete the modpack
|
||||||
|
debug(`ERROR (DB): Failed to delete modpack '${m_slug}' because of: ${reason}`)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// --- Mod-Related Functions ---
|
// --- Mod-Related Functions ---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// --- Build-Related Functions ---
|
// --- Build-Related Functions ---
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./bin/www"
|
"start": "set DEBUG=technicflux:* && node ./bin/www"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
|
|||||||
6
public/modloaders/.gitkeep
Normal file
6
public/modloaders/.gitkeep
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
======================INTERNAL FILE======================
|
||||||
|
This is just a placeholder file within the modloaders
|
||||||
|
route. The file itself is just used to keep the folder on
|
||||||
|
Git before any other files are added. This file is located
|
||||||
|
in the base route for modloaders in the system.
|
||||||
|
=========================================================
|
||||||
@@ -3,4 +3,4 @@ This is just a placeholder file within the mods route.
|
|||||||
The file itself is just used to keep the folder on Git
|
The file itself is just used to keep the folder on Git
|
||||||
before any other files are added. This file is located in
|
before any other files are added. This file is located in
|
||||||
the base route for mods in the system.
|
the base route for mods in the system.
|
||||||
=========================================================
|
=========================================================
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ This is just a placeholder file within the other route.
|
|||||||
The file itself is just used to keep the folder on Git
|
The file itself is just used to keep the folder on Git
|
||||||
before any other files are added. This file is located in
|
before any other files are added. This file is located in
|
||||||
the base route for other files in the system.
|
the base route for other files in the system.
|
||||||
=========================================================
|
=========================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user