Browse Source

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

tags/2.0.6
Teknikode 4 years ago
parent
commit
15393324b0

+ 3
- 2
Teknik/Areas/Paste/Views/Paste/Full.cshtml View File

@@ -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);

+ 2
- 1
Teknik/Areas/Paste/Views/Paste/Simple.cshtml View File

@@ -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

+ 5
- 2
Teknik/Areas/Upload/Scripts/Upload.js View File

@@ -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) {
$("#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,

+ 1
- 1
Teknik/Properties/PublishProfiles/Teknik Dev.pubxml View File

@@ -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
- 0
Teknik/Scripts/Common.js View File

@@ -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