setBaseUrl dynamic; PubTypeEnu mapping
This commit is contained in:
@ -62,34 +62,31 @@ exports.isValidPhoneNumber = function (phone) {
|
||||
// If neither condition is met, the phone number is invalid
|
||||
return false;
|
||||
}
|
||||
|
||||
exports.setBaseUrl = function (req) {
|
||||
const protocol = req.headers['x-forwarded-proto'] || 'http';
|
||||
const host = req.headers.host;
|
||||
const baseUrl = `${protocol}://${host}`;
|
||||
|
||||
fs.writeFileSync(path.join(__dirname, 'baseUrl.txt'), baseUrlGlobal, 'utf8');
|
||||
// Write the baseUrl to the file
|
||||
if (req != null) {
|
||||
fs.writeFileSync(path.join(__dirname, 'baseUrl.txt'), baseUrl, 'utf8');
|
||||
}
|
||||
return baseUrl;
|
||||
}
|
||||
};
|
||||
|
||||
exports.getBaseUrl = function (relative = "", req = null) {
|
||||
const filePath = path.join(__dirname, 'baseUrl.txt');
|
||||
|
||||
try {
|
||||
// Check if the base URL file exists
|
||||
if (fs.existsSync(filePath)) {
|
||||
// Read the base URL from the file
|
||||
const baseUrl = fs.readFileSync(filePath, 'utf8').trim();
|
||||
// If a relative path is provided, append it to the base URL
|
||||
const fullUrl = relative ? new URL(relative, baseUrl).toString() : baseUrl;
|
||||
return fullUrl;
|
||||
} else {
|
||||
|
||||
if (req) {
|
||||
const baseUrl = exports.setBaseUrl(req);
|
||||
return `${baseUrl}/${relative.replace(/^\/|\/$/g, '')}/`;
|
||||
const baseUrl = exports.setBaseUrl(req); // Correctly reference setBaseUrl
|
||||
return `${baseUrl}/${relative.replace(/^\/|\/$/g, '')}`;
|
||||
}
|
||||
|
||||
console.log('Base URL file does not exist.');
|
||||
return null;
|
||||
}
|
||||
@ -97,7 +94,6 @@ exports.getBaseUrl = function (relative = "", req = null) {
|
||||
console.error('Error reading the base URL file:', error);
|
||||
return null;
|
||||
}
|
||||
|
||||
// const host = process.env.NEXT_PUBLIC_HOST || '127.0.0.1';
|
||||
// const port = process.env.NEXT_PUBLIC_PORT ? `:${ process.env.NEXT_PUBLIC_PORT } ` : '';
|
||||
// const protocol = process.env.NEXT_PUBLIC_PROTOCOL || "https"
|
||||
@ -112,7 +108,8 @@ exports.getBaseUrl = function (relative = "", req = null) {
|
||||
// logger.debug("getBaseURL = ", url);
|
||||
|
||||
// return url;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
let prisma;
|
||||
@ -202,6 +199,18 @@ exports.getDayOfWeekNameEnEnum = function (date) {
|
||||
|
||||
return dayOfWeekNames[dayOfWeekIndex];
|
||||
}
|
||||
exports.getPubTypeEnum = function (text) {
|
||||
const input = text.trim();
|
||||
const mapping = {
|
||||
'Вестител': 'Publisher',
|
||||
'Бетелит': 'Bethelite',
|
||||
'Редовен Пионер': 'RegularPioneer',
|
||||
'Специален Пионер/Мисионер': 'SpecialPioneer_Missionary',
|
||||
};
|
||||
|
||||
// Default to 'Publisher' if the input does not match any key
|
||||
return mapping[input] || 'Publisher';
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user