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

601
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

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

View file

@ -18,13 +18,18 @@
const el = document.getElementById('doc-list'); const el = document.getElementById('doc-list');
for (const doc of data) { for (const doc of data) {
let p = document.createElement('p'); 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); el.insertAdjacentElement('beforeend', p);
let charts = document.createElement('ul'); let charts = document.createElement('ul');
for (const chart of doc.charts) { for (const chart of doc.charts) {
let l = document.createElement('li'); 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` `${chart.steps} steps, ${chart.mines} mines, ${chart.jumps} jumps, ${chart.hands} hands, ${chart.holds} holds, ${chart.rolls} rolls`
charts.insertAdjacentElement('beforeend', l); charts.insertAdjacentElement('beforeend', l);
} }

View file

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

View file

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