From 003a5983079d1c74cb7c25b91cb18adf4dec2606 Mon Sep 17 00:00:00 2001 From: oat Date: Wed, 2 Sep 2020 17:37:36 +0300 Subject: [PATCH 1/3] upload is no longer "upload" --- src/html/upload.html | 16 ++++++++++++++++ src/index.ts | 20 ++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 src/html/upload.html diff --git a/src/html/upload.html b/src/html/upload.html new file mode 100644 index 0000000..8670e9e --- /dev/null +++ b/src/html/upload.html @@ -0,0 +1,16 @@ + + + file upload + + +
+
+
+
+
+
+
+ +
+ + \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index ec12a8c..1c42f95 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,6 +37,15 @@ 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!'); @@ -49,14 +58,13 @@ db.then(() => { 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 From 7121c06d7be2233c830643a0fd52cdaea2a6c17b Mon Sep 17 00:00:00 2001 From: oat Date: Wed, 2 Sep 2020 17:40:24 +0300 Subject: [PATCH 2/3] add translit titles artists and subtitles --- src/schema.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/schema.ts b/src/schema.ts index b4c8bd8..d49d34d 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -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, From 46f2168fe53b4357cd37cd2d63e8336aeb42a886 Mon Sep 17 00:00:00 2001 From: oat Date: Wed, 2 Sep 2020 17:44:44 +0300 Subject: [PATCH 3/3] how did i live without types --- package-lock.json | 57 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 ++ src/index.ts | 10 +++++---- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 31b81dd..bbed7f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 9dbe388..804b78b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 1c42f95..0596a04 100644 --- a/src/index.ts +++ b/src/index.ts @@ -52,7 +52,8 @@ db.then(() => { 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); @@ -68,15 +69,16 @@ db.then(() => { }); 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) => {