Lotsa typescript bullshit

This commit is contained in:
mrfry 2020-11-24 10:47:04 +01:00
parent b7ac485689
commit b927988017
65 changed files with 801 additions and 8447 deletions

View file

@ -22,17 +22,20 @@
import express from 'express'
import bodyParser from 'body-parser'
import busboy from 'connect-busboy'
import { uuidv4 } from 'uuid'
import { v4 as uuidv4 } from 'uuid'
import fs from 'fs'
// other requires
import logger from '../../utils/logger.js'
import utils from '../../utils/utils.js'
import logger from '../../utils/logger'
import utils from '../../utils/utils'
import actions from '../../utils/actions'
import dbtools from '../../utils/dbtools.js'
import auth from '../../middlewares/auth.middleware.js'
import { dataToString, searchData } from '../../utils/classes.js'
import dbtools from '../../utils/dbtools'
import auth from '../../middlewares/auth.middleware'
import { dataToString, searchData } from '../../utils/classes'
import { SetupData } from '../../server'
import { ModuleType, User } from '../../types/basicTypes'
// files
const msgFile = 'stats/msgs'
@ -64,7 +67,7 @@ export interface DataFile {
name: string
}
function GetApp() {
function GetApp(): ModuleType {
const app = express()
const publicDir = publicdirs[0]
@ -79,6 +82,7 @@ function GetApp() {
{ path: `${publicDir}oldData.json`, name: 'oldData' },
{ path: `${publicDir}data.json`, name: 'newData' },
]
const data: any = {} // TODO: remove
const motdFile = publicDir + 'motd'
const userSpecificMotdFile = publicDir + 'userSpecificMotd.json'
const versionFile = publicDir + 'version'
@ -124,10 +128,11 @@ function GetApp() {
)
const questionDbs = actions.LoadJSON(dataFiles)
const version = ''
const motd = ''
const userSpecificMotd = {}
const testUsers = []
let version = ''
let motd = ''
let userSpecificMotd = {}
// FIXME: check type from file
let testUsers: any = []
function mergeObjSum(a, b) {
const res = { ...b }
@ -226,7 +231,7 @@ function GetApp() {
// -------------------------------------------------------------
app.get('/updateTodo', (req, res) => {
app.get('/updateTodo', (req: any, res: any) => {
const userId = req.session.user.id
const id = req.query.id
const todos = utils.ReadJSON(todosFile)
@ -265,7 +270,7 @@ function GetApp() {
})
})
app.get('/todos', (req, res) => {
app.get('/todos', (req: any, res: any) => {
logger.LogReq(req)
const userId = req.session.user.id
const todos = utils.ReadJSON(todosFile)
@ -277,18 +282,18 @@ function GetApp() {
})
})
app.get('/ranklist', (req, res) => {
app.get('/ranklist', (req: any, res: any) => {
logger.LogReq(req)
let result
let since = req.query.since
const user = req.session.user
const user: User = req.session.user
if (!since) {
result = utils.ReadJSON(idStatFile)
} else {
try {
since = new Date(since)
if (!(since instanceof Date) || isNaN(since)) {
if (!(since instanceof Date) || isNaN(since.getTime())) {
throw new Error('Not a date')
}
const data = utils.ReadJSON(idvStatFile)
@ -354,10 +359,10 @@ function GetApp() {
})
})
app.get('/quickvote', (req, res) => {
app.get('/quickvote', (req: any, res: any) => {
const key = req.query.key
const val = req.query.val
const user = req.session.user
const user: User = req.session.user
if (!key || !val) {
res.render('votethank', {
@ -367,7 +372,8 @@ function GetApp() {
return
}
let votes = {}
// FIXME: check vote type in file
let votes: any = {}
if (utils.FileExists(quickVotes)) {
votes = utils.ReadJSON(quickVotes)
} else {
@ -429,10 +435,10 @@ function GetApp() {
utils.WriteFile(JSON.stringify(voteData), voteFile)
})
app.get('/avaiblePWS', (req, res) => {
app.get('/avaiblePWS', (req: any, res: any) => {
logger.LogReq(req)
const user = req.session.user
const user: User = req.session.user
res.json({
result: 'success',
@ -447,7 +453,7 @@ function GetApp() {
})
})
app.post('/getpw', function(req, res) {
app.post('/getpw', function(req: any, res: any) {
logger.LogReq(req)
const requestingUser = req.session.user
@ -497,7 +503,7 @@ function GetApp() {
})
})
app.post('/getveteranpw', function(req, res) {
app.post('/getveteranpw', function(req: any, res: any) {
logger.LogReq(req)
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
const tries = dbtools.Select(userDB, 'veteranPWRequests', {
@ -546,7 +552,7 @@ function GetApp() {
return
}
const user = dbtools.Select(userDB, 'users', {
const user: User = dbtools.Select(userDB, 'users', {
oldCID: oldUserID,
})[0]
@ -593,7 +599,7 @@ function GetApp() {
}
})
app.post('/login', (req, res) => {
app.post('/login', (req: any, res: any) => {
logger.LogReq(req)
const pw = req.body.pw
? req.body.pw
@ -604,7 +610,7 @@ function GetApp() {
const cid = req.body.cid
const isScript = req.body.script
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
const user = dbtools.Select(userDB, 'users', {
const user: User = dbtools.Select(userDB, 'users', {
pw: pw,
})[0]
@ -695,7 +701,7 @@ function GetApp() {
}
})
app.post('/logout', (req, res) => {
app.post('/logout', (req: any, res: any) => {
logger.LogReq(req)
const sessionID = req.cookies.sessionID
@ -711,38 +717,36 @@ function GetApp() {
// --------------------------------------------------------------
app.get('/', function(req, res) {
app.get('/', function(req: any, res: any) {
logger.LogReq(req)
res.redirect('https://www.youtube.com/watch?v=ieqGJgqiXFk')
})
app.post('/postfeedbackfile', function(req, res) {
app.post('/postfeedbackfile', function(req: any, res: any) {
UploadFile(req, res, uloadFiles, () => {
res.json({ success: true })
})
logger.LogReq(req)
logger.Log('New feedback file', logger.GetColor('bluebg'), true)
logger.Log('New feedback file', logger.GetColor('bluebg'))
})
app.post('/postfeedback', function(req, res) {
app.post('/postfeedback', function(req: any, res: any) {
logger.LogReq(req)
if (req.body.fromLogin) {
logger.Log(
'New feedback message from Login page',
logger.GetColor('bluebg'),
true
logger.GetColor('bluebg')
)
} else {
logger.Log(
'New feedback message from feedback page',
logger.GetColor('bluebg'),
true
logger.GetColor('bluebg')
)
}
const ip = req.headers['cf-connecting-ip'] || req.connection.remoteAddress
const user = req.session.user
const user: User = req.session.user
utils.AppendToFile(
utils.GetDateString() +
@ -757,9 +761,8 @@ function GetApp() {
res.json({ success: true })
})
function UploadFile(req, res, path, next) {
function UploadFile(req: any, res: any, path, next) {
try {
const fstream
req.pipe(req.busboy)
req.busboy.on('file', function(fieldname, file, filename) {
logger.Log('Uploading: ' + filename, logger.GetColor('blue'))
@ -775,7 +778,7 @@ function GetApp() {
'_' +
filename
fstream = fs.createWriteStream(path + '/' + fn)
const fstream = fs.createWriteStream(path + '/' + fn)
file.pipe(fstream)
fstream.on('close', function() {
logger.Log(
@ -795,20 +798,20 @@ function GetApp() {
}
}
app.route('/fosuploader').post(function(req, res) {
app.route('/fosuploader').post(function(req: any, res: any) {
UploadFile(req, res, uloadFiles, (fn) => {
res.redirect('/f/' + fn)
})
})
app.route('/badtestsender').post(function(req, res) {
app.route('/badtestsender').post(function(req: any, res: any) {
UploadFile(req, res, recivedFiles, () => {
res.redirect('back')
})
logger.LogReq(req)
})
app.get('/allqr.txt', function(req, res) {
app.get('/allqr.txt', function(req: any, res: any) {
res.set('Content-Type', 'text/plain')
const stringifiedData = questionDbs.map((qdb) => {
return dataToString(qdb.data)
@ -822,7 +825,7 @@ function GetApp() {
// -------------------------------------------------------------------------------------------
// API
app.post('/uploaddata', (req, res) => {
app.post('/uploaddata', (req: any, res: any) => {
// body: JSON.stringify({
// newData: data,
// count: getCount(data),
@ -848,11 +851,12 @@ function GetApp() {
try {
// finding user
const pwds = JSON.parse(utils.ReadFile(passwordFile))
let user = Object.keys(pwds).find((key) => {
const user = pwds[key]
return user.password === password
const userKey = Object.keys(pwds).find((key) => {
const userKey = pwds[key]
return userKey.password === password
})
user = pwds[user]
// FIXME: check user type in dataeditorPW-s json
const user: any = pwds[userKey]
// logging and stuff
logger.Log(`Data upload`, logger.GetColor('bluebg'))
@ -928,10 +932,10 @@ function GetApp() {
}
})
app.post('/isAdding', function(req, res) {
app.post('/isAdding', function(req: any, res: any) {
logger.LogReq(req)
const user = req.session.user
const user: User = req.session.user
const dryRun = testUsers.includes(user.id)
@ -944,10 +948,10 @@ function GetApp() {
dryRun,
user
)
.then((result) => {
.then((resultArray) => {
res.json({
success: result !== -1,
newQuestions: result,
success: resultArray.length > 0, // TODO check for -1s
newQuestions: resultArray,
})
})
.catch((err) => {
@ -959,7 +963,7 @@ function GetApp() {
})
})
app.get('/ask', function(req, res) {
app.get('/ask', function(req: any, res) {
if (Object.keys(req.query).length === 0) {
logger.DebugLog(`No query params`, 'ask', 1)
res.json({
@ -972,7 +976,7 @@ function GetApp() {
if (req.query.q && req.query.data) {
const subj = req.query.subj || ''
const question = req.query.q
let recData = {}
let recData: any = {}
try {
recData = JSON.parse(req.query.data)
} catch (error) {
@ -1035,7 +1039,7 @@ function GetApp() {
})
}
app.get('/datacount', function(req, res) {
app.get('/datacount', function(req: any, res: any) {
logger.LogReq(req)
if (req.query.detailed === 'all') {
res.json({
@ -1049,10 +1053,10 @@ function GetApp() {
}
})
app.get('/infos', function(req, res) {
const user = req.session.user
app.get('/infos', function(req: any, res) {
const user: User = req.session.user
const result = {
const result: any = {
result: 'success',
uid: user.id,
}
@ -1074,11 +1078,11 @@ function GetApp() {
// -------------------------------------------------------------------------------------------
app.get('*', function(req, res) {
app.get('*', function(req: any, res: any) {
res.status(404).render('404')
})
app.post('*', function(req, res) {
app.post('*', function(req: any, res: any) {
res.status(404).render('404')
})
@ -1116,14 +1120,14 @@ function GetApp() {
}
function getDayDiff(dateString) {
const msdiff = new Date() - new Date(dateString)
const msdiff = new Date().getTime() - new Date(dateString).getTime()
return Math.floor(msdiff / (1000 * 3600 * 24))
}
function IncrementAvaiblePWs() {
// FIXME: check this if this is legit and works
logger.Log('Incrementing avaible PW-s ...')
const users = dbtools.SelectAll(userDB, 'users')
const users: Array<User> = dbtools.SelectAll(userDB, 'users')
users.forEach((user) => {
if (user.avaiblePWRequests >= maxPWCount) {
@ -1173,10 +1177,12 @@ function GetApp() {
}
}
exports.name = 'API'
exports.getApp = GetApp
exports.setup = (data) => {
userDB = data.userDB
url = data.url // eslint-disable-line
publicdirs = data.publicdirs
export default {
name: 'API',
getApp: GetApp,
setup: (data: SetupData): void => {
userDB = data.userDB
url = data.url // eslint-disable-line
publicdirs = data.publicdirs
},
}

View file

@ -19,22 +19,24 @@
------------------------------------------------------------------------- */
// package requires
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
import express from 'express'
import bodyParser from 'body-parser'
import busboy from 'connect-busboy'
const app = express()
// other requires
const utils = require('../../utils/utils.js')
const logger = require('../../utils/logger.js')
const auth = require('../../middlewares/auth.middleware.js')
import utils from '../../utils/utils'
import logger from '../../utils/logger'
import auth from '../../middlewares/auth.middleware'
import { SetupData } from '../../server'
import { ModuleType } from '../../types/basicTypes'
// stuff gotten from server.js
let userDB
let publicdirs = []
let nextdir = ''
function GetApp() {
function GetApp(): ModuleType {
app.use(
bodyParser.urlencoded({
limit: '5mb',
@ -71,9 +73,9 @@ function GetApp() {
// --------------------------------------------------------------
function AddHtmlRoutes(files) {
const routes = files.reduce((acc, f) => {
if (f.includes('html')) {
acc.push(f.split('.')[0])
const routes = files.reduce((acc, file) => {
if (file.includes('html')) {
acc.push(file.split('.')[0])
return acc
}
return acc
@ -109,10 +111,12 @@ function GetApp() {
}
}
exports.name = 'Data editor'
exports.getApp = GetApp
exports.setup = (data) => {
userDB = data.userDB
publicdirs = data.publicdirs
nextdir = data.nextdir
export default {
name: 'Data editor',
getApp: GetApp,
setup: (data: SetupData): void => {
userDB = data.userDB
publicdirs = data.publicdirs
nextdir = data.nextdir
},
}

View file

@ -19,19 +19,21 @@
------------------------------------------------------------------------- */
// package requires
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
import express from 'express'
import bodyParser from 'body-parser'
import busboy from 'connect-busboy'
const app = express()
// other requires
const logger = require('../../utils/logger.js')
import logger from '../../utils/logger'
import { SetupData } from '../../server'
import { ModuleType } from '../../types/basicTypes'
// stuff gotten from server.js
let publicdirs = []
let url = '' // http(s)//asd.basd
function GetApp() {
function GetApp(): ModuleType {
app.set('view engine', 'ejs')
app.set('views', ['./src/modules/main/views', './src/sharedViews'])
publicdirs.forEach((pdir) => {
@ -79,9 +81,11 @@ function GetApp() {
}
}
exports.name = 'Main'
exports.getApp = GetApp
exports.setup = (data) => {
url = data.url
publicdirs = data.publicdirs
export default {
name: 'Main',
getApp: GetApp,
setup: (data: SetupData): void => {
url = data.url
publicdirs = data.publicdirs
},
}

View file

@ -1,338 +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 cookieParser = require('cookie-parser')
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 = './vids/p'
const userDataDirectory = './data/vidsData'
const passwordFile = 'data/vidsPasswords.json'
if (!utils.FileExists(userDataDirectory)) {
utils.CreatePath(userDataDirectory, true)
}
function GetApp() {
app.set('view engine', 'ejs')
app.set('views', ['./src/modules/pornvids/views', './sharedViews'])
app.use(express.static('p'))
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.use(cookieParser())
// --------------------------------------------------------------
app.get('/login', (req, res) => {
logger.LogReq(req)
// FIXME: redirect to original url
res.cookie('pw', req.query.pw).redirect('/')
})
app.get('/logout', (req, res) => {
logger.LogReq(req)
// FIXME: redirect to original url
res.clearCookie('pw').redirect('/')
})
// app, '/*.mp4', 'video/mp4', 'stuff/video'
function appGetFileType(app, wildcard, contentType, pageToRender) {
app.get(wildcard, function(req, res) {
const user = GetUserByPW(GetPw(req))
if (!user) {
logger.Log('Vids user: No user', logger.GetColor('blue'))
res.render('login')
return
}
let p = decodeURI(req.url)
let fp = p
if (p.includes('?')) {
fp = p.split('?')
fp.pop()
fp = fp.join('/')
}
const fpath = listedFiles + fp
if (!fs.existsSync(fpath)) {
res.render('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)
logger.Log(`Vids user: ${user.name}`, logger.GetColor('blue'))
AppendWatchedFileToUser(user, fp)
let fname = fpath.split('/')
fname = fname.pop()
res.render(pageToRender, {
path: fp,
fname,
url,
contentType,
albumArt: GetAlbumArt(p),
})
}
})
}
function WriteUserData(user, uData) {
const dataLoc = userDataDirectory + '/' + user.name + '.json'
utils.WriteFile(JSON.stringify(uData), dataLoc)
}
function GetUserData(user) {
try {
const dataLoc = userDataDirectory + '/' + user.name + '.json'
let uData = utils.ReadFile(dataLoc)
uData = JSON.parse(uData)
return uData
} catch (e) {
return {}
}
}
function AppendWatchedFileToUser(user, file) {
const uData = GetUserData(user)
if (uData) {
if (Array.isArray(uData.watched)) {
if (!uData.watched.includes(file)) {
uData.watched.push(file)
}
} else {
uData.watched = [file]
}
WriteUserData(user, uData)
} else {
logger.Log(
'Error appending to user data, no user data found',
logger.GetColor('redbg')
)
}
}
const fileTypes = [
['/*.mp4', 'video/mp4', 'video'],
['/*.mkv', 'audio/x-matroska', 'video'],
['/*.mp3', 'audio/mpeg', '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) {
logger.LogReq(req)
const user = GetUserByPW(GetPw(req))
let uData = {}
if (!user) {
logger.Log('Vids user: No user', logger.GetColor('blue'))
res.render('login')
return
} else {
logger.Log(`Vids user: ${user.name}`, logger.GetColor('blue'))
uData = GetUserData(user)
}
let parsedUrl = decodeURI(req.url)
let curr =
listedFiles +
'/' +
parsedUrl.substring('/'.length, parsedUrl.length).split('?')[0]
let relPath = curr.substring(listedFiles.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, "/");
try {
const stat = fs.lstatSync(curr)
if (stat.isDirectory() || stat.isSymbolicLink()) {
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()
if (uData && Array.isArray(uData.watched)) {
res.watched = uData.watched.includes(res.path)
} else {
res.watched = false
}
f.push(res)
}
})
res.render('folders', {
folders: f,
user: user,
dirname: relPath,
prevDir,
url,
})
} else {
let watchedFile = relPath
if (watchedFile.charAt(watchedFile.length - 1) === '/') {
watchedFile = watchedFile.substr(0, watchedFile.length - 1)
}
AppendWatchedFileToUser(user, watchedFile)
let fileStream = fs.createReadStream(curr)
fileStream.pipe(res)
}
} catch (e) {
res.render('nofile', {
missingFile: curr,
url,
})
}
})
function GetPw(req) {
return req.cookies.pw
}
function GetUserByPW(password) {
const pwds = JSON.parse(utils.ReadFile(passwordFile))
let user = Object.keys(pwds).find((key) => {
const u = pwds[key]
return u.password === password
})
user = pwds[user]
return user
}
// -----------------------------------------------------------------------------------------------
app.get('*', function(req, res) {
res.status(404).render('404')
})
app.post('*', function(req, res) {
res.status(404).render('404')
})
return {
app: app,
}
}
exports.name = 'Porn vids'
exports.getApp = GetApp
exports.setup = (data) => {
url = data.url
}

View file

@ -1,39 +0,0 @@
<html>
<body bgcolor="#212127">
<head>
<title><%= fname %></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
<style>
body {
font: normal 14px Verdana;
color: #999999;
}
video {
width: 100%
}
</style>
</head>
<center>
<h2>
<%= fname %>
</h2>
<img
id="coverArt"
style="width:auto; max-height: 100%;"
src="<%= url + albumArt %>"
alt=' '
/>
<audio id="audioPlayer" controls style="width:100%">
<source src="<%= url %><%= path %>?stream=true" type=<%= contentType %>>
</audio>
</center>
</body>
<script>
console.log('a')
document.getElementById('coverArt').style.height = window.innerHeight - 140
</script>
</html>

View file

@ -1,144 +0,0 @@
<html>
<body bgcolor="#ffeeee">
<head>
<title><%=dirname%></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
<style>
body {
font: normal 14px Verdana;
}
td {
vertical-align: top;
word-wrap: break-word;
word-break: break-all;
table-layout: fixed;
padding: 0;
vertical-align: middle;
}
a {
color: #0000ff;
}
.subtable {
border-collapse: collapse;
table-layout:fixed;
width:100%
}
.maintable {
border-collapse: collapse;
table-layout:fixed;
width:100%;
padding:0; margin:0;
border: none !important;
}
tr {
width:32%;
}
.butt td {
font: normal 24px Verdana;
font-weight: bold;
}
.watched {
color: #999999;
}
.butt {
cursor: pointer;
width: 100%;
border: none;
text-align: left;
}
.rainbow {
background: linear-gradient( 92deg, #ff0000, #00ffff);
background: -webkit-linear-gradient( 92deg, #ff0000, #00ffff);
background-size:600vw 600vw;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: textAnimate 4s linear infinite alternate;
}
@keyframes textAnimate {
from {
filter: hue-rotate(0deg);
background-position-x: 0%;
}
to {
filter: hue-rotate(360deg);
background-position-x: 600vw;
}
}
</style>
</head>
<center>
<h1 class="rainbow">
<div>
Hi <%= user.name %> c:
</div>
<div>
gyerekkori videók <%=dirname%>
</div>
</h1>
</center>
<h2>
<a href="<%= url + prevDir%>" >Back</a>
</h2>
</p>
<table class="maintable">
<% for (var i = 0; i < folders.length; i++) { %>
<tr>
<td>
<a
href="<%= url + folders[i].path %>"
style="font-size: 0px"
>
<button
class="butt"
onmouseenter='mouseEnter(this, <%= i %>)'
onmouseleave='mouseLeave(this, <%= i %>)'
>
<table class="subtable <%= folders[i].watched ? 'watched' : '' %>">
<tr height="62">
<td style='width:85%;'>
<%=folders[i].name %>
</td>
<td style='width:15%;'>
<%
if (folders[i].isDir) {
%> <%= "Mappa" %> <%
} else {
if (folders[i].size === 0) {
%> <%= "~0 MB" %> <%
} else {
%> <%= folders[i].size + ' MB' %> <%
}
}
%>
</td>
</tr>
</table>
</button>
</a>
</td>
</tr>
<% } %>
</table>
<a href='/logout'>logout</a>
</body>
<script>
console.log('hi')
function mouseEnter (e, i) {
e.className += ' rainbow'
}
function mouseLeave (e, i) {
e.className = e.className.replace(/ rainbow/g, '')
}
</script>
</html>

View file

@ -1,63 +0,0 @@
<html>
<body bgcolor="#212127">
<head>
<title>login</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
<style>
video {
width: 100%
}
.rainbow {
background: linear-gradient( 92deg, #ff0000, #00ffff);
background: -webkit-linear-gradient( 92deg, #ff0000, #00ffff);
background-size:600vw 600vw;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: textAnimate 4s linear infinite alternate;
}
@keyframes textAnimate {
from {
filter: hue-rotate(0deg);
background-position-x: 0%;
}
to {
filter: hue-rotate(360deg);
background-position-x: 600vw;
}
}
.text {
color: white;
}
.title {
font: normal 28px Verdana;
font-weight: bold;
color: white;
}
</style>
</head>
<center>
<h2 class='title'>
Login to Porn Vids
</h2>
<div class='text'>
Jelszó:
</div>
<input type='text' id='pw' />
<button onclick='login()'>
Login
</button>
</center>
</body>
<script>
function login () {
const pw = document.getElementById('pw').value
location.href = '/login/?pw=' + pw
}
</script>
</html>

View file

@ -1,94 +0,0 @@
<html>
<body bgcolor="#212127">
<head>
<title>No such file/folder</title>
<meta charset="UTF-8">
<style>
body {
font: normal 14px Verdana;
color: #999999;
}
td {
vertical-align: top
}
textarea {
font: normal 14px Verdana;
color: #999999;
background-color: #212127;
width: 100%;
height: 700;
}
a {
color: #9999ff;
}
.subtable {
border-collapse: collapse;
table-layout:fixed;
width:100%
}
.maintable {
border-collapse: collapse;
table-layout:fixed;
width:100%
padding:0; margin:0;
border: none !important;
}
tr {
line-height: 29px;
width:32%;
}
.butt {
background-color: #212127;
color: #999999;
cursor: pointer;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 13px;
}
.active,
.butt:hover {
background-color: #555;
}
</style>
</head>
<center>
<h1>
No such file / folder:
</br>
<%= missingFile %>
</br>
<a href="<%= url %>" > Back to root </a>
</br>
<a
onclick='goBack("<%=missingFile%>")'
href="#"
>
Go back
</a>
</h1>
</center>
</body>
<script>
function goBack(path) {
path = path.replace('./public/files', '')
if (path[path.length - 1] == '/') {
path = path.substring(0, path.length -2)
}
let p = path.split('/')
p.pop()
if (p.length > 1) {
location.href = p.join('/')
} else {
location.href = '/'
}
}
</script>
</html>

View file

@ -1,57 +0,0 @@
<html>
<body bgcolor="#ffeeee">
<head>
<title><%= fname %></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
<style>
video {
width: 100%
}
.rainbow {
background: linear-gradient( 92deg, #ff0000, #00ffff);
background: -webkit-linear-gradient( 92deg, #ff0000, #00ffff);
background-size:600vw 600vw;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: textAnimate 4s linear infinite alternate;
}
@keyframes textAnimate {
from {
filter: hue-rotate(0deg);
background-position-x: 0%;
}
to {
filter: hue-rotate(360deg);
background-position-x: 600vw;
}
}
.title {
font: normal 28px Verdana;
font-weight: bold;
}
</style>
</head>
<center>
<h2 class='rainbow title'>
<%= fname %>
</h2>
</center>
<video id="videoPlayer" controls>
<source src="<%= url %><%= path %>?stream=true" type="video/mp4">
</video>
</body>
<script>
var v = document.getElementsByTagName('video')[0]
v.style.maxHeight = window.innerHeight - 100
v.maxWidth = window.innerWidth
console.log('a')
</script>
</html>

View file

@ -19,23 +19,24 @@
------------------------------------------------------------------------- */
// package requires
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
const url = require('url')
import express from 'express'
import bodyParser from 'body-parser'
import busboy from 'connect-busboy'
const app = express()
// other requires
const utils = require('../../utils/utils.js')
const logger = require('../../utils/logger.js')
const auth = require('../../middlewares/auth.middleware.js')
import utils from '../../utils/utils'
import logger from '../../utils/logger'
import auth from '../../middlewares/auth.middleware'
import { SetupData } from '../../server'
import { ModuleType } from '../../types/basicTypes'
// stuff gotten from server.js
let publicdirs = []
let userDB
let nextdir = ''
function GetApp() {
function GetApp(): ModuleType {
app.use(
bodyParser.urlencoded({
limit: '5mb',
@ -180,7 +181,7 @@ function GetApp() {
let target = redirect.to
if (!redirect.to.includes('?')) {
target += url.format({ query: req.query })
target += utils.formatUrl({ query: req.query })
}
res.redirect(target)
@ -200,10 +201,10 @@ function GetApp() {
routes.forEach((route) => {
logger.DebugLog(`Added route /${route}`, 'Qmining routes', 1)
app.get(`/${route}`, function(req, res) {
app.get(`/${route}`, function(req: express.Request, res) {
logger.LogReq(req)
res.redirect(
url.format({
utils.formatUrl({
pathname: `${route}.html`,
query: req.query,
})
@ -241,10 +242,12 @@ function GetApp() {
}
}
exports.name = 'Qmining'
exports.getApp = GetApp
exports.setup = (data) => {
userDB = data.userDB
publicdirs = data.publicdirs
nextdir = data.nextdir
export default {
name: 'Qmining',
getApp: GetApp,
setup: (data: SetupData): void => {
userDB = data.userDB
publicdirs = data.publicdirs
nextdir = data.nextdir
},
}

View file

@ -19,27 +19,29 @@
------------------------------------------------------------------------- */
// package requires
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
const fs = require('fs')
import express from 'express'
import bodyParser from 'body-parser'
import busboy from 'connect-busboy'
import fs from 'fs'
const app = express()
// other requires
const logger = require('../../utils/logger.js')
const utils = require('../../utils/utils.js')
import logger from '../../utils/logger'
import utils from '../../utils/utils'
import { SetupData } from '../../server'
import { ModuleType } from '../../types/basicTypes'
// stuff gotten from server.js
let publicdirs = []
function GetApp() {
const p = publicdirs[0]
if (!p) {
function GetApp(): ModuleType {
const publicdir = publicdirs[0]
if (!publicdir) {
throw new Error(`No public dir! ( SIO )`)
}
// files in public dirs
const uloadFiles = p + 'f'
const uloadFiles = publicdir + 'f'
app.set('view engine', 'ejs')
app.set('views', ['./src/modules/sio/views', './src/sharedViews'])
@ -75,23 +77,22 @@ function GetApp() {
})
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() +
const date = new Date()
const fn =
date.getHours() +
'' +
d.getMinutes() +
date.getMinutes() +
'' +
d.getSeconds() +
date.getSeconds() +
'_' +
filename
fstream = fs.createWriteStream(path + '/' + fn)
const fstream = fs.createWriteStream(path + '/' + fn)
file.pipe(fstream)
fstream.on('close', function() {
logger.Log(
@ -107,7 +108,7 @@ function GetApp() {
})
}
app.route('/fosuploader').post(function(req, res, next) {
app.route('/fosuploader').post(function(req, res) {
UploadFile(req, res, uloadFiles, (fn) => {
res.redirect('/f/' + fn)
})
@ -125,8 +126,10 @@ function GetApp() {
}
}
exports.name = 'Sio'
exports.getApp = GetApp
exports.setup = (data) => {
publicdirs = data.publicdirs
export default {
name: 'Sio',
getApp: GetApp,
setup: (data: SetupData): void => {
publicdirs = data.publicdirs
},
}

View file

@ -19,27 +19,29 @@
------------------------------------------------------------------------- */
// package requires
const express = require('express')
const bodyParser = require('body-parser')
const busboy = require('connect-busboy')
const fs = require('fs')
import express from 'express'
import bodyParser from 'body-parser'
import busboy from 'connect-busboy'
import fs from 'fs'
const app = express()
// other requires
const logger = require('../../utils/logger.js')
import logger from '../../utils/logger'
import { SetupData } from '../../server'
import { ModuleType } from '../../types/basicTypes'
// stuff gotten from server.js
let publicdirs = []
let url = ''
function GetApp() {
const p = publicdirs[0]
if (!p) {
function GetApp(): ModuleType {
const publicDir = publicdirs[0]
if (!publicDir) {
throw new Error(`No public dir! ( Stuff )`)
}
// files in public dirs
const listedFiles = './' + p + 'files'
const listedFiles = './' + publicDir + 'files'
app.set('view engine', 'ejs')
app.set('views', ['./src/modules/stuff/views', './src/sharedViews'])
@ -72,10 +74,10 @@ function GetApp() {
// 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('?')
const path = decodeURI(req.url)
let fp: any = path
if (path.includes('?')) {
fp = path.split('?')
fp.pop()
fp = fp.join('/')
}
@ -115,14 +117,13 @@ function GetApp() {
}
} else {
logger.LogReq(req)
let fname = fpath.split('/')
fname = fname.pop()
const fname = fpath.split('/').pop()
res.render(pageToRender, {
path: fp,
fname,
url,
contentType,
albumArt: GetAlbumArt(p),
albumArt: GetAlbumArt(path),
})
}
})
@ -140,7 +141,7 @@ function GetApp() {
let tmp = path.split('.')
tmp.pop()
tmp = tmp.join('.').split('/')
let last = tmp.pop()
const last = tmp.pop()
return tmp.join('/') + '/.' + last + '.png'
}
@ -150,7 +151,7 @@ function GetApp() {
})
app.get('/*', function(req, res) {
let parsedUrl = decodeURI(req.url)
const parsedUrl = decodeURI(req.url)
let curr =
listedFiles +
'/' +
@ -161,10 +162,10 @@ function GetApp() {
relPath += '/'
}
let t = relPath.split('/')
const temp = relPath.split('/')
let prevDir = ''
for (let i = 0; i < t.length - 2; i++) {
prevDir += t[i] + '/'
for (let i = 0; i < temp.length - 2; i++) {
prevDir += temp[i] + '/'
}
// curr = curr.replace(/\//g, "/");
@ -179,9 +180,9 @@ function GetApp() {
curr += '/'
}
let f = []
const folders = []
let files = fs.readdirSync(curr)
const files = fs.readdirSync(curr)
files.sort(function(a, b) {
return (
fs.statSync(curr + b).mtime.getTime() -
@ -191,10 +192,9 @@ function GetApp() {
files.forEach((item) => {
if (item[0] !== '.') {
let res = { name: item }
let stat = fs.statSync(curr + '/' + item)
let fileSizeInBytes = stat['size']
const res: any = { name: item }
const stat = fs.statSync(curr + '/' + item)
const fileSizeInBytes = stat['size']
res.size = Math.round(fileSizeInBytes / 1000000)
res.path = relPath
@ -206,21 +206,21 @@ function GetApp() {
res.mtime = stat['mtime'].toLocaleString()
res.isDir = stat.isDirectory()
f.push(res)
folders.push(res)
}
})
res.render('folders', {
folders: f,
folders: folders,
dirname: relPath,
prevDir,
url,
})
} else {
let fileStream = fs.createReadStream(curr)
const fileStream = fs.createReadStream(curr)
fileStream.pipe(res)
}
} catch (e) {
} catch (err) {
res.render('nofile', {
missingFile: curr,
url,
@ -243,9 +243,11 @@ function GetApp() {
}
}
exports.name = 'Stuff'
exports.getApp = GetApp
exports.setup = (data) => {
url = data.url
publicdirs = data.publicdirs
export default {
name: 'Stuff',
getApp: GetApp,
setup: (data: SetupData): void => {
url = data.url
publicdirs = data.publicdirs
},
}