File rearrange

This commit is contained in:
MrFry 2020-01-23 09:48:55 +01:00
parent 1f9206f95b
commit 5530f03fac
22 changed files with 5 additions and 1789 deletions

View file

@ -1,69 +0,0 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
let url = '' // http(s)//asd.basd
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
const app = express()
const logger = require('../utils/logger.js')
// const utils = require('../utils/utils.js')
// const actions = require('../utils/actions.js')
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(busboy({
limits: {
fileSize: 10000 * 1024 * 1024
}
}))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
limit: '5mb',
extended: true
}))
app.use(bodyParser.json({
limit: '5mb'
}))
// --------------------------------------------------------------
app.get('/', function (req, res) {
res.render('main/main', {
siteurl: url
})
})
app.get('*', function (req, res) {
res.status(404).render('shared/404')
})
app.post('*', function (req, res) {
res.status(404).render('shared/404')
})
exports.app = app
exports.setup = (x) => {
url = x.url
}
logger.Log('Main module started', logger.GetColor('yellow'))

View file

@ -1,46 +0,0 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
let url = ''
const express = require('express')
const app = express()
const logger = require('../utils/logger.js')
// --------------------------------------------------------------
app.get('/', function (req, res) {
res.redirect(url + req.url)
})
app.get('*', function (req, res) {
res.redirect(url + req.url)
})
app.post('*', function (req, res) {
res.redirect(url + req.url)
})
exports.app = app
exports.setup = (x) => {
url = x.url
}
logger.Log('Old module started', logger.GetColor('yellow'))

View file

@ -1,238 +0,0 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
let url = ''
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
const fs = require('fs')
const app = express()
// const http = require('http')
// const https = require('https')
const logger = require('../utils/logger.js')
const utils = require('../utils/utils.js')
const actions = require('../utils/actions.js')
const recivedFiles = 'public/recivedfiles'
const uloadFiles = 'public/f'
const dataFile = 'public/data.json'
const msgFile = 'stats/msgs'
const motdFile = 'public/motd'
let donateURL = ''
try {
donateURL = utils.ReadFile('./data/donateURL')
} catch (e) {
logger.Log('Couldnt read donate URL file!', logger.GetColor('red'))
}
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(busboy({
limits: {
fileSize: 10000 * 1024 * 1024
}
}))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
limit: '5mb',
extended: true
}))
app.use(bodyParser.json({
limit: '5mb'
}))
// --------------------------------------------------------------
app.get('/', function (req, res) {
// req.hostname
let motd = ''
try {
motd = utils.ReadFile(motdFile)
} catch (e) {
}
res.render('qmining/main', {
siteurl: url,
qa: actions.ProcessQA(),
motd: motd
})
res.end()
})
app.get('/manual', function (req, res) {
res.render('qmining/man')
res.end()
logger.LogReq(req)
})
app.get('/legacy', function (req, res) {
var f = utils.ReadFile(dataFile)
var d = actions.LoadJSON(f)
let qcount = 0
for (let i = 0; i < d.length; i++) { qcount += d.Subjects[i].length }
let scount = d.length
res.render('qmining/alldata', {
data: d,
scount: scount,
qcount: qcount,
siteurl: url
})
logger.LogReq(req)
})
app.post('/postfeedback', function (req, res) {
res.redirect('back')
logger.Log('New feedback message', logger.GetColor('bluebg'), true)
utils.AppendToFile('\n\n' + logger.GetDateString() + ': ' + req.body.message_field, msgFile)
})
app.get('/postfeedback', function (req, res) {
res.redirect('/')
})
app.post('/isAdding', function (req, res) {
res.end('OK')
logger.LogReq(req)
actions.ProcessIncomingRequest(req.body.datatoadd)
utils.WriteBackup()
})
app.get('/lred', function (req, res) {
res.redirect('/legacy')
res.end()
logger.LogReq(req)
})
app.get('/menuClick', function (req, res) {
res.redirect('/')
res.end()
logger.LogReq(req)
})
// all questions readable
app.get('/allqr', function (req, res) {
var f = utils.ReadFile(dataFile)
var d = actions.LoadJSON(f)
res.render('qmining/allqr', {
d: d.toString().split('\n')
})
logger.LogReq(req)
})
app.get('/greasy', function (req, res) {
res.redirect('https://greasyfork.org/en/scripts/38999-moodle-elearning-kmooc-test-help')
res.end()
logger.LogReq(req)
})
app.get('/install', function (req, res) {
res.redirect(url + '/moodle-test-userscript/stable.user.js?install')
res.end()
logger.LogReq(req)
})
app.get('/donate', function (req, res) {
res.redirect(donateURL)
res.end()
logger.LogReq(req)
})
app.get('/thanks', function (req, res) {
res.render('qmining/thanks', {
siteurl: url
})
res.end()
logger.LogReq(req)
})
app.get('/classesgit', function (req, res) {
res.redirect('https://gitlab.com/MrFry/question-classes')
res.end()
logger.LogReq(req)
})
app.get('/scriptgit', function (req, res) {
res.redirect('https://gitlab.com/MrFry/moodle-test-userscript')
res.end()
logger.LogReq(req)
})
app.get('/servergit', function (req, res) {
res.redirect('https://gitlab.com/MrFry/mrfrys-node-server')
res.end()
logger.LogReq(req)
})
function UploadFile (req, res, path, next) {
var fstream
req.pipe(req.busboy)
req.busboy.on('file', function (fieldname, file, filename) {
logger.Log('Uploading: ' + filename, logger.GetColor('blue'))
utils.CreatePath(path, true)
let d = new Date()
let fn = d.getHours() + '' + d.getMinutes() + '' + d.getSeconds() + '_' + filename
fstream = fs.createWriteStream(path + '/' + fn)
file.pipe(fstream)
fstream.on('close', function () {
logger.Log('Upload Finished of ' + path + '/' + fn, logger.GetColor('blue'))
next(fn)
})
fstream.on('error', function (err) {
console.log(err)
res.end('something bad happened :s')
})
})
}
app.route('/fosuploader').post(function (req, res, next) {
UploadFile(req, res, uloadFiles, (fn) => {
res.redirect('/f/' + fn)
})
})
app.route('/badtestsender').post(function (req, res, next) {
UploadFile(req, res, recivedFiles, (fn) => {
res.render('qmining/uploaded')
})
logger.LogReq(req)
})
app.get('*', function (req, res) {
res.status(404).render('shared/404')
})
app.post('*', function (req, res) {
res.status(404).render('shared/404')
})
exports.app = app
exports.setup = (x) => {
url = x.url
}
logger.Log('Qmining module started', logger.GetColor('yellow'))

View file

@ -1,95 +0,0 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
const fs = require('fs')
const app = express()
// const http = require('http')
// const https = require('https')
const logger = require('../utils/logger.js')
const utils = require('../utils/utils.js')
const uloadFiles = './public/f'
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(busboy({
limits: {
fileSize: 10000 * 1024 * 1024
}
}))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
limit: '5mb',
extended: true
}))
app.use(bodyParser.json({
limit: '5mb'
}))
// --------------------------------------------------------------
app.get('/', function (req, res) {
res.render('sio/uload')
res.end()
})
function UploadFile (req, res, path, next) {
var fstream
req.pipe(req.busboy)
req.busboy.on('file', function (fieldname, file, filename) {
logger.Log('Uploading: ' + filename, logger.GetColor('blue'))
utils.CreatePath(path, true)
let d = new Date()
let fn = d.getHours() + '' + d.getMinutes() + '' + d.getSeconds() + '_' + filename
fstream = fs.createWriteStream(path + '/' + fn)
file.pipe(fstream)
fstream.on('close', function () {
logger.Log('Upload Finished of ' + path + '/' + fn, logger.GetColor('blue'))
next(fn)
})
fstream.on('error', function (err) {
console.log(err)
res.end('something bad happened :s')
})
})
}
app.route('/fosuploader').post(function (req, res, next) {
UploadFile(req, res, uloadFiles, (fn) => {
res.redirect('/f/' + fn)
})
})
app.get('*', function (req, res) {
res.status(404).render('shared/404')
})
app.post('*', function (req, res) {
res.status(404).render('shared/404')
})
exports.app = app
logger.Log('Sio module started', logger.GetColor('yellow'))

View file

@ -1,208 +0,0 @@
/* ----------------------------------------------------------------------------
Question Server
GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
const fs = require('fs')
const app = express()
let url = ''
const logger = require('../utils/logger.js')
// const utils = require('../utils/utils.js')
// const actions = require('../utils/actions.js')
const listedFiles = './public/files'
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.use(busboy({
limits: {
fileSize: 10000 * 1024 * 1024
}
}))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
limit: '5mb',
extended: true
}))
app.use(bodyParser.json({
limit: '5mb'
}))
// --------------------------------------------------------------
// app, '/*.mp4', 'video/mp4', 'stuff/video'
function appGetFileType (app, wildcard, contentType, pageToRender) {
app.get(wildcard, function (req, res) {
let p = decodeURI(req.url)
let fp = p
if (p.includes('?')) {
fp = p.split('?')
fp.pop()
fp = fp.join('/')
}
const fpath = './public/files' + fp
if (!fs.existsSync(fpath)) {
res.render('stuff/nofile', {
missingFile: fpath,
url
})
return
}
if (req.query.stream || !pageToRender) {
const stat = fs.statSync(fpath)
const fileSize = stat.size
const range = req.headers.range
if (range) {
const parts = range.replace(/bytes=/, '').split('-')
const start = parseInt(parts[0], 10)
const end = parts[1]
? parseInt(parts[1], 10)
: fileSize - 1
const chunksize = (end - start) + 1
const file = fs.createReadStream(fpath, { start, end })
const head = {
'Content-Range': `bytes ${start}-${end}/${fileSize}`,
'Accept-Ranges': 'bytes',
'Content-Length': chunksize,
'Content-Type': contentType
}
res.writeHead(206, head)
file.pipe(res)
} else {
const head = {
'Content-Length': fileSize,
'Content-Type': contentType
}
res.writeHead(200, head)
fs.createReadStream(fpath).pipe(res)
}
} else {
logger.LogReq(req)
let fname = fpath.split('/')
fname = fname.pop()
res.render(pageToRender, {
path: fp,
fname,
url,
contentType,
albumArt: GetAlbumArt(p)
})
}
})
}
const fileTypes = [
['/*.mp4', 'video/mp4', 'stuff/video'],
['/*.mkv', 'audio/x-matroska', 'stuff/video'],
['/*.mp3', 'audio/mpeg', 'stuff/audio'],
['/*.pdf', 'application/pdf'],
['/*.zip', 'application/zip']
]
function GetAlbumArt (path) {
let tmp = path.split('.')
tmp.pop()
tmp = tmp.join('.').split('/')
let last = tmp.pop()
return tmp.join('/') + '/.' + last + '.png'
}
fileTypes.forEach((t) => {
appGetFileType(app, t[0], t[1], t[2])
})
app.get('/*', function (req, res) {
let parsedUrl = decodeURI(req.url)
let curr = listedFiles + '/' + parsedUrl.substring('/'.length, parsedUrl.length).split('?')[0]
let relPath = curr.substring('./public/files'.length, curr.length)
if (relPath[relPath.length - 1] !== '/') { relPath += '/' }
let t = relPath.split('/')
let prevDir = ''
for (let i = 0; i < t.length - 2; i++) { prevDir += t[i] + '/' }
// curr = curr.replace(/\//g, "/");
// relPath = relPath.replace(/\//g, "/");
logger.LogReq(req)
try {
if (fs.lstatSync(curr).isDirectory()) {
if (curr[curr.length - 1] !== '/') { curr += '/' }
let f = []
fs.readdirSync(curr).forEach((item) => {
if (item[0] !== '.') {
let res = { name: item }
let stat = fs.statSync(curr + '/' + item)
let fileSizeInBytes = stat['size']
res.size = Math.round(fileSizeInBytes / 1000000)
res.path = relPath
if (res.path[res.path.length - 1] !== '/') { res.path += '/' }
res.path += item
res.mtime = stat['mtime'].toLocaleString()
res.isDir = stat.isDirectory()
f.push(res)
}
})
res.render('stuff/folders', {
folders: f,
dirname: relPath,
prevDir,
url
})
} else {
let fileStream = fs.createReadStream(curr)
fileStream.pipe(res)
}
} catch (e) {
res.render('stuff/nofile', {
missingFile: curr,
url
})
}
})
// -----------------------------------------------------------------------------------------------
app.get('*', function (req, res) {
res.status(404).render('shared/404')
})
app.post('*', function (req, res) {
res.status(404).render('shared/404')
})
exports.app = app
exports.setup = (x) => {
url = x.url
}
logger.Log('Stuff module started', logger.GetColor('yellow'))