basic file "uploading" and listing

This commit is contained in:
oat 2020-09-02 17:13:26 +03:00
parent 1eebe45e4e
commit 24c127178b
Signed by untrusted user who does not match committer: oat
GPG Key ID: DD83A9617A252385
4 changed files with 53 additions and 2 deletions

5
package-lock.json generated
View File

@ -1365,6 +1365,11 @@
}
}
},
"mongoose-int32": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/mongoose-int32/-/mongoose-int32-0.4.1.tgz",
"integrity": "sha512-8ymH8hAmVDYxngNwI3Te9KnPGzlf0hI5wgRp3R8soAftuvSg4d/IZkHcSz9b84giPiiRhyvPgtasUiWqAWVQAQ=="
},
"mongoose-legacy-pluralize": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz",

View File

@ -13,6 +13,7 @@
"dependencies": {
"express": "^4.17.1",
"mongoose": "^5.10.2",
"mongoose-int32": "^0.4.1",
"typescript": "^4.0.2",
"winston": "^3.3.3"
},

View File

@ -4,6 +4,7 @@ import * as fs from 'fs';
import * as winston from 'winston';
import * as format from './lib/format';
import { File } from './schema';
const config = JSON.parse(fs.readFileSync('./config/config.json', {encoding: 'utf8'}));
@ -48,10 +49,26 @@ db.then(() => {
app.set('config', config);
app.set('logger', logger);
app.get('/', (req, res) => {
res.send(`${config.name} homepage - unfinished`);
app.get('/upload', (req, res) => { // only for testing, very abusable
const file = new File({
title: 'penis', // look how mature i am
artist: 'cock'
});
file.save();
res.send('made and saved a sample file');
});
app.get('/list', async (req, res) => { // only for testing
const docs = await File.find({});
res.send(JSON.stringify(docs));
});
app.get('/', (req, res) => {
res.send('wip');
});
app.get('*', (req, res) => {
res.status(404).send('404');
});

28
src/schema.ts Normal file
View File

@ -0,0 +1,28 @@
import * as mongoose from 'mongoose';
const Schema = mongoose.Schema;
const Int32 = require('mongoose-int32');
const Sample = new Schema({
start: {type: Int32, default: new Int32(0)},
length: {type: Int32, default: new Int32(0)}
});
const Chart = new Schema({
name: {type: String, default: ''},
rating: {type: Int32, default: new Int32(0)},
type: {type: String, default: 'Challenge'}
});
const FileSchema = new Schema({
title: {type: String, default: 'unknown'},
artist: {type: String, default: 'unknown'},
subtitle: String,
credit: String,
uploader: {type: String, default: '00000000-0000-4000-a000-000000000000'},
sample: Sample,
bpms: {type: [Number], default: 0},
charts: [Chart]
});
export const File = mongoose.model('File', FileSchema);