AdGuardHome/scripts/translations/upload.js

45 lines
990 B
JavaScript
Raw Normal View History

const path = require('path');
const fs = require('fs');
const request = require('request-promise');
const LOCALES_DIR = '../../client/src/__locales';
2019-07-18 18:35:23 +03:00
const BASE_FILE = 'en.json';
const LANGUAGE = 'en';
const TWOSKY_URI = process.env.TWOSKY_URI;
const TWOSKY_PROJECT_ID = 'home';
/**
* Prepare post params
*/
2019-07-18 18:35:23 +03:00
const getRequestData = (url, projectId) => {
const formData = {
2019-07-18 18:35:23 +03:00
format: 'json',
language: LANGUAGE,
filename: BASE_FILE,
project: projectId,
file: fs.createReadStream(path.resolve(LOCALES_DIR, `${LANGUAGE}.json`)),
};
2019-07-18 18:35:23 +03:00
return {
url: `${url}/upload`,
formData
};
};
/**
2019-07-18 18:35:23 +03:00
* Make request to twosky to upload new json
*/
const upload = () => {
2019-07-18 18:35:23 +03:00
if (!TWOSKY_URI) {
console.error('No credentials');
return;
}
const { url, formData } = getRequestData(TWOSKY_URI, TWOSKY_PROJECT_ID);
request
.post({ url, formData })
.catch(err => console.log(err));
};
upload();