Skip to content

Commit

Permalink
delete method added
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbert Fodor authored and Norbert Fodor committed Oct 24, 2019
1 parent da4e36a commit a73dc23
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ daily
.env
uploaded-jsons
rename.json
delete.json
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Output example:
* if you want to upload into different groups then the uploader will
do it in parallel requests. __This MAY KILL the cms api__.

### delete

`npm run delete` - use the _./delete.json_ file.

* read label keys from delete.json and try to delete all labels

### get-everything

`npm run get-everything` - download all defined groups.
Expand Down
6 changes: 6 additions & 0 deletions delete.json.exmple
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"ClassId": "WizzBookingFlowResources",
"Keys": ["demo-pass-enter-email", "demo-pass-buy-promo-line-1", "demo-pass-buy-promo-line-2"]
}
]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"get": "node src/get.js",
"post": "node src/post.js",
"rename": "cross-env OPERATION=rename node src/post.js",
"delete": "cross-env OPERATION=delete node src/post.js",
"get-everything": "shx rm -rf output && shx mkdir output && node src/get-everything",
"daily-backup": "node src/get-everything daily all-langs",
"postinstall": "shx mkdir -p daily",
Expand Down
37 changes: 30 additions & 7 deletions src/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ const config = require('./config');
const uris = config.api.split(',').map(s => s + '/labels');

const rename = process.env.OPERATION === 'rename';
const isDeleteKeys = process.env.OPERATION === 'delete';
const backupDir = 'uploaded-jsons';
const fileName = process.env.UPLOAD_FILE_NAME || (rename ? 'rename.json' : 'upload.json');
const now = (new Date()).toISOString().substring(0, 19).replace('T', '_').replace(/:/g, '-');
const method = rename ? 'PUT' : 'POST';
const fileName =
process.env.UPLOAD_FILE_NAME ||
(isDeleteKeys ? 'delete.json' : rename ? 'rename.json' : 'upload.json');
const now = new Date()
.toISOString()
.substring(0, 19)
.replace('T', '_')
.replace(/:/g, '-');
const method = isDeleteKeys ? 'DELETE' : rename ? 'PUT' : 'POST';

let input = cat(fileName);
const inputSize = input.length;

try {
input = JSON.parse(input);
} catch (err) {
Expand All @@ -35,10 +43,21 @@ function upload (uri, count) {
delete body.TaskId; // not yet implemented in the api
const environment = uri.split('.')[1];
console.log(`Uploading to ${environment}.... please wait!`.grey);
return request({method, uri, body, json: true, rejectUnauthorized: false, timeout: config.timeout})
.then((result) => {
console.log(`Uploaded to ${environment}: ${i + 1}. (out of ${l}) - Result: ${JSON.stringify(result)}`.green.bold);
return request({
method,
uri,
body,
json: true,
rejectUnauthorized: false,
timeout: config.timeout
})
.then(result => {
console.log(
`Uploaded to ${environment}: ${i +
1}. (out of ${l}) - Result: ${JSON.stringify(result)}`.green.bold
);
shelljs.config.silent = true;
if (isDeleteKeys) return;
mkdir(backupDir);
let target = `${backupDir}/${now}_#${tfsId}_${fileName}`;
if (count === 0) {
Expand All @@ -47,7 +66,11 @@ function upload (uri, count) {
}
})
.catch(err => {
console.log(`Upload failed to ${environment}: ${i + 1}. [${id}] - Err: ${err.response.statusCode}`.bold.red);
console.log(
`Upload failed to ${environment}: ${i + 1}. [${id}] - Err: ${
err.response.statusCode
}`.bold.red
);
});
}
}
Expand Down

0 comments on commit a73dc23

Please sign in to comment.