Chrome Extensions: Using a Local PHP file - google-chrome-extension

My Popup.js is passing a value to my local php file for processing then the results are displayed on popup.html as shown below:
$.get("get_charities.php", {scope: "ALL", m_val: formatted_val},function(charity_arr){
$('#convertor_content .result').remove();
console.log(charity_arr);
for(var i in charity_arr){
$('#convertor_content').append( "Enough to "+ charity_arr[i].pre_text+" <a href='" + charity_arr[i].url + "' target='_blank'>" + Math.round(charity_arr[i].impact_value) + " " + charity_arr[i].post_text + "</a>" + "<br>" + "<hr>" );
}
});
Since I am using a local php file, how do I test if my popup.html is working correctly?

Related

Web Server saving images as 0 bytes

When I send an image to my web server through an http request, it manages to save the original image with its full size. But when I attempt to resize the image, it saves it as 0 bytes. Im using an npm module called sharp to do the image resizing. When I do any resizing, even massive resizing jobs on my local machine, there are no issues. Running this code on my Apache web server causes it to not actually save the images most of the time. It seems completely random which images it actually saves. The only consistent part is that it saves the original image sent through the http request.
In my filesystem there will be the original image EG: abcdefg.jpg, and then abcdefg-350x350.jpg will be 0 bytes.
const results = await temp.mv(path.resolve(folderName + name + '.' + extension))
bluebird.map(sizes, (size) => {
sharp(folderName + name + '.' + extension)
.resize(size.w, size.h, {
fit: 'cover'
})
.toFile(folderName + name + '-' + size.w + 'x' + size.h + '.' + extension)
console.log('Resized image')
})
.then(() => {
console.log('Images were resized')
if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'testing') {
console.log('Images resized and going back');
res.status(200).json({'location': '/imageserving/uploads/' + year + '/' + month + '/' + name + '.' + extension, fileIndex: '1'});
}
else if (process.env.NODE_ENV === 'production') {
//possibly use req.hostname
res.status(200).json({'location': 'mysite/uploads/' + year + '/' + month + '/' + name + '.' + extension, fileIndex: '1'});
}
})
Try updating this line:
sharp(folderName + name + '.' + extension)
to this:
return sharp(folderName + name + '.' + extension)
...that should make sure the following then() section is properly chained to the promise and avoids potential race conditions that may be causing the inconsistent behavior.

Office.context.mailbox.item.addFileAttachmentAsync The code worked correctly. Why an internal error has occurred?

Previously the code worked correctly. Why an internal error has occurred?
Is this a problem with the JavaScript API for Office?
https://learn.microsoft.com/en-us/outlook/add-ins/add-and-remove-attachments-to-an-item-in-a-compose-form
The link and title are correct. I checked it out.
var options = {
asyncContext: null
};
Office.context.mailbox.item.addFileAttachmentAsync(link, title, options, function (asyncResult) {
console.log("asyncResult: " + JSON.stringify(asyncResult));
if (asyncResult.status === "succeeded") {
$docName.prepend("<i class='ms-Icon ms-Icon--checkbox ms-font-m ms-fontColor-green'>");
$fileProcess.resolve();
} else {
console.log("Office.context.mailbox.item.addFileAttachmentAsync() [" + asyncResult.status + "] error: "//
+ JSON.stringify(asyncResult.error) + " value: " + JSON.stringify(asyncResult.value));
$fileProcess.reject();
$attachedDoc.addClass("ms-bgColor-error");
$docName.prepend("<i class='ms-Icon ms-Icon--alert ms-font-m ms-fontColor-error'></i>");
$docName.after("<div class='ms-ListItem-tertiaryText addedError'>" + asyncResult.error.message + "</div>");
}
});
I got an asyncResult:
asyncResult: {"value":null,"status":"failed","error":{"name":"Internal Error","message":"An internal error has occurred."}}
The problem was with a self-signed certificate.

fs.rename not operative, however original and target name paths seem correct

I am using Node.js and Multer to upload some image files to an "uploads" folder. That part seems to be working fine. I wish to rename the files after uploading so the proper file extensions (.jpg, .png, .gif, etc) are appended to the filenames.
I am attempting to use 'fs.rename' to accomplish this however it fails. I receive no errors...and the 'original' path and the 'target' path to rename seem to be correct when I examine my console logs. My code is below...does anybody have an explanation for this? This is very confusing, I thank you in advance.
//A means of ensuring only images are uploaded.
//note 'files' is an array of image files, omitted for clarity
var len = files.length;
var i;
for (i = 0; i < len; i++) {
if (files[i] != "undefined") {
const host = req.hostname;
const filePath = req.protocol + "://" + host + '/' + files[i].path;
const image = files[i].mimetype.startsWith('image/');
const type = files[i].mimetype.toString();
if(image) {
console.log('photo #' + i + ' uploaded');
console.log('uploaded file: ' + files[i].filename + ' saved within: ' + files[i].destination + ' at path: ' + files[i].path);
console.log('photo #' + i + ' filepath: ' + filePath);
console.log('photo #' + i + ' image extension is: ' + type);
console.log('photo #' + i + ' TYPEOF is: ' + typeof type);
var cutoff = type.split("/"); //"split" on "backslash"
var oldPath = req.protocol + "://" + host + ':8080' + '/uploads/' + files[i].filename
var targetPath = req.protocol + "://" + host + ':8080' + '/uploads' + '/image' + i + "." + cutoff[1]
console.log('photo #' + i + ' cutoff: ' + cutoff[1]);
console.log('ORIGINAL path for photo #' + i + ' is: ' + oldPath);
console.log('RENAMED target path for photo #' + i + ' is: ' + targetPath);
fs.rename(oldPath, targetPath, function(err) {
if (err) {
console.log("Unable to rename photo #" + i + " file...!")
} else {
console.log("Successfully renamed the file!")
}
})
// ...save filePath to database...if desired...
} else {
console.log("file # " + i + " received--however wrong format");
}
} //if NOT 'undefined'
} //for loop
Here is the output of a run to show the console logs:
photo #0 uploaded
uploaded file: identification-1572752074000 saved within: ./uploads at path: uploads\identification-1572752074000
photo #0 filepath: http://localhost/uploads\identification-1572752074000
photo #0 image extension is: image/jpeg
photo #0 TYPEOF is: string
photo #0 cutoff: jpeg
ORIGINAL path for photo #0 is: http://localhost:8080/uploads/identification-1572752074000
RENAMED target path for photo #0 is: http://localhost:8080/uploads/image0.jpeg
photo #1 uploaded
uploaded file: identification-1572752074015 saved within: ./uploads at path: uploads\identification-1572752074015
photo #1 filepath: http://localhost/uploads\identification-1572752074015
photo #1 image extension is: image/jpeg
photo #1 TYPEOF is: string
photo #1 cutoff: jpeg
ORIGINAL path for photo #1 is: http://localhost:8080/uploads/identification-1572752074015
RENAMED target path for photo #1 is: http://localhost:8080/uploads/image1.jpeg
Unable to rename photo #2 file...!
Unable to rename photo #2 file...!
The other strange thing is the loop advances to 'photo #2'...which should not be since there are only 2 images in the 'files' array ('0' and '1')...not sure if that is related to my problem here. Thanks for any suggestions.
You are passing URLs to fs.rename(). It requires local OS file paths, not URLs.
I don't know exactly where things are in your local file system or if they even are in your local file system, but you could try changing this:
var oldPath = req.protocol + "://" + host + ':8080' + '/uploads/' + files[i].filename
var targetPath = req.protocol + "://" + host + ':8080' + '/uploads' + '/image' + i + "." + cutoff[1]
to this:
var oldPath = '/uploads/' + files[i].filename
var targetPath = '/uploads' + '/image' + i + "." + cutoff[1]
Assuming the /uploads directory is on the local file system and the /uploads/image directory already exists.

Phonegap barcode prompts to enter value

Am using phonegap-plugin-barcodescanner in a phonegap app to scan QR codes.
When firing the scanner using:
function scan() {
cordova.plugins.barcodeScanner.scan(
function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
},
function (error) {
alert("Scanning failed: " + error);
}
);
}
The camera doesn't start - I just get a prompt saying:
"Enter barcode value (empty value will fire handler)"
Any ideas welcome TQ
The prompt says "Enter barcode value (empty value will fire handler)" maybe because you run platform browser. I' ve got the same "problem" when i run my project with "cordova run browser", and "browser" is a platform installed.

Signalr and servicestack

I have a servicestack server app that only process api calls (rest).
I am trying to implement the functionality I found in this Strathweb.com article.
To call my api's I use the url .../api/getthis and it works well.
I added the IncomingHubAttribute and OutgoingHubAtttributes and decorate my methods with them and the methods get called and all is good.
I can browse to localhost:1234/signalr/hubs and I see the generated js but when I browse to localhost:1234/log.html as described in the article I get
*hub.client is not defined.*
I have the following in my apphost file...
//Switch ServiceStack’s mode of operation to buffered,
PreRequestFilters.Add((req, res) => req.UseBufferedStream = true);
...
public override void Configure(Funq.Container container)
{ ...
RouteTable.Routes.MapHubs();
I have read about having to add
SetConfig(new EndpointHostConfig{RawHttpHandlers...
but don't fully understand what would get routed to where. I feel I am so close.
This is my log.html file
<html>
<head>
</head>
<body>
<ul id="messages"></ul>
</body>
<script type="text/javascript" src="Scripts\jquery-1.6.4.js"></script>
<script type="text/javascript" src="Scripts\jquery.signalR.core.js"></script>
<script type="text/javascript" src="/signalr/hubs"></script>
<script type="text/javascript">
$(function () {
var hub = $.connection.servicelog;//<---- **this does not seem to get resolved**
hub.client.log = function (data) {
$('#messages').prepend('<li>' + data.Time + " - " + data.Data + '</li>');
};
hub.client.logMessage = function (data) {
$('#messages').prepend('<li>' + data.Time + " - " + data.Data.Id + " " + data.Data.Name + '</li>');
};
hub.client.logArray = function (data) {
$('#messages').prepend('<li>' + data.Time + " - " + data.Data + '</li>');
};
$.connection.hub.start();
});
</script>
</html>
You are loading an incorrect signalr script "Scripts\jquery.signalR.core.js". It should be "Scripts\jquery.signalR-(version).js"

Resources