user checking when user uploads

This commit is contained in:
oat 2020-10-12 03:39:44 +03:00
parent 795f983721
commit ef58af8a9a
Signed by: oat
GPG key ID: DD83A9617A252385

View file

@ -3,14 +3,18 @@ import * as fs from 'fs';
const StreamZip = require('node-stream-zip'); const StreamZip = require('node-stream-zip');
import { parseSM } from './lib/smparse'; import { parseSM } from './lib/smparse';
import { File } from './schema'; import { File, User } from './schema';
export function run(app) { export function run(app) {
const logger = app.get('logger'); const logger = app.get('logger');
app.post('/api/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'); if (!req.files) return res.status(400).send('No files were given');
if (!req.session.uuid) return res.status(401).send('Not authorized'); if (!req.session.uuid) return res.status(401).send('Not authorized, use /discordauth');
const user = (await User.find({uuid: req.session.uuid}))[0];
if (!user) return res.status(401).send('User doesn\'t exist, try re-logging in');
if (!user.get('approvedUpload')) return res.status(403).send('Your account is not allowed to upload files! Contact a moderator to verify your account');
const file = req.files.file; const file = req.files.file;