converter-toless-plugin
Advanced tools
Comparing version 0.0.38 to 0.0.39
@@ -0,1 +1,5 @@ | ||
import type { Express, Response } from "express" | ||
export interface converterOptions { | ||
@@ -28,5 +32,2 @@ deleteallTempFilesOnStart: boolean; | ||
export interface FilterOps { | ||
@@ -48,2 +49,12 @@ enabled: boolean; | ||
export interface Page { | ||
name: string; | ||
dir: string; | ||
} | ||
export interface Pages { | ||
[key: string]: Page | ||
} | ||
export interface Dirs { | ||
@@ -53,2 +64,35 @@ maindir: string; | ||
back_end: string; | ||
} | ||
export interface Router { | ||
/** get a page with options*/ | ||
page: (pageName: string, options?: any) => string; | ||
/** Set a page with options*/ | ||
setPage: (res: Response, pageName: string, options?: any) => void; | ||
/** Get one of the costume paths */ | ||
path: (name: string) => string; | ||
/** check this user with google recaptcha */ | ||
reCaptchaCheck: (UserToken: string, ip: string) => [stated: boolean, msg: string]; | ||
/** hold all dirs for the plugin to know its main files */ | ||
alldir: Dirs; | ||
/** holds the folder for its logs */ | ||
logdir: string; | ||
/** holds the app that the plugin can use to communicate */ | ||
app: Express; | ||
/** holds all possible pages that the plugin can use */ | ||
pages: Pages; | ||
/** holds the costume paths */ | ||
paths: any; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Compiler, converterOptions, Dirs } from "../d/types"; | ||
import { Compiler, converterOptions, Dirs, Router } from "../d/types"; | ||
import { Request, Response } from "express"; | ||
@@ -11,6 +11,7 @@ export default class CompilersHandler { | ||
outputdir: string; | ||
/**In Minutes */ | ||
timetoGarbageCleaner: number; | ||
app: any; | ||
filter: any; | ||
router: any; | ||
router: Router; | ||
debug: any; | ||
@@ -17,0 +18,0 @@ logInFile: any; |
@@ -31,3 +31,3 @@ import { createRequire } from 'module'; | ||
logfile: Path.join(_dirname, 'logs', 'converterlog.txt'), | ||
timetoGarbageCleaner: 14400, | ||
timetoGarbageCleaner: 240, | ||
deleteallTempFilesOnStart: true, | ||
@@ -38,3 +38,4 @@ filesizeLimitsMB: 100, | ||
}; | ||
let MB = 2048; | ||
const MB = 2048; | ||
const Minute = 60000; | ||
export default class CompilersHandler { | ||
@@ -98,2 +99,12 @@ constructor(props = {}) { | ||
try { | ||
// check for captcha abuse | ||
if (req.body['g-recaptcha-response'] === undefined || req.body['g-recaptcha-response'] === '' || req.body['g-recaptcha-response'] === null) { | ||
this.log("rickrolled, you tried to abuse the system huh?", req, res); | ||
} | ||
// check for user verification | ||
const [stated, msg] = this.router.reCaptchaCheck(req.body["captcha"], req.ip); | ||
if (!stated) { | ||
this.log(msg, req, res); | ||
} | ||
this.log(msg); | ||
const compileType = req.body.type; | ||
@@ -121,6 +132,8 @@ const file = req.file; | ||
} | ||
// check if the file can work with the compiler | ||
// check if the compiler can work with the file | ||
if (compiler.whitelistInputs[0]) { | ||
if (compiler.whitelistInputs.length > 0 && compiler.whitelistInputs.map(a => a.toUpperCase()).indexOf(props.type.toUpperCase()) == -1) { | ||
this.log(`Not an acceptable file type by the compiler ${compileType}`, req, res); | ||
this.log(`Not an acceptable file type by the compiler | ||
${compiler.name}\n it only accepts | ||
[${compiler.whitelistInputs.join(`,`)}]`, req, res); | ||
return; | ||
@@ -232,5 +245,5 @@ } | ||
async makeGetReqForTheFile(urlfile, filepath) { | ||
this.app.get(urlfile, (_req, res) => { | ||
this.app.get(urlfile, (req, res) => { | ||
if (!fs.existsSync(filepath)) { | ||
res.send(this.router.message("sorry the file is no longer avaliable")); | ||
res.send(this.log("sorry the file is no longer avaliable", req, res)); | ||
} | ||
@@ -244,3 +257,3 @@ res.download(filepath); | ||
if (res) { | ||
res.send(this.router.message(errorMes)); | ||
res.status(406).send({ message: errorMes }); | ||
res.end(); | ||
@@ -256,3 +269,3 @@ } | ||
if (err) | ||
console.warn(`[${Date.now()}] ${ip} Not Able to log into file because the file is not accesible ${logfile}`); | ||
console.warn(`[${Date.now()}] ${ip} Not Able to log into file because the file is not accesible ${logfile}\n`); | ||
}); // => | ||
@@ -288,3 +301,3 @@ } | ||
var mtime = stats.mtime; | ||
if (Number(new Date()) - Number(new Date(mtime)) >= this.timetoGarbageCleaner * 100) { | ||
if (Number(new Date()) - Number(new Date(mtime)) >= this.timetoGarbageCleaner * Minute) { | ||
fs.unlink(Path.join(_dir, file), (err) => { | ||
@@ -291,0 +304,0 @@ if (err) |
{ | ||
"name": "converter-toless-plugin", | ||
"version": "0.0.38", | ||
"version": "0.0.39", | ||
"description": "this is a plugin", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -16,3 +16,3 @@ import { createRequire } from 'module'; | ||
// for types | ||
import { Compiler, converterOptions, Dirs } from "../d/types"; | ||
import { Compiler, converterOptions, Dirs, Router } from "../d/types"; | ||
@@ -54,3 +54,3 @@ | ||
timetoGarbageCleaner: 14400, | ||
timetoGarbageCleaner: 240, | ||
@@ -66,4 +66,6 @@ deleteallTempFilesOnStart: true, | ||
let MB = 2048 | ||
const MB = 2048; | ||
const Minute = 60000; | ||
export default class CompilersHandler { | ||
@@ -79,2 +81,4 @@ | ||
outputdir!: string; | ||
/**In Minutes */ | ||
timetoGarbageCleaner!: number; | ||
@@ -84,5 +88,6 @@ | ||
filter: any; | ||
router: any; | ||
router!: Router; | ||
debug: any; | ||
logInFile: any; | ||
constructor(props: converterOptions | object = {}) { | ||
@@ -162,2 +167,19 @@ this.getParams({ ...defaultProps, ...props }) | ||
try { | ||
// check for captcha abuse | ||
if (req.body['g-recaptcha-response'] === undefined || req.body['g-recaptcha-response'] === '' || req.body['g-recaptcha-response'] === null) { | ||
this.log("rickrolled, you tried to abuse the system huh?", req, res); | ||
} | ||
// check for user verification | ||
const [stated, msg] = this.router.reCaptchaCheck(req.body["captcha"], req.ip) | ||
if (!stated) { | ||
this.log(msg, req, res); | ||
} | ||
this.log(msg) | ||
const compileType: number = req.body.type; | ||
@@ -196,6 +218,12 @@ const file = req.file | ||
// check if the file can work with the compiler | ||
// check if the compiler can work with the file | ||
if (compiler.whitelistInputs[0]) { | ||
if (compiler.whitelistInputs.length > 0 && compiler.whitelistInputs.map(a => a.toUpperCase()).indexOf(props.type.toUpperCase()) == -1) { | ||
this.log(`Not an acceptable file type by the compiler ${compileType}`, req, res) | ||
this.log( | ||
`Not an acceptable file type by the compiler | ||
${compiler.name}\n it only accepts | ||
[${compiler.whitelistInputs.join(`,`)}]` | ||
, req, res) | ||
return; | ||
@@ -323,5 +351,5 @@ } | ||
async makeGetReqForTheFile(urlfile: string, filepath: string) { | ||
this.app.get(urlfile, (_req: Request, res: Response) => { | ||
this.app.get(urlfile, (req: Request, res: Response) => { | ||
if (!fs.existsSync(filepath)) { | ||
res.send(this.router.message("sorry the file is no longer avaliable")) | ||
res.send(this.log("sorry the file is no longer avaliable", req, res)) | ||
} | ||
@@ -336,3 +364,3 @@ res.download(filepath); | ||
if (res) { | ||
res.send(this.router.message(errorMes)) | ||
res.status(406).send({ message: errorMes }) | ||
res.end(); | ||
@@ -350,3 +378,3 @@ } | ||
(err: any) => { | ||
if (err) console.warn(`[${Date.now()}] ${ip} Not Able to log into file because the file is not accesible ${logfile}`) | ||
if (err) console.warn(`[${Date.now()}] ${ip} Not Able to log into file because the file is not accesible ${logfile}\n`) | ||
}); // => | ||
@@ -387,3 +415,3 @@ } | ||
var mtime = stats.mtime; | ||
if (Number(new Date()) - Number(new Date(mtime)) >= this.timetoGarbageCleaner * 100) { | ||
if (Number(new Date()) - Number(new Date(mtime)) >= this.timetoGarbageCleaner * Minute) { | ||
fs.unlink(Path.join(_dir, file), (err: any) => { | ||
@@ -390,0 +418,0 @@ if (err) console.error(err) |
42229
1110