request(BASEURI + '/cgi-bin/ptz.cgi?action=' + action + '&channel=0&code=' + direction + '&arg1=' + speed +'&arg2=' + speed + '&arg3=0', function (error, response, body) { if ((error) || (response.statusCode !== 200) || (body.trim() !== "OK")) { self.emit("error", 'FAILED TO ISSUE PTZ UP COMMAND'); } }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/snapshot.cgi?' + options.channel , function (error, response, body) { if ((error) || (response.statusCode !== 200)) { self.emit("error", 'ERROR ON SNAPSHOT'); } }) .on('end',function(){ if(TRACE) console.log('SNAPSHOT SAVED'); self.emit("getSnapshot", { 'status':'DONE',}); }) .auth(USER,PASS,false).pipe(fs.createWriteStream(path.join(options.path,options.filename)));
request(BASEURI + '/cgi-bin/mediaFileFind.cgi?action=factory.create', function (error, response, body) { if ((error)) { self.emit("error", 'ERROR ON CREATE FILE FIND COMMAND'); } // stripping 'result=' and returning the object ID var oid = body.trim().substr(7); self.emit("fileFinderCreated",oid); }).auth(USER,PASS,false);
downloadAuth(options, username, password, file, sha, installer) { let stream = fs.createWriteStream(file); this.downloads.set(stream.path, {installer, options, username, password, sha, 'failure': false, currentSize : 0}); this.root = this.root.then(() => { return new Promise((resolve)=>{ request.get(this.setAdditionalOptions(options)) .auth(username, password) .on('error', this.errorHandler.bind(this, stream)) .on('error', resolve) .on('response', this.responseHandler.bind(this, installer)) .on('data', this.dataHandler.bind(this, file)) .on('end', this.endHandler.bind(this, stream)) .pipe(stream) .on('close', this.closeHandler.bind(this, stream.path, sha, options)) .on('close', resolve); }); }); return this.root; }
function getFile(path) { var url = 'https://down.jottacloud.com/jfs/' + config.username + '/' + encodeURI(path) + '?mode=bin'; var target = path.substring(path.lastIndexOf('/')+1).replace(/((\?|#).*)?$/,''); console.log('Downloading: ' + path); console.log('Saving to: ' + target); var options = { url: url, headers: { 'User-Agent': 'node-jfs https://github.com/paaland/node-jfs' } }; request .get(options) .auth(config.username, config.password, true) .on('error', function(err) { console.error(err) }) .on('response', function(response) { console.log(response.statusCode) // 200 }) .pipe(fs.createWriteStream(target)); }
// console.log(url); request(url, function (error, response, body) { if ((error)) { if (TRACE) console.log('startFileFind Error:',error); self.emit("error", 'FAILED TO ISSUE FIND FILE COMMAND'); } else { if (TRACE) console.log('startFileFind Response:',body.trim()); // no results = http code 400 ? //if(response.statusCode == 400 ) { // self.emit("error", 'FAILED TO ISSUE FIND FILE COMMAND - NO RESULTS ?'); //} else { // self.emit('startFileFindDone',objectId,body.trim()); //} } }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/mediaFileFind.cgi?action=findNextFile&object=' + objectId + '&count=' + count, function (error, response, body) { if ((error) || (response.statusCode !== 200)) { if (TRACE) console.log('nextFileFind Error:',error); self.emit("error", 'FAILED NEXT FILE COMMAND'); } // if (TRACE) console.log('nextFileFind Response:',body.trim()); var items = {}; var data = body.split('\r\n'); // getting found count items.found = data[0].split("=")[1]; // parsing items data.forEach(function(item){ if(item.startsWith('items[')) { var propertyAndValue = item.split("="); setKeypath(items, propertyAndValue[0], propertyAndValue[1]); } }); self.emit('nextFileFindDone',objectId,items); }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1', function (error, response, body) { if ((!error) && (response.statusCode === 200)) { if (body === 'Error') { // Didnt work, lets try another method for older cameras request(BASEURI + '/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[0].NightOptions.SwitchMode=0', function (error, response, body) { if ((error) || (response.statusCode !== 200)) { self.emit("error", 'FAILED TO CHANGE TO DAY PROFILE'); } }).auth(USER,PASS,false); } } else { self.emit("error", 'FAILED TO CHANGE TO DAY PROFILE'); } }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/ptz.cgi?action=getStatus', function (error, response, body) { if ((!error) && (response.statusCode === 200)) { body = body.toString().split('\r\n'); self.emit("ptzStatus", body); } else { self.emit("error", 'FAILED TO QUERY STATUS'); } }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/mediaFileFind.cgi?action=close&object=' + objectId, function (error, response, body) { if ((error) || (response.statusCode !== 200) || (body.trim() !== "OK")) { self.emit("error", 'ERROR ON CLOSE FILE FIND COMMAND'); } self.emit('closeFileFindDone',objectId,body.trim()); }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&arg1=0&arg2=' + preset + '&arg3=0', function (error, response, body) { if ((error) || (response.statusCode !== 200) || (body.trim() !== "OK")) { self.emit("error", 'FAILED TO ISSUE PTZ PRESET'); } }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/ptz.cgi?action=start&channel=0&code=' + cmd + '&arg1=0&arg2=' + multiple + '&arg3=0', function (error, response, body) { if ((error) || (response.statusCode !== 200) || (body.trim() !== "OK")) { self.emit("error", 'FAILED TO ISSUE PTZ ZOOM'); } }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/mediaFileFind.cgi?action=destroy&object=' + objectId, function (error, response, body) { if ((error) || (response.statusCode !== 200) || (body.trim() !== "OK")) { self.emit("error", 'ERROR ON DESTROY FILE FIND COMMAND'); } self.emit('destroyFileFindDone',objectId,body.trim()); }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/ptz.cgi?action=start&channel=0&code=' + ptzcommand + '&arg1=' + arg1 + '&arg2=' + arg2 + '&arg3=' + arg3 + '&arg4=' + arg4, function (error, response, body) { if ((error) || (response.statusCode !== 200) || (body.trim() !== "OK")) { self.emit("error", 'FAILED TO ISSUE PTZ COMMAND'); } }).auth(USER,PASS,false);
request(BASEURI + '/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=2', function (error, response, body) { if ((!error) && (response.statusCode === 200)) { if (body === 'Error') { // Didnt work, lets try another method for older cameras request(BASEURI + '/cgi-bin/configManager.cgi?action=setConfig&VideoInOptions[0].NightOptions.SwitchMode=3', function (error, response, body) { if ((error) || (response.statusCode !== 200)) { self.emit("error", 'FAILED TO CHANGE TO NIGHT PROFILE'); } }).auth(USER,PASS,false); } } else { self.emit("error", 'FAILED TO CHANGE TO NIGHT PROFILE'); } }).auth(USER,PASS,false);