Compare commits
3 commits
721497d02e
...
46f2168fe5
Author | SHA1 | Date | |
---|---|---|---|
|
46f2168fe5 | ||
|
7121c06d7b | ||
|
003a598307 |
5 changed files with 98 additions and 10 deletions
57
package-lock.json
generated
57
package-lock.json
generated
|
@ -114,18 +114,75 @@
|
|||
"fastq": "^1.6.0"
|
||||
}
|
||||
},
|
||||
"@types/bson": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/bson/-/bson-4.0.2.tgz",
|
||||
"integrity": "sha512-+uWmsejEHfmSjyyM/LkrP0orfE2m5Mx9Xel4tXNeqi1ldK5XMQcDsFkBmLDtuyKUbxj2jGDo0H240fbCRJZo7Q==",
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/color-name": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
||||
"integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/express": {
|
||||
"version": "github:types/express#7670cf1cbce96b3159e3ff04a253926b34111220",
|
||||
"from": "github:types/express",
|
||||
"requires": {
|
||||
"@types/serve-static": "github:types/npm-serve-static#c1f96843c8b96a37f6c534cb1dadb48f5329e4e0",
|
||||
"path-to-regexp": "github:pillarjs/path-to-regexp#ec285ed3500aed455df59e3b8b07f473412918a4"
|
||||
},
|
||||
"dependencies": {
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
|
||||
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
|
||||
},
|
||||
"path-to-regexp": {
|
||||
"version": "github:pillarjs/path-to-regexp#ec285ed3500aed455df59e3b8b07f473412918a4",
|
||||
"from": "github:pillarjs/path-to-regexp#ec285ed3500aed455df59e3b8b07f473412918a4",
|
||||
"requires": {
|
||||
"isarray": "0.0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@types/json-schema": {
|
||||
"version": "7.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.6.tgz",
|
||||
"integrity": "sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/mongodb": {
|
||||
"version": "3.5.26",
|
||||
"resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.5.26.tgz",
|
||||
"integrity": "sha512-p0X2VJgIBNHfNBdZdzzG8eQ/3bf6mQoXDT0UhVyVEdSzXEa1+2pFcwGvEZp72sjztyBwfRKlgrXMjCVavLcuGg==",
|
||||
"requires": {
|
||||
"@types/bson": "*",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/mongoose": {
|
||||
"version": "5.7.36",
|
||||
"resolved": "https://registry.npmjs.org/@types/mongoose/-/mongoose-5.7.36.tgz",
|
||||
"integrity": "sha512-ggFXgvkHgCNlT35B9d/heDYfSqOSwTmQjkRoR32sObGV5Xjd0N0WWuYlLzqeCg94j4hYN/OZxZ1VNNLltX/IVQ==",
|
||||
"requires": {
|
||||
"@types/mongodb": "*",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "14.6.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.6.2.tgz",
|
||||
"integrity": "sha512-onlIwbaeqvZyniGPfdw/TEhKIh79pz66L1q06WUQqJLnAb6wbjvOtepLYTGHTqzdXgBYIE3ZdmqHDGsRsbBz7A=="
|
||||
},
|
||||
"@types/serve-static": {
|
||||
"version": "github:types/npm-serve-static#c1f96843c8b96a37f6c534cb1dadb48f5329e4e0",
|
||||
"from": "github:types/npm-serve-static#c1f96843c8b96a37f6c534cb1dadb48f5329e4e0"
|
||||
},
|
||||
"@typescript-eslint/eslint-plugin": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.0.1.tgz",
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
"author": "oatmealine",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/express": "github:types/express",
|
||||
"@types/mongoose": "^5.7.36",
|
||||
"express": "^4.17.1",
|
||||
"mongoose": "^5.10.2",
|
||||
"mongoose-int32": "^0.4.1",
|
||||
|
|
16
src/html/upload.html
Normal file
16
src/html/upload.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>file upload</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/upload" method="post">
|
||||
<label for="title">Title: </label><br>
|
||||
<input type="text" id="title" name="title"><br>
|
||||
<label for="artist">Artist: </label><br>
|
||||
<input type="text" id="artist" name="artist"><br>
|
||||
<label for="credit">Credit: </label><br>
|
||||
<input type="text" id="credit" name="credit"><br>
|
||||
<input type="submit" value="upload">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
30
src/index.ts
30
src/index.ts
|
@ -37,38 +37,48 @@ const logger = winston.createLogger({
|
|||
]
|
||||
});
|
||||
|
||||
function returnStatic(page) {
|
||||
return (req, res) => {
|
||||
fs.readFile(`src/html/${page}`, 'utf8', (err, data) => {
|
||||
if (err) throw err;
|
||||
res.send(data);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
logger.info('connecting to mongodb database');
|
||||
db.then(() => {
|
||||
logger.info('connected to database!');
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
// @ts-ignore
|
||||
app.use(express.urlencoded({extended: true}));
|
||||
|
||||
app.set('db', db);
|
||||
app.set('config', config);
|
||||
app.set('logger', logger);
|
||||
|
||||
app.get('/upload', async (req, res) => { // only for testing, very abusable
|
||||
const file = new File({
|
||||
title: 'penis', // look how mature i am
|
||||
artist: 'cock'
|
||||
});
|
||||
app.get('/upload', returnStatic('upload.html'));
|
||||
|
||||
app.post('/upload', async (req, res) => { // only for testing, very abusable
|
||||
const file = new File(req.body);
|
||||
await file.save();
|
||||
|
||||
res.send('made and saved a sample file');
|
||||
res.send('uploaded file');
|
||||
});
|
||||
|
||||
app.get('/list', async (req, res) => { // only for testing
|
||||
let docs = await File.find({});
|
||||
docs = docs.map(d => {
|
||||
const docs = await File.find({});
|
||||
const map = docs.map(d => {
|
||||
const keys = Object.keys(d.toObject()).filter(k => !k.startsWith('_'));
|
||||
const obj = {};
|
||||
for (const key of keys) obj[key] = d[key];
|
||||
|
||||
return obj;
|
||||
});
|
||||
res.send(JSON.stringify(docs));
|
||||
|
||||
res.send(JSON.stringify(map));
|
||||
});
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
|
|
|
@ -16,8 +16,11 @@ const Chart = new Schema({
|
|||
|
||||
const FileSchema = new Schema({
|
||||
title: {type: String, default: 'unknown'},
|
||||
titleTranslit: String,
|
||||
artist: {type: String, default: 'unknown'},
|
||||
artistTranslit: String,
|
||||
subtitle: String,
|
||||
subtitleTranslit: String,
|
||||
credit: String,
|
||||
uploader: {type: String, default: '00000000-0000-4000-a000-000000000000'},
|
||||
sample: Sample,
|
||||
|
|
Loading…
Reference in a new issue