diff --git a/public/index.html b/public/index.html
new file mode 100644
index 0000000..a9d09dd
--- /dev/null
+++ b/public/index.html
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+ Index
+
+
+
+ Hi
+
+
+
\ No newline at end of file
diff --git a/public/list.html b/public/list.html
new file mode 100644
index 0000000..55ef341
--- /dev/null
+++ b/public/list.html
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+ list
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/upload.html b/public/upload.html
new file mode 100644
index 0000000..850b5b3
--- /dev/null
+++ b/public/upload.html
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+ File upload
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/auth.ts b/src/auth.ts
index 5b730f2..61ba49d 100644
--- a/src/auth.ts
+++ b/src/auth.ts
@@ -28,13 +28,12 @@ export function run(app) {
authorization: `${postRes.data.token_type} ${postRes.data.access_token}`
}
});
-
- res.send(`hi ${userInfo.data.username}#${userInfo.data.discriminator}`);
+ res.send(`hi ${userInfo.data.username}#${userInfo.data.discriminator}
`);
} catch(err) {
res.send(`whoooops
${err}`);
}
} else {
- res.send('https://discord.com/api/oauth2/authorize?client_id=750952563079250012&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fdiscordauth&response_type=code&scope=identify');
+ res.send(`Click here!!`);
}
});
}
\ No newline at end of file
diff --git a/src/html/upload.html b/src/html/upload.html
deleted file mode 100644
index e118003..0000000
--- a/src/html/upload.html
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
- file upload
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index f3a01a0..d58c801 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -53,6 +53,8 @@ db.then(() => {
// @ts-ignore
app.use(express.urlencoded({extended: true}));
app.use(fileUpload({limits: { fileSize: 50 * 1024 * 1024 }}));
+ app.use(express.static('public', {extensions: ['html', 'htm']}));
+ app.use('/assets', express.static('assets'));
app.set('db', db);
app.set('config', config);
@@ -61,22 +63,12 @@ db.then(() => {
upload.run(app);
auth.run(app);
- app.get('/list', async (req, res) => { // only for testing
+ app.get('/api/list', async (req, res) => { // only for testing
const docs = await File.find({});
-
- res.send(docs.map((doc: any) =>
- `${doc.artist} - ${doc.title} by ${doc.credit}
` +
- doc.charts.map(ch =>
- `- ${ch.difficulty} ${ch.rating}: ${ch.name}`
- ).join('
')
- ).join('
'));
+ // TODO: filter out _id and __v? possibly more
+ res.send(docs);
});
- app.get('/', (req, res) => {
- res.send('wip');
- });
-
-
app.get('*', (req, res) => {
res.status(404).send('404');
});
diff --git a/src/upload.ts b/src/upload.ts
index d8b94c6..e916f9f 100644
--- a/src/upload.ts
+++ b/src/upload.ts
@@ -8,12 +8,12 @@ import { File } from './schema';
export function run(app) {
const logger = app.get('logger');
-
- app.get('/upload', returnStatic('upload.html'));
- app.post('/upload', async (req, res) => { // only for testing, very abusable
+ app.post('/api/upload', async (req, res) => { // only for testing, very abusable
+ if (!req.files) return res.status(400).send('No files were given');
const file = req.files.file;
- if (file.mimetype !== 'application/zip') return res.status(400).send('Invalid filetype');
+
+ if (file.mimetype !== 'application/zip' && file.mimetype !== 'application/x-zip-compressed') return res.status(400).send('Invalid filetype');
const dir = tmpdir() + '/' + file.md5;
fs.writeFile(dir, file.data, (err) => {
@@ -40,7 +40,8 @@ export function run(app) {
const file = new File(chart);
file.save();
- res.send(`your file "${chart.artist} - ${chart.title}" has been uploaded! check the listing`); // todo: change to actual url
+ // TODO: filter out _id and __v? possibly more
+ res.send(chart);
}
zip.close();