diff --git a/src/app/models/config.model.ts b/src/app/models/config.model.ts new file mode 100644 index 0000000..3359aed --- /dev/null +++ b/src/app/models/config.model.ts @@ -0,0 +1,13 @@ +import { Document, model, Schema, Types } from 'mongoose' + +const ConfigSchema = new Schema({ + json: Object, + name: String, +}) + +export type ConfigModel = Document & { + json: object, + name: string, +} + +export default model('configs', ConfigSchema, 'configs') \ No newline at end of file diff --git a/src/app/models/user.model.ts b/src/app/models/user.model.ts index ac652f5..f1471bb 100644 --- a/src/app/models/user.model.ts +++ b/src/app/models/user.model.ts @@ -6,7 +6,7 @@ const UserSchema = new Schema({ password: String, configs: [{ name: String, - conf: Object, + conf: Types.ObjectId, }] }) @@ -26,7 +26,7 @@ UserSchema.methods.changePassword = function (password: string, newPassword: str interface INamedConfig { name: string, - conf: object + conf: Types.ObjectId } export type UserModel = Document & { diff --git a/src/app/routes/routes.ts b/src/app/routes/routes.ts index cf83e24..7858340 100644 --- a/src/app/routes/routes.ts +++ b/src/app/routes/routes.ts @@ -1,6 +1,8 @@ import { Application } from "express" import { PassportStatic } from "passport" import * as Auth from './auth' +import ConfigDB from '../models/config.model' + export const init = (app: Application, passport: PassportStatic) => { app.get('/', async (req, res) => { @@ -10,15 +12,32 @@ export const init = (app: Application, passport: PassportStatic) => { }) app.put('/', async (req, res) => { - if (req.isAuthenticated() && req.user) { - req.user.configs.push({ - name: req.body.name, - conf: req.body.config + try { + const conf = new ConfigDB() + conf.json = req.body.config + conf.name = req.body.name + await conf.save() + + if (req.isAuthenticated() && req.user) { + req.user.configs.push({ + name: req.body.name, + conf: conf._id + }) + } + res.status(200).send(conf) + } catch (ex) { + res.status(500).send({ + error: ex }) + } + }) + + app.get('/configs/:id', async (req, res) => { + const conf = await ConfigDB.findById(req.params.id) + if (conf) { + res.json(conf.json) } else { - res.status(401).send({ - error: 'Not logged in!' - }) + res.status(404).end() } }) diff --git a/src/app/views/home copy.ejs b/src/app/views/home copy.ejs deleted file mode 100644 index 677fec2..0000000 --- a/src/app/views/home copy.ejs +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - Geolosys Configurator - - - - - - - - - - - - - - -
-
-
-

- -

-
-
- -
-
Config Name (For Saving)
- - - -
Deposit Type
- -
- -
- -
Deposit Structure Type (1.14+ Only)
- -
- -
- -
Ore Blocks
-
- -
Sample Blocks
-
- -
Minimum Y-Level
- - - -
Maximum Y-Level
- - - -
Chance (Relative to All - Chances) -
- - - -
Size
- - - -
Density
- - - -
Dimension Blacklist
- -
- -
Blocks that This Deposit Can Replace
- -
- -
Biomes To Spawn / Not Spawn
- -
- - - -
-
- -
-
- - - \ No newline at end of file diff --git a/src/app/views/home.ejs b/src/app/views/home.ejs index b5f7cbf..bd8cc09 100644 --- a/src/app/views/home.ejs +++ b/src/app/views/home.ejs @@ -105,6 +105,30 @@ Source Code Hosted on GitHub + + + + + \ No newline at end of file diff --git a/src/app/views/login.ejs b/src/app/views/login.ejs index 90736b7..d928c88 100644 --- a/src/app/views/login.ejs +++ b/src/app/views/login.ejs @@ -39,7 +39,7 @@ -