pull/12/head
tycrek 4 years ago
parent b1ad57377d
commit a62a9bf49f
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -2,6 +2,7 @@ require('dotenv').config();
const fs = require('fs-extra'); const fs = require('fs-extra');
const uuid = require('uuid').v4; const uuid = require('uuid').v4;
const express = require('express'); const express = require('express');
const useragent = require('express-useragent');
const multer = require('multer'); const multer = require('multer');
const zws = require('./zws'); const zws = require('./zws');
const { path, saveData, log, verify } = require('./utils'); const { path, saveData, log, verify } = require('./utils');
@ -46,6 +47,8 @@ function preStartup() {
} }
function startup() { function startup() {
app.use(useragent.express());
// Upload file // Upload file
app.post('/', upload.single('file'), (req, res) => { app.post('/', upload.single('file'), (req, res) => {
if (!verify(req, tokens)) return res.sendStatus(401); if (!verify(req, tokens)) return res.sendStatus(401);
@ -62,6 +65,7 @@ function startup() {
// View file // View file
app.get('/:resourceId', (req, res) => { app.get('/:resourceId', (req, res) => {
log(req.useragent);
let resourceId = req.params.resourceId.split('.')[0]; let resourceId = req.params.resourceId.split('.')[0];
if (data[resourceId] && data[resourceId].mimetype == 'video/mp4' && req.params.resourceId.split('.')[1] != 'mp4') return res.redirect(req.url + '.mp4'); if (data[resourceId] && data[resourceId].mimetype == 'video/mp4' && req.params.resourceId.split('.')[1] != 'mp4') return res.redirect(req.url + '.mp4');
let fileData = fs.readFileSync(path(data[resourceId].path)); let fileData = fs.readFileSync(path(data[resourceId].path));

14
package-lock.json generated

@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-useragent": "^1.0.15",
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
"multer": "^1.4.2", "multer": "^1.4.2",
"uuid": "^8.3.2" "uuid": "^8.3.2"
@ -275,6 +276,14 @@
"node": ">= 0.10.0" "node": ">= 0.10.0"
} }
}, },
"node_modules/express-useragent": {
"version": "1.0.15",
"resolved": "https://registry.npmjs.org/express-useragent/-/express-useragent-1.0.15.tgz",
"integrity": "sha512-eq5xMiYCYwFPoekffMjvEIk+NWdlQY9Y38OsTyl13IvA728vKT+q/CSERYWzcw93HGBJcIqMIsZC5CZGARPVdg==",
"engines": {
"node": ">=4.5"
}
},
"node_modules/finalhandler": { "node_modules/finalhandler": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
@ -943,6 +952,11 @@
"vary": "~1.1.2" "vary": "~1.1.2"
} }
}, },
"express-useragent": {
"version": "1.0.15",
"resolved": "https://registry.npmjs.org/express-useragent/-/express-useragent-1.0.15.tgz",
"integrity": "sha512-eq5xMiYCYwFPoekffMjvEIk+NWdlQY9Y38OsTyl13IvA728vKT+q/CSERYWzcw93HGBJcIqMIsZC5CZGARPVdg=="
},
"finalhandler": { "finalhandler": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",

@ -24,6 +24,7 @@
"dependencies": { "dependencies": {
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-useragent": "^1.0.15",
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
"multer": "^1.4.2", "multer": "^1.4.2",
"uuid": "^8.3.2" "uuid": "^8.3.2"

Loading…
Cancel
Save