From 24c127178be96f78f036bad6150b777c2f54c9b0 Mon Sep 17 00:00:00 2001 From: oat Date: Wed, 2 Sep 2020 17:13:26 +0300 Subject: [PATCH] basic file "uploading" and listing --- package-lock.json | 5 +++++ package.json | 1 + src/index.ts | 21 +++++++++++++++++++-- src/schema.ts | 28 ++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/schema.ts diff --git a/package-lock.json b/package-lock.json index 6d3c919..31b81dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index f5d3b9f..9dbe388 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/index.ts b/src/index.ts index 4041f5d..660b9ee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'); }); diff --git a/src/schema.ts b/src/schema.ts new file mode 100644 index 0000000..b4c8bd8 --- /dev/null +++ b/src/schema.ts @@ -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); \ No newline at end of file