Browse Source

Fixed CORs issues with running web workers. Changed URLs for workers and scripts imported inside workers to Blob URLs.

pull/40/head
Teknikode 6 years ago
parent
commit
15393324b0
  1. 5
      Teknik/Areas/Paste/Views/Paste/Full.cshtml
  2. 3
      Teknik/Areas/Paste/Views/Paste/Simple.cshtml
  3. 7
      Teknik/Areas/Upload/Scripts/Upload.js
  4. 2
      Teknik/Properties/PublishProfiles/Teknik Dev.pubxml
  5. 15
      Teknik/Scripts/Common.js

5
Teknik/Areas/Paste/Views/Paste/Full.cshtml

@ -40,13 +40,14 @@ @@ -40,13 +40,14 @@
addEventListener('load', function () {
var code = document.querySelector('#code');
var language = document.querySelector('#syntaxLanguage');
var worker = new Worker('@Scripts.Url("~/bundles/syntaxWorker")');
var worker = new Worker(GenerateBlobURL('@Scripts.Url("~/bundles/syntaxWorker")'));
worker.onmessage = function (event) {
code.innerHTML = event.data.value;
language.innerText = event.data.language;
}
var scriptBlob = GenerateBlobURL('@Scripts.Url("~/bundles/highlight")');
var obj = {
script: '@Scripts.Url("~/bundles/highlight")',
script: scriptBlob,
code: code.textContent
};
worker.postMessage(obj);

3
Teknik/Areas/Paste/Views/Paste/Simple.cshtml

@ -26,10 +26,11 @@ @@ -26,10 +26,11 @@
<script>
addEventListener('load', function () {
var code = document.querySelector('#code');
var worker = new Worker('@Scripts.Url("~/bundles/syntaxWorker")');
var worker = new Worker(GenerateBlobURL('@Scripts.Url("~/bundles/syntaxWorker")'));
worker.onmessage = function (event) {
code.innerHTML = event.data.value;
}
var scriptBlob = GenerateBlobURL('@Scripts.Url("~/bundles/highlight")');
var obj = {
script: '@Scripts.Url("~/bundles/highlight")',
code: code.textContent

7
Teknik/Areas/Upload/Scripts/Upload.js

@ -199,7 +199,7 @@ function encryptFile(file, callback) { @@ -199,7 +199,7 @@ function encryptFile(file, callback) {
callback(e.target.result, keyStr, ivStr, filetype, fileExt, fileID, saveKey, serverSideEncrypt);
}
else {
var worker = new Worker(encScriptSrc);
var worker = new Worker(GenerateBlobURL(encScriptSrc));
worker.addEventListener('message', function (e) {
switch (e.data.cmd) {
@ -227,11 +227,14 @@ function encryptFile(file, callback) { @@ -227,11 +227,14 @@ function encryptFile(file, callback) {
$("#progress-" + fileID).children('.progress-bar').html('Error Occured');
}
// Generate the script to include as a blob
var scriptBlob = GenerateBlobURL(aesScriptSrc);
// Execute worker with data
var objData =
{
cmd: 'encrypt',
script: aesScriptSrc,
script: scriptBlob,
key: keyStr,
iv: ivStr,
chunkSize: chunkSize,

2
Teknik/Properties/PublishProfiles/Teknik Dev.pubxml

@ -18,7 +18,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt @@ -18,7 +18,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt
<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>Administrator</UserName>
<UserName>Uncled1023</UserName>
<_SavePWD>True</_SavePWD>
</PropertyGroup>
</Project>

15
Teknik/Scripts/Common.js

@ -173,6 +173,21 @@ function getAnchor() { @@ -173,6 +173,21 @@ function getAnchor() {
return (urlParts.length > 1) ? urlParts[1] : null;
}
function GenerateBlobURL(url) {
var cachedBlob = null;
jQuery.ajax({
url: url,
success: function (result) {
var workerJSBlob = new Blob([result], {
type: "text/javascript"
});
cachedBlob = window.URL.createObjectURL(workerJSBlob);
},
async: false
});
return cachedBlob;
}
AddAntiForgeryToken = function (data) {
data.__RequestVerificationToken = $('#__AjaxAntiForgeryForm input[name=__RequestVerificationToken]').val();
return data;

Loading…
Cancel
Save