File uploading, other tweaks.
This commit is contained in:
parent
7b6328809b
commit
3f461319b3
7 changed files with 102 additions and 180 deletions
13
src/app/models/config.model.ts
Normal file
13
src/app/models/config.model.ts
Normal file
|
|
@ -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<ConfigModel>('configs', ConfigSchema, 'configs')
|
||||
|
|
@ -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 & {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -1,158 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Geolosys Configurator</title>
|
||||
|
||||
<link rel="shortcut icon" href="/assets/img/logo.png" type="image/x-icon">
|
||||
|
||||
<link rel="stylesheet" href="/Libraries/font-awesome/css/all.min.css">
|
||||
<link rel="stylesheet" href="/Libraries/bootstrap/css/bootstrap.css">
|
||||
<script src="/Libraries/bootstrap/js/bootstrap.bundle.min.js"></script>
|
||||
<script type="module" src="/assets/js/modules/events.module.js"></script>
|
||||
<script type="module" src="/assets/js/modules/generators.module.js"></script>
|
||||
<!-- <script src="/assets/js/home.js"></script> -->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<div class="container-fluid">
|
||||
<a href="/" class="navbar-brand">
|
||||
<span>
|
||||
<img width="24" src="/assets/img/logo.png"> Configurator
|
||||
</span>
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a href="#" class="nav-link active">
|
||||
<span>
|
||||
<i class="far fa-plus-square"></i> Create
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<% if(user) {%>
|
||||
<li class="nav-item">
|
||||
<a href="/configs" class="nav-link">
|
||||
<span>
|
||||
<b>{ }</b> Your Configs
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<% } %>
|
||||
<li class="nav-item">
|
||||
<% if(user) {%>
|
||||
<a href="/logout" class="nav-link">
|
||||
<span>
|
||||
<i class="fas fa-sign-out-alt"></i> Log Out
|
||||
</span>
|
||||
</a>
|
||||
<% } else { %>
|
||||
<a href="/login" class="nav-link">
|
||||
<span>
|
||||
<i class="fas fa-sign-out-alt"></i> Log In
|
||||
</span>
|
||||
</a>
|
||||
<% } %>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="accordion" id="oreconfig">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2 class="mb-0">
|
||||
<button class="btn btn-link btn-block text-left" type="button" data-toggle="collapse"
|
||||
data-target="#config-1" aria-expanded="true" aria-controls="config-1">
|
||||
Config #1
|
||||
</button>
|
||||
</h2>
|
||||
</div>
|
||||
<div id="config-1" class="collapse show" aria-labelledby="headingOne" data-parent="#oreconfig">
|
||||
<!-- <div class="container" style="margin-top: 2rem;"> -->
|
||||
<form>
|
||||
<h6>Config Name (For Saving)</h6>
|
||||
|
||||
<input class="form-control mb-3" type="text" name="confName" id="confName">
|
||||
|
||||
<h6>Deposit Type</h6>
|
||||
|
||||
<div class="mb-3">
|
||||
<select class="form-select" aria-label="Deposit Type" name="DepositType">
|
||||
<option value="deposit" selected>Normal</option>
|
||||
<option value="depositMulti">Multi-Ore</option>
|
||||
<option value="depositBiome">Biome Specific</option>
|
||||
<option value="depositBiomeMulti">Multi-Ore & Biome Specific</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<h6>Deposit Structure Type <b>(1.14+ Only)</b></h6>
|
||||
|
||||
<div class="mb-3">
|
||||
<select class="form-select" aria-label="Structure Type" name="StructureType">
|
||||
<option value="dense" selected>Dense</option>
|
||||
<option value="sparse">Sparse</option>
|
||||
<option value="dike">Dike</option>
|
||||
<option value="layer">Layer</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<h6>Ore Blocks</h6>
|
||||
<div id="blocks"></div>
|
||||
|
||||
<h6>Sample Blocks</h6>
|
||||
<div id="samples"></div>
|
||||
|
||||
<h6>Minimum Y-Level</h6>
|
||||
|
||||
<input class="form-control mb-3" type="number" value="0" min="0" max="255" name="yMin" id="yMin">
|
||||
|
||||
<h6>Maximum Y-Level</h6>
|
||||
|
||||
<input class="form-control mb-3" type="number" value="1" min="0" max="255" name="yMax" id="yMax">
|
||||
|
||||
<h6>Chance <a href="https://oitsjustjo.se/M3NfQxBsZ" target="_blank">(Relative to All
|
||||
Chances)</a>
|
||||
</h6>
|
||||
|
||||
<input class="form-control mb-3" type="number" value="1" min="0" name="chance" id="chance">
|
||||
|
||||
<h6>Size</h6>
|
||||
|
||||
<input class="form-control mb-3" type="text" name="confName" id="confName">
|
||||
|
||||
<h6>Density</h6>
|
||||
|
||||
<input class="form-control mb-3" type="text" name="confName" id="confName">
|
||||
|
||||
<h6>Dimension Blacklist</h6>
|
||||
|
||||
<div id="dimBlacklist"></div>
|
||||
|
||||
<h6>Blocks that This Deposit Can Replace</h6>
|
||||
|
||||
<div id="replacers"></div>
|
||||
|
||||
<h6>Biomes To Spawn / Not Spawn</h6>
|
||||
|
||||
<div id="biomes"></div>
|
||||
|
||||
|
||||
<button type="submit" class="btn btn-primary m-auto d-block">Generate!</button>
|
||||
</form>
|
||||
</div>
|
||||
<!-- </div> -->
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -105,6 +105,30 @@
|
|||
Source Code Hosted on
|
||||
<a href="https://github.com/oitsjustjose/geolosys-config-generator" target="_blank">GitHub</a>
|
||||
</h6>
|
||||
|
||||
|
||||
<div class="modal fade" tabindex="-1" id="notification">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
new bootstrap.Modal(document.getElementById('notification'));
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
</div>
|
||||
|
||||
|
||||
<div class="modal" tabindex="-1" id="notification">
|
||||
<div class="modal fade" tabindex="-1" id="notification">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const generateJSONListener = () => {
|
|||
const oreCfg = document.getElementById('oreconfig');
|
||||
const stoneCfg = document.getElementById('stoneconfig');
|
||||
|
||||
btn.addEventListener('click', () => {
|
||||
btn.addEventListener('click', async () => {
|
||||
btn.attributes.disabled = true;
|
||||
|
||||
let ores = Array();
|
||||
|
|
@ -32,18 +32,46 @@ const generateJSONListener = () => {
|
|||
return;
|
||||
}
|
||||
|
||||
console.log(ores);
|
||||
console.log(JSON.parse(
|
||||
const asJson = JSON.parse(
|
||||
JSON.stringify({
|
||||
"ores": ores
|
||||
})
|
||||
));
|
||||
);
|
||||
|
||||
console.log(asJson);
|
||||
|
||||
const resp = await fetch('/', {
|
||||
method: 'PUT',
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
name: '',
|
||||
config: asJson,
|
||||
})
|
||||
});
|
||||
|
||||
const newDoc = await resp.json();
|
||||
makeNotification('Config Upload Complete!', `
|
||||
<center>
|
||||
You can view your JSON at
|
||||
<br>
|
||||
<a href="${location.origin}/configs/${newDoc._id}">${location.origin}/configs/${newDoc._id}</a>
|
||||
</center>
|
||||
`);
|
||||
|
||||
// TODO: save this to the database!!!! If there's no name, name it some random ID maybe? /shrug
|
||||
btn.attributes.disabled = false;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const makeNotification = (title, contents) => {
|
||||
const modal = document.getElementById('notification');
|
||||
|
||||
modal.querySelector('.modal-title').innerHTML = title;
|
||||
modal.querySelector('.modal-body').innerHTML = contents;
|
||||
|
||||
new bootstrap.Modal.getInstance(modal).show();
|
||||
};
|
||||
|
||||
const parseForm = (form) => {
|
||||
let ore = {
|
||||
'blocks': Array(),
|
||||
|
|
@ -97,21 +125,17 @@ const parseForm = (form) => {
|
|||
}
|
||||
}
|
||||
|
||||
// console.log(ore);
|
||||
return ore;
|
||||
};
|
||||
|
||||
const parsed = (any) => {
|
||||
if (!any) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (isNaN(Number(any))) {
|
||||
} else if (isNaN(Number(any))) {
|
||||
return String(any);
|
||||
} else {
|
||||
return Number(any);
|
||||
}
|
||||
|
||||
return Number(any);
|
||||
};
|
||||
|
||||
const switch112Listener = () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue