- substantial bit rot accrued in 4 years of non-maintenance which made Reader unusable
 - Reader now works reliably on public pages - or at least it _Works For Me™_

 - Refactored a substantial part of the code to comply to the "current" (ha ha) Nextcloud API
 - Dropped Owncloud compatibility for lack of a testing installation
 - Dropped IE (<11) support
 - Dropped compatibility with older (<20) Nextcloud versions
 - Dropped app-specific ajax code, now handled by SettingsController
 - Updated dependencies where applicable
This commit is contained in:
Frank de Lange 2022-09-24 00:00:03 +00:00
parent 16afbe45fe
commit b190e180ef
137 changed files with 30984 additions and 2 deletions

142
js/ready.js Normal file
View file

@ -0,0 +1,142 @@
document.onreadystatechange = function () {
if (document.readyState == "complete") {
var type=decodeURIComponent(getUrlParameter('type')),
file=decodeURIComponent(getUrlParameter('file')),
options = {},
$session = $('.session');
options.session = {};
options.session.filename = decodeURI($session.data('filename'));
options.session.format = $session.data('filetype');
options.session.fileId = $session.data('fileid');
options.session.title = options.session.filename;
options.session.nonce = $session.data('nonce') || "";
options.session.version = $session.data('version') || "";
options.session.metadata = $session.data('metadata') || {};
options.session.annotations = $session.data('annotations') || {};
options.session.fileId = $session.data('fileid') || "";
options.session.scope = $session.data('scope') || "";
options.session.cursor = $session.data('cursor') || {};
options.session.defaults = $session.data('defaults') || {};
options.session.preferences = $session.data('preferences') || {};
options.session.defaults = $session.data('defaults') || {};
options.session.basePath = $session.data('basepath');
options.session.downloadLink = $session.data('downloadlink');
console.log(options.session.basePath);
/* functions return jquery promises */
options.session.getPreference = function(name) {
return $.get(options.session.basePath + "preference/" + options.session.fileId + "/" + options.session.scope + "/" + name);
};
options.session.setPreference = function(name, value) {
return $.post(options.session.basePath + "preference",
{
"fileId": options.session.fileId,
"scope": options.session.scope,
"name": name,
"value": JSON.stringify(value)
});
};
options.session.deletePreference = function(name) {
return $.delete(options.session.basePath + "preference/" + options.session.fileId + "/" + options.session.scope + "/" + name);
};
options.session.getDefault = function(name) {
return $.get(options.session.basePath + "preference/default/" + options.session.scope + "/" + name);
};
options.session.setDefault = function(name, value) {
return $.post(options.session.basePath + "preference/default",
{
"scope": options.session.scope,
"name": name,
"value": JSON.stringify(value)
});
};
options.session.deleteDefault = function(name) {
return $.delete(options.session.basePath + "preference/default/" + options.session.scope + "/" + name);
};
options.session.getBookmark = function(name, type) {
return $.get(options.session.basePath + "bookmark/" + options.session.fileId + "/" + type + "/" + name);
};
options.session.setBookmark = function(name, value, type, content) {
return $.post(options.session.basePath + "bookmark",
{
"fileId": options.session.fileId,
"name": name,
"value": JSON.stringify(value),
"type": type,
"content": JSON.stringify(content)
});
};
options.session.deleteBookmark = function(name) {
return $.delete(options.session.basePath + "bookmark/" + options.session.fileId + "/" + name);
};
options.session.getCursor = function() {
return $.get(options.session.basePath + "bookmark/cursor/" + options.session.fileId);
};
options.session.setCursor = function(value) {
return $.post(options.session.basePath + "bookmark/cursor",
{
"fileId": options.session.fileId,
"value": JSON.stringify(value)
});
};
options.session.deleteCursor = function() {
return $.delete(options.session.basePath + "bookmark/cursor/" + options.session.fileId);
};
switch (type) {
case 'epub':
options['contained'] = true;
renderEpub(file, options);
break;
case 'cbx':
renderCbr(file, options);
break;
case 'pdf':
renderPdf(file, options);
break;
default:
console.log(type + ' is not supported by Reader');
}
}
// why is there no standard library function for this?
function getUrlParameter (param) {
var pattern = new RegExp('[?&]'+param+'((=([^&]*))|(?=(&|$)))','i');
var m = window.location.search.match(pattern);
return m && ( typeof(m[3])==='undefined' ? '' : m[3] );
}
// start epub.js renderer
function renderEpub(file, options) {
// some parameters...
EPUBJS.filePath = "vendor/epubjs/";
EPUBJS.cssPath = "vendor/epubjs/css/";
EPUBJS.basePath = $('.session').data('basepath');
var reader = ePubReader(file, options);
}
// start cbr.js renderer
function renderCbr(file, options) {
CBRJS.filePath = "vendor/cbrjs/";
var reader = cbReader(file, options);
}
// start pdf.js renderer
function renderPdf(file, options) {
PDFJS.filePath = "vendor/pdfjs/";
PDFJS.imageResourcesPath = "vendor/pdfjs/css/images/";
PDFJS.workerSrc = options.session.basePath + 'vendor/pdfjs/lib/pdf.worker.js';
var reader = pdfReader(file, options);
}
};