Initial commit
This commit is contained in:
38
remote/src/utils/config.js
Normal file
38
remote/src/utils/config.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const newConfig = require('../config');
|
||||
|
||||
module.exports = {
|
||||
getServerConfig() {
|
||||
return newConfig.getSection('server') || {};
|
||||
},
|
||||
|
||||
getStreamConfig() {
|
||||
return newConfig.getSection('stream') || {};
|
||||
},
|
||||
|
||||
getInputConfig() {
|
||||
return newConfig.getSection('input') || {};
|
||||
},
|
||||
|
||||
getSecurityConfig() {
|
||||
return newConfig.getSection('security') || {};
|
||||
},
|
||||
|
||||
getFRPConfig() {
|
||||
return newConfig.getSection('frp') || { enabled: false };
|
||||
},
|
||||
|
||||
getConfig() {
|
||||
return newConfig.getAll();
|
||||
},
|
||||
|
||||
setConfig(newConfig) {
|
||||
return this.getConfig();
|
||||
},
|
||||
|
||||
get: newConfig.get,
|
||||
getSection: newConfig.getSection,
|
||||
getAll: newConfig.getAll,
|
||||
reload: newConfig.reload,
|
||||
clearCache: newConfig.clearCache,
|
||||
validate: newConfig.validate
|
||||
};
|
||||
46
remote/src/utils/logger.js
Normal file
46
remote/src/utils/logger.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const winston = require('winston');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const paths = require('./paths');
|
||||
|
||||
const logDir = path.join(paths.getBasePath(), 'logs');
|
||||
|
||||
if (!fs.existsSync(logDir)) {
|
||||
fs.mkdirSync(logDir, { recursive: true });
|
||||
}
|
||||
|
||||
const baseLogger = winston.createLogger({
|
||||
level: process.env.LOG_LEVEL || 'info',
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
||||
winston.format.errors({ stack: true }),
|
||||
winston.format.splat(),
|
||||
winston.format.json()
|
||||
),
|
||||
defaultMeta: { service: 'remote-screen' },
|
||||
transports: [
|
||||
new winston.transports.File({
|
||||
filename: path.join(logDir, 'error.log'),
|
||||
level: 'error'
|
||||
}),
|
||||
new winston.transports.File({
|
||||
filename: path.join(logDir, 'combined.log')
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' && !process.pkg) {
|
||||
baseLogger.add(new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.simple()
|
||||
)
|
||||
}));
|
||||
}
|
||||
|
||||
function createLogger(moduleName) {
|
||||
return baseLogger.child({ module: moduleName });
|
||||
}
|
||||
|
||||
module.exports = baseLogger;
|
||||
module.exports.createLogger = createLogger;
|
||||
43
remote/src/utils/paths.js
Normal file
43
remote/src/utils/paths.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
function getBasePath() {
|
||||
if (process.pkg) {
|
||||
return path.dirname(process.execPath);
|
||||
}
|
||||
return path.join(__dirname, '../..');
|
||||
}
|
||||
|
||||
function getPublicPath() {
|
||||
return path.join(getBasePath(), 'public');
|
||||
}
|
||||
|
||||
function getConfigPath() {
|
||||
return path.join(getBasePath(), 'config');
|
||||
}
|
||||
|
||||
function getFRPPath() {
|
||||
return path.join(getBasePath(), 'frp');
|
||||
}
|
||||
|
||||
function getUploadPath() {
|
||||
return path.join(getBasePath(), 'uploads');
|
||||
}
|
||||
|
||||
function getTempPath() {
|
||||
return path.join(getBasePath(), 'uploads', 'temp');
|
||||
}
|
||||
|
||||
function resourceExists(resourcePath) {
|
||||
return fs.existsSync(resourcePath);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getBasePath,
|
||||
getPublicPath,
|
||||
getConfigPath,
|
||||
getFRPPath,
|
||||
getUploadPath,
|
||||
getTempPath,
|
||||
resourceExists
|
||||
};
|
||||
Reference in New Issue
Block a user