This commit is contained in:
oat 2020-12-26 23:03:34 +03:00
parent 4cbe252852
commit 564d71c48f
Signed by: oat
GPG key ID: DD83A9617A252385
7 changed files with 349 additions and 300 deletions

BIN
assets/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

605
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -12,24 +12,25 @@
"license": "MIT",
"dependencies": {
"@types/express": "github:types/express",
"@types/mongoose": "^5.7.36",
"@types/mongoose": "^5.10.3",
"axios": "^0.20.0",
"connect-mongo": "^3.2.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-fileupload": "^1.2.0",
"express-session": "^1.17.1",
"mongoose": "^5.10.2",
"mongoose": "^5.11.8",
"mongoose-int32": "^0.4.1",
"node-stream-zip": "^1.11.3",
"typescript": "^4.0.2",
"uuid": "^8.3.1",
"node-stream-zip": "^1.12.0",
"serve-favicon": "^2.5.0",
"typescript": "^4.1.3",
"uuid": "^8.3.2",
"winston": "^3.3.3"
},
"devDependencies": {
"@types/express-session": "^1.17.0",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"eslint": "^7.8.1"
"@types/express-session": "^1.17.3",
"@typescript-eslint/eslint-plugin": "^4.11.0",
"@typescript-eslint/parser": "^4.11.0",
"eslint": "^7.16.0"
}
}

View file

@ -18,13 +18,18 @@
const el = document.getElementById('doc-list');
for (const doc of data) {
let p = document.createElement('p');
p.innerHTML = `${doc.artist} - ${doc.title} by ${doc.credit}\nuploaded by ${doc.uploader} ${doc.uploaderJSON.username}#${doc.uploaderJSON.discriminator}\n<a href="files/${doc.id}.zip">download</a>`;
p.innerHTML = `<b>${doc.artist} - ${doc.title}</b> by ${doc.credit}\nuploaded by ${doc.uploaderJSON.username}#${doc.uploaderJSON.discriminator}\n<a href="files/${doc.id}.zip">download</a>`;
if (doc.editable) {
p.innerHTML += ` <a href="../${doc.id}/edit">edit</a>`
}
el.insertAdjacentElement('beforeend', p);
let charts = document.createElement('ul');
for (const chart of doc.charts) {
let l = document.createElement('li');
l.innerText = `${chart.difficulty} ${chart.rating} - ${chart.name}\n` +
l.innerHTML = `${chart.difficulty} ${chart.rating} - <b>${chart.name}</b><br>` +
`${chart.steps} steps, ${chart.mines} mines, ${chart.jumps} jumps, ${chart.hands} hands, ${chart.holds} holds, ${chart.rolls} rolls`
charts.insertAdjacentElement('beforeend', l);
}

View file

@ -4,6 +4,7 @@ import * as fs from 'fs';
import * as winston from 'winston';
import * as fileUpload from 'express-fileupload';
import * as session from 'express-session';
import * as favicon from 'serve-favicon';
const MongoStore = require('connect-mongo')(session);
import * as format from './lib/format';
@ -54,6 +55,7 @@ db.then(() => {
// @ts-ignore
app.use(express.urlencoded({extended: true}));
app.use(favicon('assets/icon.ico'));
app.use(fileUpload({limits: { fileSize: 50 * 1024 * 1024 }}));
app.use(express.static('public', {extensions: ['html', 'htm']}));
app.use(express.static('storage', {extensions: ['zip']}));
@ -78,12 +80,16 @@ db.then(() => {
upload.run(app);
auth.run(app);
app.get('/api/list', async (req, res) => { // only for testing
app.get('/api/list', async (req, res) => {
const files = await File.find({});
const docs = [];
for (const doc of files) {
const d = doc.toJSON();
const d: any = doc.toJSON();
d.editable = false;
if (req.session) d.editable = req.session.uuid === d.uploader;
const user = await User.find({uuid: d.uploader});
if (user) {
d.uploaderJSON = user[0].toJSON(); // this is built upon 20 layers of metajank and i despise it

View file

@ -53,7 +53,7 @@ export function parseSM(data: string) {
const map = {};
for (const i in keys) {
map[Number(keys[i])] = Number(values[i]); // afaik maps are only numbers?
map[String(Number(keys[i])).replace('.', ',')] = Number(values[i]); // afaik maps are only numbers?
}
value = map;

View file

@ -44,7 +44,7 @@ export function run(app) {
let id = 0;
for (const f of await File.find({})) {
id = Math.max(f.id, id);
id = Math.max(Number(f.id), id);
}
chart.id = id + 1;