blocked by osTicket PR#3920
Closed this issue · 14 comments
This osTicket PR looks to be incompatible with this plugin: osTicket/osTicket#3920
I received a "failed to load pdf document" error on PDF's and others didn't display either until I reverted this PR.
Cheers.
As long as we have javascript, we can do it, check this hack out:
var req = new XMLHttpRequest();
req.open("GET","url-to-file", true)
req.responseType = "arraybuffer";
req.onload = function(e){
var ab = req.response;
var blob = new Blob([ab], {type: "application/pdf"});
var url = URL.createObjectURL(blob);
var el = document.getElementsById('pdf-object-id');
var hack = el.cloneNode();
hack.setAttribute('data',url);
hack.setAttribute('src',url);
el.parentNode.replaceChild(hack,el);
};
req.send();
Obviously needs tidying, but it works. 👍
I've been working on an upgrade with admin defined max-inlined attachments, which uses ajax, so, it's not a stretch to pull blobs and insert them.. https://github.com/clonemeagain/attachment_preview/tree/feature/toggle-number-of-attachments
Oh great, I won't pretend I entirely understand it, but I'll check it out and give it a shot.
Nice plugin btw, I think it adds some flair to the osTicket ticket view.
Basically, ajax can make binary transfers, and object urls can refer to Blob's of binary data, so we can join those together like the above and it works regardless of the disposition. :-)
This likely fixes the mime issues I was getting as well. So it's double good.
This is now working for me with PDF's with your latest commits and osTicket PR#3920 applied, thanks.
Perhaps I have only just noticed it however the option to preview youtube links: "Convert Youtube/video to Player", doesn't work. I can see an outline of a frame that it is trying to add, but there is no content inside the frame. I could post a screenshot if you wish.
I'm guessing you are likely aware of this, however, and I'm only testing out things so not a big deal, just letting you know.
Cheers.
Ooh, wasn't actually. I'll check it ASAP
I can't see the error mate, can you share how you're posting them? Maybe I do it differently.
I can either email in ticket with just a youtube url, or I can create a new ticket from the agent web interface and use "insert link" to add in a url. n.b I can't copy and paste the url directly into the text area as redactor takes over and converts the url to some html embedded youtube clip code.
Here are some screen shots:
Here is the ticket view when the option for "Convert Youtube" is set.
note the thin blue frame which is where the player is at least trying to be set into place.
Here is the ticket view when the option is turned off.
I'll load up an instance with just stock v1.10 and see if that restores this function, my install has a bunch of different pull requests etc in it now.
Hmm, I still have the same problem using stock v1.10 and I even tried going back a bunch of commits on the plugin. I found this in the page source however:
<div class="thread-body no-pjax">
<div><a href="https://www.youtube.com/watch?v=Pjw2A3QU8Qg">https://www.youtube.com/watch?v=Pjw2A3QU8Qg</a><div class="embedded" style="max-width: 100%; height: auto; padding: 4px; border: 1px solid #C3D9FF; margin-top: 10px; margin-bottom: 10px !important;"><iframe width="560" height="349" src="http://www.youtube.com/embed/Pjw2A3QU8Qg?rel=0&hd=1" frameborder="0" allowfullscreen="1"></iframe></div></div>
<div class="clear"></div>
</div>
When I go back to the latest commits on this plugin I find a much bigger section in the page source.
It starts with some css <style name="Attachments Preview Stylesheet">, then includes some javascript <script type="text/javascript" name="Attachments Preview Toggle Script"> and finally follows with:
<div id="ap-file-1" class="embedded"><iframe width="560" height="349" src="http://www.youtube.com/embed/Pjw2A3QU8Qg?rel=0&hd=1" frameborder="0" allowfullscreen="1" id="ap-file-1-c"></iframe></div></div>
So perhaps the plugin is working ok and it is something on my side ?
I've tested with a few different browser/os combos though.
I do see this in the httpd error log but it doesn't seem to refer to a problem:
AttachmentPreviewPlugin: pjax prefix trick in operation.., referer: https://
Is there somewhere else I can check for what might be blocking my view of these iframes ?
Cheers.
If I copy and paste the HTML you've put there, into a bare HTML file, open it in a browser, it works. The plugin also works on my prod server..
So.. I'm literally not seeing the problem mate.
Does your computer actually have access to youtube?
Is your browser/extensions/AV restricting iframes?
Are you using an "adblocker" that is being particularly efficient?
All good, I'm with you and think your code is working fine, it is just something on my end. I have a fair array of VMs I'm testing on but happy to consider this and the original issue all closed and ok.
Perhaps if anyone else encounters any trouble like this in the future, let me know and I'll be happy to test further.
Thanks for your help with this.
Aha, I couldn't leave well enough alone and have found something further on this.
I disabled https and the youtube link previews started working.
So a quick edit to line 569 of class.AttachmentPreviewPlugin.php to use https instead of http for the src attribute of the iframe and this enabled working when my osticket install was set back to using https only.
Maybe my install goes a little too far with enabling of HSTS also so not many other people would likely run into this.
I can get behind that.
Fantastic, thanks.