Jump to content

kaotkbliss

Active Members
  • Posts

    2,672
  • Joined

  • Last visited

1 Follower

About kaotkbliss

  • Birthday 07/19/1977

Profile Information

  • Location
    USA

Recent Profile Visitors

1,160 profile views

kaotkbliss's Achievements

  1. Managed to figure this out async function somename (parameters) { promise = new Promise((resolve, reject)=> { do stuff; resolve (return val); }; complete = await promise; }; async function somename2 (parameters) { promise = new Promise((resolve, reject)=> { do stuff; resolve (return val); }; complete = await promise; }; let getSomename = async (parameters, newParameters) => { await somename(parameters); await somename(newParameters); return (some val); }; let getSomename2 = async (parameters, newParameters) => { await somename2(parameters); await somename2(newParameters); return (some val); }; getSomename(parameters, newParameters).then((onReturn) => { getSomename2(parameters, newparameters).then((onReturn) => { do stuff; }) })
  2. I have to functions, each return a promise. I need to execute the first function 2x, then when it's done, execute the 2nd function 2x currently it's set up in this format async function somename (parameters) { promise = new Promise((resolve, reject)=> { do stuff; }; complete = await promise; }; async function somename2 (parameters) { promise = new Promise((resolve, reject)=> { do stuff; }; complete = await promise; }; somename(parameters).then((onReturn) => { somename(newparameters).then((onReturn) => { somename2(parameters).then((onReturn) => { somename2(newparameters).then((onReturn) => { do stuff; }) }) }) }) Ideally I'd like to just call the first function 2x, then wait for both to finish, then call the next one 2x and wait for both of those to finish. That way each pair of functions is running at the same time.
  3. So the problem with the hash is that the software we use that outputs pdfs doesn't create them binarily (is that a word?) identical using the same variables so each time a pdf is created it gets a new hash. I was able to get around this by using the pdf2json module and grabbing the rasterization of each page, then comparing each array from both pdfs.
  4. I started on a different route by using the http module to "download" the file to where I could use __dirname + /somepath then work with it from there. But now I'm having issues with trying to get the file hash/checksum I have a control pdf, which is the result of test variables being plugged into the app. whenever changes are made to the app, the new pdf with the same variables plugged in should still be exactly the same as the control pdf I've been messing around with crypto, but that seems to include the filename and the path in the hash it generates for the file, so it never matches. Also, when I changed 1 variable and created a new pdf, it's hash doesn't change, although I'm pretty sure it should since the contents of the pdf changed.
  5. We make a lot of apps with a web page interface for various departments in the company to use. When writing or making changes to an app, we usually run the server code locally for testing changes. My boss wants me to automate this process by using Postman to send a set group of variables to the locally running server code, then compare the returned pdf with a control pdf to make sure they are still identical. Since the server code is running locally, it's hosted on "localhost:port" but javascript can't read a file at a path "localhost:port//somename.pdf" so I need to convert localhost:port to the absolute path where the local server script is actually running. Is there a way to do this?
  6. Talk about getting this in just under the wire. Right at closing time today. I don't have the code on me, but I did manage to solve the issue
  7. I just realized I had accidentally left in an extra }; towards the end of my plugin. Although that still doesn't change that I can't perform if/else loops or any other code in the web page based on the success return of the plugin
  8. We have a small function we use in our server code to periodically send messages to a web page interface to notify the user of key steps in the process. This is in the form of function sendMsg(body, flag = null) { ws.send(JSON.stringify({ body: body, flag: flag })); } where body is the information and the flag is the type of message I'm trying to make the receiving of the messages a jQuery plugin and where I'm having an issue. It does all the processing it's supposed to do but I can't get it to return data back to the web page for me to grab. //create websocket (endpoint as argument) (function ( $ ) { $.MakeSocket = function( options ) { settings = $.extend({ // These are the defaults. endpoint: '', data : '', success : {}, error : {}, open : {}, exit : {} }, options ); var wsURI; if (window.location.protocol === "https:") { wsURI = "wss:"; } else { wsURI = "ws:"; } wsURI += "//" + window.location.host; wsURI += window.location.pathname + settings.endpoint; var socket = new WebSocket(wsURI); socket.onopen = function() { settings.open = {body: null, flag: 'OPEN'}; } socket.onmessage = function( event ) { var json = JSON.parse(event.data); if (json.flag === 'DATA') { socket.send(JSON.stringify({ results : settings.data, flag : 'DATA', })); } else if (json.flag === 'COMP') { console.log('<Comp>', json); settings.success = json; socket.close(); } else { console.log('<Info>', json); settings.success = json; //callback( settings ); }; } socket.onerror = function(event) { settings.error = {body: event, flag: 'ERR'}; } socket.onclose = function() { console.log('Close called'); settings.exit = {body: null, flag: 'EXIT'}; } }; }; }( jQuery )); What this does is creates a websocket, then processes our message flags for the webpage And we want to be able to call the websocket and message processing like so: $.MakeSocket({ endpoint : "Process", data : data, success : function (wsData) { console.log('<wsData>', wsData); } }); so that we can perform functions based on if the result is a success, what type of success, error, ect. (Just like the ajax post method for jquery) Problem is I can't seem to get any return value from the plugin to use in the webpage.
  9. I ended up going a different route. To actually do what I need to do later with the records I'm using a different dbf module and while it's helpfile didn't say anything about it, I found where it does in fact log the number of records in it's processing so I was able to use that.
  10. I'm using this node module, dbffile to try and get a count of records in a database. I want to modify their existing example: DBFFile.open('[full path to .dbf file]') .then(dbf => { console.log(`DBF file contains ${dbf.recordCount} rows.`); console.log(`Field names: ${dbf.fields.map(f => f.name)}`); return dbf.readRecords(100); }) .then(rows => rows.forEach(row => console.log(row))) .catch(err => console.log('An error occurred: ' + err)); to just simply return the dbf.recordCount to be used later in the script. if I do: DBFFile.open(dbfFilePath + '/' + csvData.DATANAME) .then(dbf => { qty = dbf.recordCount; }) .catch(err => console.log('An error occurred: ' + err)); I simply get "undefined" later in my script. If I try: qty = DBFFile.open(dbfFilePath + '/' + csvData.DATANAME) .then(dbf => { return dbf.recordCount; }) .catch(err => console.log('An error occurred: ' + err)); Then I get Promise {pending}
  11. update, got a fix from my manager. I was close when I tried to use the first ajax call (the top script) I just needed to change data : $("#form8125").serialize(), to data: new FormData($('#lithoform')[0]), contentType: false, and processData: false so close at one point.
  12. Just to add, The first thing I tried was to copy the first HTML script and just change the # tags to the appropriate form, but then the server side gave me an error like "filename is not a known property of unknown file" or something along those lines. So all the object's properties are either moved or removed (I can't tell which because using util.inspect(req) or util.inspect(req.body) returns so much information I can't find where the information might have been stored. Which it probably never made it over. Also to add, I've googled variations of multer + ajax and tried pretty much every variation of the code I could find but it either broke the upload like above or the response loaded a new page, clearing any of the form that might have already been filled out.
  13. I've just started learning nodejs for work and I've been tasked with making a webform that will send the form information to our GMC Inspire application to automatically fill out US postal forms and return the completed pdf. Everything is working great except now they want to be able to upload a partially filled out pdf and just fill in the rest. I can get the file to upload and use it, but after the upload, the html waits for a response from the server and if they wait too long to fill out the rest of the form and generate their pdf, the site will time-out. If I have the server send a response, then the site navigates away from the current page, losing all the other information filled out in the form. I have a bootstrap alert box I use to return errors from the server and wanted to use that to send the response to so the page doesn't refresh and gets a response so it doesn't time-out. Problem is, when I add the ajax script, it breaks the information needed to process the uploaded pdf. HTML where the upload is defined <button type="submit" name="8125" id="8125" class="btn btn-primary">Generate</button> <div class="alert alert-danger" role="alert" id="8125box" onclick="$('.alert').hide()"> <div id="8125text" style="word-break: break-all"></div> </div> </div> </form> <form action="/upload" method="post" enctype="multipart/form-data" id="lithoform" name="lithoform"> <input type="file" name="litho" id="litho" /> <input type="submit" value="Upload" id="lithobtn" name="lithobtn" /> </form> </div> HTML script that's supposed to upload the pdf so I can return a response to the alert box (the top script is the working script for the form, the bottom script is one of the many attempts to do the same with the pdf upload) <script> $(document).ready(function() { $("#8125").click(function(e) { e.preventDefault(); $("body").css("cursor", "progress"); $("#8125").prop("disabled", true); $('#3606box').hide(); $('#8125box').hide(); $.ajax({ type : 'POST', url : '/8125', data : $("#form8125").serialize(), dataType : 'json', success : function(data) { console.log(data); // data: { err: NULL, results: { filePath: ... } } window.open(data.results.filePath, '_blank'); $("#8125").prop("disabled", false); $("body").css("cursor", "default"); }, error : function (jqXHR, textStatus, errorThrown) { // jqXHR.responseJSON: { err: err, results: NULL } // Bootstrap Alert: //$("#8125text").html(jqXHR.responseJSON.err); $("#8125text").html('ERROR ' + jqXHR.responseText); $("#8125box").show(); $("#8125").prop("disabled", false); $("body").css("cursor", "default"); } }); }); }); </script> <script> $(document).ready(function() { var options = { beforeSubmit: showRequest, // pre-submit callback success: showResponse // post-submit callback }; console.log('did it make it here?'); // bind to the form's submit event $("#lithoform").submit(function () { $(this).ajaxSubmit(options); // always return false to prevent standard browser submit and page navigation return false; }); }); // pre-submit callback function showRequest(formData, jqForm, options) { alert('Uploading is starting.'); return true; } // post-submit callback function showResponse(responseText, statusText, xhr, $form) { alert('status: ' + statusText + '\n\nresponseText: \n' + responseText ); } </script> The nodejs server parts of the code to handle the upload var express = require('express'); var app = express(); var path = require('path'); var fs = require('fs'); var bodyParser = require('body-parser'); var child_process = require('child_process') const homedir = require('os').homedir(); const openurl = require('openurl'); const util = require('util'); var multer = require('multer') outPut = 'public/srv'; lithoLoc = path.join(outPut,'uploads'); var litho = null; var storage = multer.diskStorage({ destination: function(req, file, callback) { callback(null, lithoLoc) }, filename: function(req, file, callback) { callback(null, file.originalname) } }); var upload = multer({storage: storage}); app.post('/upload', upload.single('litho'), function (req, res, next) { res.end("File is uploaded"); litho = req.file.filename; // req.file is the `litho` file // req.body will hold the text fields, if there were any });
  14. I ended up using the MS gui for robocopy but so far everything looks good. Got Win10 installed fresh from usb (didn't need to go through xp and 7 install) and it activated fine. So far it seems to be running normal with programs getting put in the start menu as they should, NVidia GeForce experience working as it should, etc.
  15. You've been extremely helpful with all of this thank you yet again!
×
×
  • Create New...