Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

48 Zeilen
1.5 KiB

vor 3 Jahren
  1. /*
  2. * A tool for deleting pads from the CLI, because sometimes a brick is required
  3. * to fix a window.
  4. */
  5. const request = require('../src/node_modules/request');
  6. const settings = require(`${__dirname}/../tests/container/loadSettings`).loadSettings();
  7. const supertest = require(`${__dirname}/../src/node_modules/supertest`);
  8. const api = supertest(`http://${settings.ip}:${settings.port}`);
  9. const path = require('path');
  10. const fs = require('fs');
  11. if (process.argv.length != 3) {
  12. console.error('Use: node deletePad.js $PADID');
  13. process.exit(1);
  14. }
  15. // get the padID
  16. const padId = process.argv[2];
  17. // get the API Key
  18. const filePath = path.join(__dirname, '../APIKEY.txt');
  19. const apikey = fs.readFileSync(filePath, {encoding: 'utf-8'});
  20. // Set apiVersion to base value, we change this later.
  21. let apiVersion = 1;
  22. // Update the apiVersion
  23. api.get('/api/')
  24. .expect((res) => {
  25. apiVersion = res.body.currentVersion;
  26. if (!res.body.currentVersion) throw new Error('No version set in API');
  27. return;
  28. })
  29. .end((err, res) => {
  30. // Now we know the latest API version, let's delete pad
  31. const uri = `/api/${apiVersion}/deletePad?apikey=${apikey}&padID=${padId}`;
  32. api.post(uri)
  33. .expect((res) => {
  34. if (res.body.code === 1) {
  35. console.error('Error deleting pad', res.body);
  36. } else {
  37. console.log('Deleted pad', res.body);
  38. }
  39. return;
  40. })
  41. .end(() => {});
  42. });
  43. // end