mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-17 03:44:20 +03:00
Initial refactor (routes and utils to respective folders)
This commit is contained in:
13
src/utils/getFormattedTime.js
Normal file
13
src/utils/getFormattedTime.js
Normal file
@@ -0,0 +1,13 @@
|
||||
//converts time in seconds to minutes:seconds
|
||||
module.exports = function getFormattedTime(seconds) {
|
||||
let minutes = Math.floor(seconds / 60);
|
||||
let secondsDisplay = Math.round(seconds - minutes * 60);
|
||||
if (secondsDisplay < 10) {
|
||||
//add a zero
|
||||
secondsDisplay = "0" + secondsDisplay;
|
||||
}
|
||||
|
||||
let formatted = minutes+ ":" + secondsDisplay;
|
||||
|
||||
return formatted;
|
||||
}
|
||||
10
src/utils/getHash.js
Normal file
10
src/utils/getHash.js
Normal file
@@ -0,0 +1,10 @@
|
||||
var crypto = require('crypto');
|
||||
|
||||
module.exports = function (value, times=5000) {
|
||||
for (let i = 0; i < times; i++) {
|
||||
let hashCreator = crypto.createHash('sha256');
|
||||
value = hashCreator.update(value).digest('hex');
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
6
src/utils/getIP.js
Normal file
6
src/utils/getIP.js
Normal file
@@ -0,0 +1,6 @@
|
||||
var fs = require('fs');
|
||||
var config = JSON.parse(fs.readFileSync('config.json'));
|
||||
|
||||
module.exports = function getIP(req) {
|
||||
return config.behindProxy ? req.headers['x-forwarded-for'] : req.connection.remoteAddress;
|
||||
}
|
||||
Reference in New Issue
Block a user