Skip to content

Commit

Permalink
deprecate post
Browse files Browse the repository at this point in the history
  • Loading branch information
bajzarpa committed Nov 3, 2020
1 parent 4690a81 commit 4ceebe9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 98 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,18 @@ Output example:
}
```

### post
### post (deprecated)

`npm run post` - uploads the _./upload.json_ file.
~~.`npm run post` - uploads the _./upload.json_ file.~~

* try to combine the labels into one big item (_./examples/upload-bfc-season-combined_)
* if you want to upload into different groups then the uploader will
do it in parallel requests. __This MAY KILL the cms api__.
~~* try to combine the labels into one big item (_./examples/upload-bfc-season-combined_)~~
~~* if you want to upload into different groups then the uploader will~~
~~do it in parallel requests. __This MAY KILL the cms api__.~~

### delete
### delete (deprecated)
~~.`npm run delete` - use the _./delete.json_ file.~~

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

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

### get-everything

Expand Down
90 changes: 1 addition & 89 deletions src/post.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,2 @@
/* global cat:false, cp:false, mkdir:false */
// uses upload.json
require('shelljs/global');
const shelljs = require('shelljs');
const request = require('request-promise');
require('colors');
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 ||
(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) {
console.error(`JSON parse error. Is "${fileName}" a valid json?`, err);
process.exit(1);
}

if (!input.length) {
console.error('Payload is not an array?'.red.bold);
process.exit(1);
}

function upload (uri, count) {
for (let i = 0, l = input.length; i < l; i++) {
const body = input[i];
const id = body.Items ? Object.keys(body.Items)[0] : '?';
const tfsId = String(body.TaskId || 0).replace(/[^\d]/g, '');
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
);
shelljs.config.silent = true;
if (isDeleteKeys) return;
mkdir(backupDir);
let target = `${backupDir}/${now}_#${tfsId}_${fileName}`;
if (count === 0) {
cp(fileName, target);
console.log(`File backed up to ${target}`);
}
})
.catch(err => {
console.log(
`Upload failed to ${environment}: ${i + 1}. [${id}] - Err: ${
err.response.statusCode
}`.bold.red
);
});
}
}

const startTime = Date.now();
async function run (uri, count) {
if (uris.length > 1) {
console.info(`Uploading to ${uris.length} url(s)`);
}
for (let i = 0, l = uris.length; i < l; i++) {
await upload(uris[i], i);
}
const time = (Date.now() - startTime) / 1000;
console.log(`Uploaded ${inputSize}b in ${time}s`);
}

run();
console.error('sf-label-manager is deprecated. please use the internal tool instead'.red.bold);

0 comments on commit 4ceebe9

Please sign in to comment.