forked from oat/in-the-database-2
		
	basic file "uploading" and listing
This commit is contained in:
		
							parent
							
								
									1eebe45e4e
								
							
						
					
					
						commit
						24c127178b
					
				
					 4 changed files with 53 additions and 2 deletions
				
			
		
							
								
								
									
										21
									
								
								src/index.ts
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								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'); | ||||
| 	}); | ||||
|  |  | |||
							
								
								
									
										28
									
								
								src/schema.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/schema.ts
									
										
									
									
									
										Normal 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); | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue