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
|
// If neither condition is met, the phone number is invalid
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.setBaseUrl = function (req) {
|
exports.setBaseUrl = function (req) {
|
||||||
const protocol = req.headers['x-forwarded-proto'] || 'http';
|
const protocol = req.headers['x-forwarded-proto'] || 'http';
|
||||||
const host = req.headers.host;
|
const host = req.headers.host;
|
||||||
const baseUrl = `${protocol}://${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;
|
return baseUrl;
|
||||||
}
|
};
|
||||||
|
|
||||||
exports.getBaseUrl = function (relative = "", req = null) {
|
exports.getBaseUrl = function (relative = "", req = null) {
|
||||||
const filePath = path.join(__dirname, 'baseUrl.txt');
|
const filePath = path.join(__dirname, 'baseUrl.txt');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Check if the base URL file exists
|
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
// Read the base URL from the file
|
|
||||||
const baseUrl = fs.readFileSync(filePath, 'utf8').trim();
|
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;
|
const fullUrl = relative ? new URL(relative, baseUrl).toString() : baseUrl;
|
||||||
return fullUrl;
|
return fullUrl;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (req) {
|
if (req) {
|
||||||
const baseUrl = exports.setBaseUrl(req);
|
const baseUrl = exports.setBaseUrl(req); // Correctly reference setBaseUrl
|
||||||
return `${baseUrl}/${relative.replace(/^\/|\/$/g, '')}/`;
|
return `${baseUrl}/${relative.replace(/^\/|\/$/g, '')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Base URL file does not exist.');
|
console.log('Base URL file does not exist.');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -97,7 +94,6 @@ exports.getBaseUrl = function (relative = "", req = null) {
|
|||||||
console.error('Error reading the base URL file:', error);
|
console.error('Error reading the base URL file:', error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const host = process.env.NEXT_PUBLIC_HOST || '127.0.0.1';
|
// const host = process.env.NEXT_PUBLIC_HOST || '127.0.0.1';
|
||||||
// const port = process.env.NEXT_PUBLIC_PORT ? `:${ process.env.NEXT_PUBLIC_PORT } ` : '';
|
// const port = process.env.NEXT_PUBLIC_PORT ? `:${ process.env.NEXT_PUBLIC_PORT } ` : '';
|
||||||
// const protocol = process.env.NEXT_PUBLIC_PROTOCOL || "https"
|
// const protocol = process.env.NEXT_PUBLIC_PROTOCOL || "https"
|
||||||
@ -112,7 +108,8 @@ exports.getBaseUrl = function (relative = "", req = null) {
|
|||||||
// logger.debug("getBaseURL = ", url);
|
// logger.debug("getBaseURL = ", url);
|
||||||
|
|
||||||
// return url;
|
// return url;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let prisma;
|
let prisma;
|
||||||
@ -202,6 +199,18 @@ exports.getDayOfWeekNameEnEnum = function (date) {
|
|||||||
|
|
||||||
return dayOfWeekNames[dayOfWeekIndex];
|
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