X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fhelpers%2Fcore-utils.ts;h=33bbdca8b6b44f1a95516fe93359d53da7a5f47e;hb=49347a0a8b64559192d8f29f1237308025a48fd4;hp=f8dd45533f352a05c6f85e2c0de3948e3dd9d3a3;hpb=556ddc319242aafef51bae9301423ecf8701a3af;p=github%2FChocobozzz%2FPeerTube.git
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index f8dd45533..33bbdca8b 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -11,7 +11,9 @@ import {
rename,
unlink,
writeFile,
- access
+ access,
+ stat,
+ Stats
} from 'fs'
import * as mkdirp from 'mkdirp'
import * as bcrypt from 'bcrypt'
@@ -25,8 +27,31 @@ function isTestInstance () {
}
function root () {
- // We are in /dist/helpers/utils.js
- return join(__dirname, '..', '..', '..')
+ // We are in /helpers/utils.js
+ const paths = [ __dirname, '..', '..' ]
+
+ // We are under /dist directory
+ if (process.mainModule.filename.endsWith('.ts') === false) {
+ paths.push('..')
+ }
+
+ return join.apply(null, paths)
+}
+
+// Thanks: https://stackoverflow.com/a/12034334
+function escapeHTML (stringParam) {
+ const entityMap = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': '"',
+ "'": ''',
+ '/': '/',
+ '`': '`',
+ '=': '='
+ }
+
+ return String(stringParam).replace(/[&<>"'`=\/]/g, s => entityMap[s])
}
function promisify0 (func: (cb: (err: any, result: A) => void) => void): () => Promise {
@@ -85,12 +110,14 @@ const bcryptGenSaltPromise = promisify1(bcrypt.genSalt)
const bcryptHashPromise = promisify2(bcrypt.hash)
const createTorrentPromise = promisify2(createTorrent)
const rimrafPromise = promisify1WithVoid(rimraf)
+const statPromise = promisify1(stat)
// ---------------------------------------------------------------------------
export {
isTestInstance,
root,
+ escapeHTML,
promisify0,
promisify1,
@@ -108,5 +135,6 @@ export {
bcryptGenSaltPromise,
bcryptHashPromise,
createTorrentPromise,
- rimrafPromise
+ rimrafPromise,
+ statPromise
}