Files
DocumentServer-v-9.2.0/core/Common/js/desktop_fetch.js
Yajbir Singh f1b860b25c
Some checks failed
check / markdownlint (push) Has been cancelled
check / spellchecker (push) Has been cancelled
updated
2025-12-11 19:03:17 +05:30

50 lines
1.3 KiB
JavaScript

// correct fetch for desktop application
var printErr = undefined;
var print = undefined;
var fetch = ("undefined" !== typeof window) ? window.fetch : (("undefined" !== typeof self) ? self.fetch : null);
var getBinaryPromise = null;
function internal_isLocal()
{
if (window.navigator && window.navigator.userAgent.toLowerCase().indexOf("ascdesktopeditor") < 0)
return false;
if (window.location && window.location.protocol == "file:")
return true;
if (window.document && window.document.currentScript && 0 == window.document.currentScript.src.indexOf("file:///"))
return true;
return false;
}
if (internal_isLocal())
{
fetch = undefined; // fetch not support file:/// scheme
getBinaryPromise = function()
{
var wasmPath = "ascdesktop://fonts/" + wasmBinaryFile.substr(8);
return new Promise(function (resolve, reject)
{
var xhr = new XMLHttpRequest();
xhr.open('GET', wasmPath, true);
xhr.responseType = 'arraybuffer';
if (xhr.overrideMimeType)
xhr.overrideMimeType('text/plain; charset=x-user-defined');
else
xhr.setRequestHeader('Accept-Charset', 'x-user-defined');
xhr.onload = function ()
{
if (this.status == 200)
resolve(new Uint8Array(this.response));
};
xhr.send(null);
});
}
}
else
{
getBinaryPromise = function() { return getBinaryPromise2.apply(undefined, arguments); }
}