fix: remove fetch requests
This commit is contained in:
1 parent
158a3f14ea
commit
7b6eed96f4
6 files changed
+6
-450
No files matched your search
@@ -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;
|
||||
Reference in new issue
Block a user