Skip to content

Commit

Permalink
use a deletePad approach that works when server is running and works …
Browse files Browse the repository at this point in the history
…with MySQL
  • Loading branch information
JohnMcLear authored and muxator committed Apr 3, 2020
1 parent 93180c2 commit cdf5b63
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions bin/deletePad.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
* to fix a window.
*/

const request = require('../src/node_modules/request');
const settings = require(__dirname+'/../tests/backend/loadSettings').loadSettings();
const supertest = require(__dirname+'/../src/node_modules/supertest');
const api = supertest('http://'+settings.ip+":"+settings.port);
const path = require('path');
const fs = require('fs');
if (process.argv.length != 3) {
console.error("Use: node deletePad.js $PADID");
process.exit(1);
Expand All @@ -11,31 +17,34 @@ if (process.argv.length != 3) {
// get the padID
let padId = process.argv[2];

let npm = require('../src/node_modules/npm');
// get the API Key
var filePath = path.join(__dirname, '../APIKEY.txt');
var apikey = fs.readFileSync(filePath, {encoding: 'utf-8'});

// Set apiVersion to base value, we change this later.
var apiVersion = 1;

// Update the apiVersion
api.get('/api/')
.expect(function(res){
apiVersion = res.body.currentVersion;
if (!res.body.currentVersion) throw new Error("No version set in API");
return;
})
.end(function(err, res){

// Now we know the latest API version, let's delete pad
var uri = '/api/'+apiVersion+'/deletePad?apikey='+apikey+'&padID='+padId;
api.post(uri)
.expect(function(res){
if (res.body.code === 1){
console.error("Error deleting pad", res.body);
}else{
console.log("Deleted pad", res.body);
}
return;
})
.end(function(){})
});
// end

npm.load({}, async function(er) {
if (er) {
console.error("Could not load NPM: " + er)
process.exit(1);
}

try {
let settings = require('../src/node/utils/Settings');
let db = require('../src/node/db/DB');
await db.init();

padManager = require('../src/node/db/PadManager');
await padManager.removePad(padId);

console.log("Finished deleting padId: " + padId);
process.exit(0);

} catch (e) {
if (err.name === "apierror") {
console.error(e);
} else {
console.trace(e);
}
process.exit(1);
}
});

0 comments on commit cdf5b63

Please sign in to comment.