mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-12 12:39:05 -05:00
fix: remove fetch requests
This commit is contained in:
Vendored
-2
@@ -21,8 +21,6 @@ services:
|
||||
environment:
|
||||
- DB_CONNECTION_STRING=mongodb://mongodb:27017/uptime_db
|
||||
- REDIS_HOST=redis
|
||||
- POEDITOR_API_TOKEN=
|
||||
- POEDITOR_PROJECT_ID=
|
||||
# volumes:
|
||||
# - /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
redis:
|
||||
|
||||
+2
-2
@@ -161,8 +161,7 @@ const startApp = async () => {
|
||||
}
|
||||
|
||||
// Create and Register Primary services
|
||||
const networkService = new NetworkService(axios, ping, logger, http, Docker, net);
|
||||
const translationService = new TranslationService(logger, networkService);
|
||||
const translationService = new TranslationService(logger);
|
||||
const stringService = new StringService(translationService);
|
||||
ServiceRegistry.register(StringService.SERVICE_NAME, stringService);
|
||||
|
||||
@@ -171,6 +170,7 @@ const startApp = async () => {
|
||||
await db.connect();
|
||||
|
||||
// Create services
|
||||
const networkService = new NetworkService(axios, ping, logger, http, Docker, net, stringService);
|
||||
const settingsService = new SettingsService(AppSettings);
|
||||
await settingsService.loadSettings();
|
||||
const emailService = new EmailService(
|
||||
|
||||
@@ -12,9 +12,8 @@ const UPROCK_ENDPOINT = "https://api.uprock.com/checkmate/push";
|
||||
*/
|
||||
class NetworkService {
|
||||
static SERVICE_NAME = SERVICE_NAME;
|
||||
static POEDITOR_BASE_URL = 'https://api.poeditor.com/v2';
|
||||
|
||||
constructor(axios, ping, logger, http, Docker, net) {
|
||||
constructor(axios, ping, logger, http, Docker, net, stringService) {
|
||||
this.TYPE_PING = "ping";
|
||||
this.TYPE_HTTP = "http";
|
||||
this.TYPE_PAGESPEED = "pagespeed";
|
||||
@@ -31,17 +30,7 @@ class NetworkService {
|
||||
this.http = http;
|
||||
this.Docker = Docker;
|
||||
this.net = net;
|
||||
|
||||
this.apiToken = process.env.POEDITOR_API_TOKEN;
|
||||
this.projectId = process.env.POEDITOR_PROJECT_ID;
|
||||
|
||||
if (!this.apiToken || !this.projectId) {
|
||||
this.logger.error({
|
||||
message: 'POEditor API token or project ID is missing in environment variables',
|
||||
service: this.SERVICE_NAME,
|
||||
method: 'constructor'
|
||||
});
|
||||
}
|
||||
this.stringService = stringService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -410,95 +399,6 @@ class NetworkService {
|
||||
return this.handleUnsupportedType(type);
|
||||
}
|
||||
}
|
||||
|
||||
async getPoEditorLanguages() {
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
params.append('api_token', this.apiToken);
|
||||
params.append('id', this.projectId);
|
||||
|
||||
const response = await this.axios.post(`${NetworkService.POEDITOR_BASE_URL}/languages/list`, params, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
});
|
||||
|
||||
return response.data.result.languages.map(lang => lang.code);
|
||||
} catch (error) {
|
||||
error.service = this.SERVICE_NAME;
|
||||
error.method = "getPoEditorLanguages";
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async exportPoEditorTranslations(language) {
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
params.append('api_token', this.apiToken);
|
||||
params.append('id', this.projectId);
|
||||
params.append('language', language);
|
||||
params.append('type', 'key_value_json');
|
||||
|
||||
const exportResponse = await this.axios.post(`${NetworkService.POEDITOR_BASE_URL}/projects/export`, params, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
});
|
||||
|
||||
const { url } = exportResponse.data.result;
|
||||
const translationsResponse = await this.axios.get(url);
|
||||
return translationsResponse.data;
|
||||
} catch (error) {
|
||||
error.service = this.SERVICE_NAME;
|
||||
error.method = "exportPoEditorTranslations";
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getPoEditorTerms() {
|
||||
try {
|
||||
const params = new URLSearchParams();
|
||||
params.append('api_token', this.apiToken);
|
||||
params.append('id', this.projectId);
|
||||
|
||||
const response = await this.axios.post(`${NetworkService.POEDITOR_BASE_URL}/terms/list`, params, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
});
|
||||
|
||||
return response.data.result?.terms?.map(term => term.term.trim()) || [];
|
||||
} catch (error) {
|
||||
error.service = this.SERVICE_NAME;
|
||||
error.method = "getPoEditorTerms";
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async addPoEditorTerms(terms) {
|
||||
try {
|
||||
const formattedTerms = terms.map(termObj => ({
|
||||
term: Object.keys(termObj)[0]
|
||||
}));
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.append('api_token', this.apiToken);
|
||||
params.append('id', this.projectId);
|
||||
params.append('data', JSON.stringify(formattedTerms));
|
||||
|
||||
const response = await this.axios.post(`${NetworkService.POEDITOR_BASE_URL}/terms/add`, params, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
});
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
error.service = this.SERVICE_NAME;
|
||||
error.method = "addPoEditorTerms";
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default NetworkService;
|
||||
|
||||
@@ -4,9 +4,8 @@ import path from 'path';
|
||||
class TranslationService {
|
||||
static SERVICE_NAME = 'TranslationService';
|
||||
|
||||
constructor(logger, networkService) {
|
||||
constructor(logger) {
|
||||
this.logger = logger;
|
||||
this.networkService = networkService;
|
||||
this.translations = {};
|
||||
this._language = 'en';
|
||||
this.localesDir = path.join(process.cwd(), 'locales');
|
||||
@@ -22,10 +21,8 @@ class TranslationService {
|
||||
|
||||
async initialize() {
|
||||
try {
|
||||
await this.loadTranslations();
|
||||
await this.loadFromFiles();
|
||||
|
||||
// Yeni eklenen terimleri POEditor'e gönder
|
||||
await this.syncTermsWithPOEditor();
|
||||
} catch (error) {
|
||||
this.logger.error({
|
||||
message: error.message,
|
||||
@@ -73,113 +70,6 @@ class TranslationService {
|
||||
}
|
||||
}
|
||||
|
||||
async loadTranslations() {
|
||||
let hasError = false;
|
||||
try {
|
||||
const languages = await this.getLanguages();
|
||||
|
||||
for (const language of languages) {
|
||||
try {
|
||||
const translations = await this.exportTranslations(language);
|
||||
this.translations[language] = translations;
|
||||
} catch (error) {
|
||||
hasError = true;
|
||||
this.logger.error({
|
||||
message: `Failed to fetch translations from POEditor for language ${language}: ${error.message}`,
|
||||
service: 'TranslationService',
|
||||
method: 'loadTranslations',
|
||||
stack: error.stack
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (hasError || Object.keys(this.translations[this._language]).length === 0) {
|
||||
this.logger.error({
|
||||
message: 'Failed to fetch translations from POEditor, using default.json',
|
||||
service: 'TranslationService',
|
||||
method: 'loadTranslations'
|
||||
});
|
||||
|
||||
// Load translations from default.json in locales directory
|
||||
const defaultFilePath = path.join(this.localesDir, 'default.json');
|
||||
if (fs.existsSync(defaultFilePath)) {
|
||||
const content = fs.readFileSync(defaultFilePath, 'utf8');
|
||||
this.translations['en'] = JSON.parse(content);
|
||||
} else {
|
||||
throw new Error('default.json file not found in locales directory');
|
||||
}
|
||||
}
|
||||
|
||||
await this.saveTranslations();
|
||||
} catch (error) {
|
||||
hasError = true;
|
||||
this.logger.error({
|
||||
message: error.message,
|
||||
service: 'TranslationService',
|
||||
method: 'loadTranslations',
|
||||
stack: error.stack
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async getLanguages() {
|
||||
try {
|
||||
return await this.networkService.getPoEditorLanguages();
|
||||
} catch (error) {
|
||||
this.logger.error({
|
||||
message: error.message,
|
||||
service: 'TranslationService',
|
||||
method: 'getLanguages',
|
||||
stack: error.stack
|
||||
});
|
||||
return ['en'];
|
||||
}
|
||||
}
|
||||
|
||||
async exportTranslations(language) {
|
||||
try {
|
||||
return await this.networkService.exportPoEditorTranslations(language);
|
||||
} catch (error) {
|
||||
this.logger.error({
|
||||
message: error.message,
|
||||
service: 'TranslationService',
|
||||
method: 'exportTranslations',
|
||||
stack: error.stack
|
||||
});
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
async saveTranslations() {
|
||||
try {
|
||||
if (!fs.existsSync(this.localesDir)) {
|
||||
fs.mkdirSync(this.localesDir);
|
||||
}
|
||||
|
||||
for (const [language, translations] of Object.entries(this.translations)) {
|
||||
const filePath = path.join(this.localesDir, `${language}.json`);
|
||||
fs.writeFileSync(filePath, JSON.stringify(translations, null, 2));
|
||||
}
|
||||
|
||||
const defaultFilePath = path.join(this.localesDir, 'default.json');
|
||||
const enTranslations = this.translations['en'] || {};
|
||||
fs.writeFileSync(defaultFilePath, JSON.stringify(enTranslations, null, 2));
|
||||
|
||||
this.logger.info({
|
||||
message: 'Translations saved to files successfully',
|
||||
service: 'TranslationService',
|
||||
method: 'saveTranslations'
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.error({
|
||||
message: error.message,
|
||||
service: 'TranslationService',
|
||||
method: 'saveTranslations',
|
||||
stack: error.stack
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
getTranslation(key) {
|
||||
let language = this._language;
|
||||
|
||||
@@ -195,93 +85,6 @@ class TranslationService {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
async getTermsFromPOEditor() {
|
||||
try {
|
||||
return await this.networkService.getPoEditorTerms();
|
||||
} catch (error) {
|
||||
this.logger.error({
|
||||
message: error.message,
|
||||
service: 'TranslationService',
|
||||
method: 'getTermsFromPOEditor',
|
||||
stack: error.stack
|
||||
});
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async addTermsToPOEditor(terms) {
|
||||
try {
|
||||
if (!terms.length) return;
|
||||
|
||||
const response = await this.networkService.addPoEditorTerms(terms);
|
||||
|
||||
if (response.response?.status === 'fail') {
|
||||
throw new Error(response.response.message || 'Failed to add terms to POEditor');
|
||||
}
|
||||
|
||||
this.logger.info({
|
||||
message: `${terms.length} new terms added to POEditor`,
|
||||
service: 'TranslationService',
|
||||
method: 'addTermsToPOEditor',
|
||||
response: response
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
this.logger.error({
|
||||
message: `Failed to add terms to POEditor: ${error.message}`,
|
||||
service: 'TranslationService',
|
||||
method: 'addTermsToPOEditor',
|
||||
stack: error.stack,
|
||||
terms: terms
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async syncTermsWithPOEditor() {
|
||||
try {
|
||||
const defaultFilePath = path.join(this.localesDir, 'default.json');
|
||||
const enTranslations = JSON.parse(fs.readFileSync(defaultFilePath, 'utf8'));
|
||||
const localTerms = Object.keys(enTranslations)
|
||||
.map(term => term);
|
||||
|
||||
const poeditorTerms = await this.getTermsFromPOEditor();
|
||||
|
||||
const newTerms = localTerms?.filter(term => !poeditorTerms?.includes(term));
|
||||
|
||||
|
||||
this.logger.info({
|
||||
message: `Comparison results - New terms found: ${newTerms.length}`,
|
||||
sampleNewTerms: newTerms.slice(0, 5),
|
||||
service: 'TranslationService',
|
||||
method: 'syncTermsWithPOEditor'
|
||||
});
|
||||
|
||||
if (newTerms.length > 0) {
|
||||
const formattedTerms = newTerms.map(term => ({
|
||||
[term]: enTranslations[term] || '',
|
||||
}));
|
||||
|
||||
await this.addTermsToPOEditor(formattedTerms);
|
||||
|
||||
} else {
|
||||
this.logger.info({
|
||||
message: 'No new terms found to synchronize',
|
||||
service: 'TranslationService',
|
||||
method: 'syncTermsWithPOEditor'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error({
|
||||
message: error.message,
|
||||
service: 'TranslationService',
|
||||
method: 'syncTermsWithPOEditor',
|
||||
stack: error.stack
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default TranslationService;
|
||||
@@ -1,145 +0,0 @@
|
||||
{
|
||||
"dontHaveAccount": "Don't have account",
|
||||
"email": "E-mail",
|
||||
"forgotPassword": "Forgot Password",
|
||||
"password": "password",
|
||||
"signUp": "Sign up",
|
||||
"submit": "Submit",
|
||||
"title": "Title",
|
||||
"continue": "Continue",
|
||||
"enterEmail": "Enter your email",
|
||||
"authLoginTitle": "Log In",
|
||||
"authLoginEnterPassword": "Enter your password",
|
||||
"commonPassword": "Password",
|
||||
"commonBack": "Back",
|
||||
"authForgotPasswordTitle": "Forgot password?",
|
||||
"authForgotPasswordResetPassword": "Reset password",
|
||||
"createPassword": "Create your password",
|
||||
"createAPassword": "Create a password",
|
||||
"authRegisterAlreadyHaveAccount": "Already have an account?",
|
||||
"commonAppName": "BlueWave Uptime",
|
||||
"authLoginEnterEmail": "Enter your email",
|
||||
"authRegisterTitle": "Create an account",
|
||||
"authRegisterStepOneTitle": "Create your account",
|
||||
"authRegisterStepOneDescription": "Enter your details to get started",
|
||||
"authRegisterStepTwoTitle": "Set up your profile",
|
||||
"authRegisterStepTwoDescription": "Tell us more about yourself",
|
||||
"authRegisterStepThreeTitle": "Almost done!",
|
||||
"authRegisterStepThreeDescription": "Review your information",
|
||||
"authForgotPasswordDescription": "No worries, we'll send you reset instructions.",
|
||||
"authForgotPasswordSendInstructions": "Send instructions",
|
||||
"authForgotPasswordBackTo": "Back to",
|
||||
"authCheckEmailTitle": "Check your email",
|
||||
"authCheckEmailDescription": "We sent a password reset link to {{email}}",
|
||||
"authCheckEmailResendEmail": "Resend email",
|
||||
"authCheckEmailBackTo": "Back to",
|
||||
"goBackTo": "Go back to",
|
||||
"authCheckEmailDidntReceiveEmail": "Didn't receive the email?",
|
||||
"authCheckEmailClickToResend": "Click to resend",
|
||||
"authSetNewPasswordTitle": "Set new password",
|
||||
"authSetNewPasswordDescription": "Your new password must be different from previously used passwords.",
|
||||
"authSetNewPasswordNewPassword": "New password",
|
||||
"authSetNewPasswordConfirmPassword": "Confirm password",
|
||||
"confirmPassword": "Confirm your password",
|
||||
"authSetNewPasswordResetPassword": "Reset password",
|
||||
"authSetNewPasswordBackTo": "Back to",
|
||||
"authPasswordMustBeAtLeast": "Must be at least",
|
||||
"authPasswordCharactersLong": "8 characters long",
|
||||
"authPasswordMustContainAtLeast": "Must contain at least",
|
||||
"authPasswordSpecialCharacter": "one special character",
|
||||
"authPasswordOneNumber": "one number",
|
||||
"authPasswordUpperCharacter": "one upper character",
|
||||
"authPasswordLowerCharacter": "one lower character",
|
||||
"authPasswordConfirmAndPassword": "Confirm password and password",
|
||||
"authPasswordMustMatch": "must match",
|
||||
"friendlyError": "Something went wrong...",
|
||||
"unknownError": "An unknown error occurred",
|
||||
"unauthorized": "Unauthorized access",
|
||||
"authAdminExists": "Admin already exists",
|
||||
"authInviteNotFound": "Invite not found",
|
||||
"unknownService": "Unknown service",
|
||||
"noAuthToken": "No auth token provided",
|
||||
"invalidAuthToken": "Invalid auth token",
|
||||
"expiredAuthToken": "Token expired",
|
||||
"noRefreshToken": "No refresh token provided",
|
||||
"invalidRefreshToken": "Invalid refresh token",
|
||||
"expiredRefreshToken": "Refresh token expired",
|
||||
"requestNewAccessToken": "Request new access token",
|
||||
"invalidPayload": "Invalid payload",
|
||||
"verifyOwnerNotFound": "Document not found",
|
||||
"verifyOwnerUnauthorized": "Unauthorized access",
|
||||
"insufficientPermissions": "Insufficient permissions",
|
||||
"dbUserExists": "User already exists",
|
||||
"dbUserNotFound": "User not found",
|
||||
"dbTokenNotFound": "Token not found",
|
||||
"dbResetPasswordBadMatch": "New password must be different from old password",
|
||||
"dbFindMonitorById": "Monitor with id ${monitorId} not found",
|
||||
"dbDeleteChecks": "No checks found for monitor with id ${monitorId}",
|
||||
"authIncorrectPassword": "Incorrect password",
|
||||
"authUnauthorized": "Unauthorized access",
|
||||
"monitorGetById": "Monitor not found",
|
||||
"monitorGetByUserId": "No monitors found for user",
|
||||
"jobQueueWorkerClose": "Error closing worker",
|
||||
"jobQueueDeleteJob": "Job not found in queue",
|
||||
"jobQueueObliterate": "Error obliterating queue",
|
||||
"pingCannotResolve": "No response",
|
||||
"statusPageNotFound": "Status page not found",
|
||||
"statusPageUrlNotUnique": "Status page url must be unique",
|
||||
"dockerFail": "Failed to fetch Docker container information",
|
||||
"dockerNotFound": "Docker container not found",
|
||||
"portFail": "Failed to connect to port",
|
||||
"alertCreate": "Alert created successfully",
|
||||
"alertGetByUser": "Got alerts successfully",
|
||||
"alertGetByMonitor": "Got alerts by Monitor successfully",
|
||||
"alertGetById": "Got alert by Id successfully",
|
||||
"alertEdit": "Alert edited successfully",
|
||||
"alertDelete": "Alert deleted successfully",
|
||||
"authCreateUser": "User created successfully",
|
||||
"authLoginUser": "User logged in successfully",
|
||||
"authLogoutUser": "User logged out successfully",
|
||||
"authUpdateUser": "User updated successfully",
|
||||
"authCreateRecoveryToken": "Recovery token created successfully",
|
||||
"authVerifyRecoveryToken": "Recovery token verified successfully",
|
||||
"authResetPassword": "Password reset successfully",
|
||||
"authAdminCheck": "Admin check completed successfully",
|
||||
"authDeleteUser": "User deleted successfully",
|
||||
"authTokenRefreshed": "Auth token is refreshed",
|
||||
"authGetAllUsers": "Got all users successfully",
|
||||
"inviteIssued": "Invite sent successfully",
|
||||
"inviteVerified": "Invite verified successfully",
|
||||
"checkCreate": "Check created successfully",
|
||||
"checkGet": "Got checks successfully",
|
||||
"checkDelete": "Checks deleted successfully",
|
||||
"checkUpdateTtl": "Checks TTL updated successfully",
|
||||
"monitorGetAll": "Got all monitors successfully",
|
||||
"monitorStatsById": "Got monitor stats by Id successfully",
|
||||
"monitorGetByIdSuccess": "Got monitor by Id successfully",
|
||||
"monitorGetByTeamId": "Got monitors by Team Id successfully",
|
||||
"monitorGetByUserIdSuccess": "Got monitor for ${userId} successfully",
|
||||
"monitorCreate": "Monitor created successfully",
|
||||
"monitorDelete": "Monitor deleted successfully",
|
||||
"monitorEdit": "Monitor edited successfully",
|
||||
"monitorCertificate": "Got monitor certificate successfully",
|
||||
"monitorDemoAdded": "Successfully added demo monitors",
|
||||
"queueGetMetrics": "Got metrics successfully",
|
||||
"queueAddJob": "Job added successfully",
|
||||
"queueObliterate": "Queue obliterated",
|
||||
"jobQueueDeleteJobSuccess": "Job removed successfully",
|
||||
"jobQueuePauseJob": "Job paused successfully",
|
||||
"jobQueueResumeJob": "Job resumed successfully",
|
||||
"maintenanceWindowGetById": "Got Maintenance Window by Id successfully",
|
||||
"maintenanceWindowCreate": "Maintenance Window created successfully",
|
||||
"maintenanceWindowGetByTeam": "Got Maintenance Windows by Team successfully",
|
||||
"maintenanceWindowDelete": "Maintenance Window deleted successfully",
|
||||
"maintenanceWindowEdit": "Maintenance Window edited successfully",
|
||||
"pingSuccess": "Success",
|
||||
"getAppSettings": "Got app settings successfully",
|
||||
"updateAppSettings": "Updated app settings successfully",
|
||||
"statusPageByUrl": "Got status page by url successfully",
|
||||
"statusPageCreate": "Status page created successfully",
|
||||
"newTermsAdded": "New terms added to POEditor",
|
||||
"dockerSuccess": "Docker container status fetched successfully",
|
||||
"portSuccess": "Port connected successfully",
|
||||
"monitorPause": "Monitor paused successfully",
|
||||
"monitorResume": "Monitor resumed successfully"
|
||||
}
|
||||
Reference in New Issue
Block a user