|
|
@ -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));
|
|
|
|