diff --git a/CHANGELOG.md b/CHANGELOG.md
index b479365..d1049ba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.5.1 - 2022-08-24
+### Fixed
+ - Public pages also needed their plugin script changes, oops... fixed.
+
## 1.5.0 - 2022-08-24
### Changed
- raised version number to 1.5.0 to avoid confusion with a forked version of this app
diff --git a/appinfo/info.xml b/appinfo/info.xml
index 953f56e..a01cad2 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -30,7 +30,7 @@ See [README] for more exhaustive information on features and potential misfeatur
[README]: https://github.com/Yetangitu/owncloud-apps/blob/master/files_reader/README.md
]]>
- 1.5.0
+ 1.5.1
AGPL
Frank de Lange
diff --git a/dist/files_reader-1.5.0.tar.gz b/dist/files_reader-1.5.0.tar.gz
deleted file mode 100644
index 5151de4..0000000
Binary files a/dist/files_reader-1.5.0.tar.gz and /dev/null differ
diff --git a/js/plugin-public.js b/js/plugin-public.js
index eec5bcd..19267d2 100644
--- a/js/plugin-public.js
+++ b/js/plugin-public.js
@@ -11,40 +11,56 @@
(function(OCA) {
-
OCA.Files_Reader = OCA.Files_Reader || {};
const epub_enabled = OCP.InitialState.loadState('files_reader', 'epub_enabled');
const pdf_enabled = OCP.InitialState.loadState('files_reader', 'pdf_enabled');
const cbx_enabled = OCP.InitialState.loadState('files_reader', 'cbx_enabled');
+ const mimeHandlers = {
+ 'epub': { default: epub_enabled, mimeTypes: ['application/epub+zip']},
+ 'pdf': { default: pdf_enabled, mimeTypes: ['application/pdf']},
+ 'cbx': { default: cbx_enabled, mimeTypes: [
+ 'application/comicbook+7z',
+ 'application/comicbook+rar',
+ 'application/comicbook+tar',
+ 'application/comicbook+zip',
+ 'application/x-cbr'
+ ]}
+ };
- /* comicbooks come in many different forms... */
- const cbx_types= [
- 'application/comicbook+7z',
- 'application/comicbook+rar',
- 'application/comicbook+tar',
- 'application/comicbook+zip',
- 'application/x-cbr',
- ];
-
+ const mimeMappings = {
+ 'application/epub+zip': 'epub',
+ 'application/pdf': 'pdf',
+ 'application/x-cbr': 'cbx',
+ 'application/comicbook+7z': 'cbx',
+ 'application/comicbook+rar': 'cbx',
+ 'application/comicbook+tar': 'cbx',
+ 'application/comicbook+zip': 'cbx'
+ };
- var isMobile = navigator.userAgent.match(/Mobi/i);
- var hasTouch = 'ontouchstart' in document.documentElement;
+ const isMobileUAD = window.navigator.userAgentData?.mobile;
+ const isMobile = typeof isMobileUAD === 'boolean'
+ ? isMobileUAD
+ : navigator.userAgent.match(/Mobi/i);
function actionHandler(fileName, mime, context) {
- var sharingToken = $('#sharingToken').val();
- var downloadUrl = OC.generateUrl('/s/{token}/download?files={files}&path={path}', {
- token: sharingToken,
- files: fileName,
- path: context.dir
- });
- OCA.Files_Reader.Plugin.show(downloadUrl, mime, true);
+ const downloadUrl = Files.getDownloadUrl(fileName, context.dir);
+ OCA.Files_Reader.Plugin.show(downloadUrl, mimeMappings[mime], true);
}
+
+
/**
* @namespace OCA.Files_Reader.Plugin
*/
OCA.Files_Reader.Plugin = {
+ /**
+ * @param mimeType
+ */
+ getMapping: function(mimeType) {
+ return mimeMappings[mimeType];
+ },
+
/**
* @param fileList
*/
@@ -79,12 +95,12 @@
* @param downloadUrl
* @param isFileList
*/
- show: function(downloadUrl, mimeType, isFileList) {
+ show: function(downloadUrl, fileType, isFileList) {
var self = this;
var $iframe;
- var viewer = OC.generateUrl('/apps/files_reader/?file={file}&type={type}', {file: downloadUrl, type: mimeType});
- // launch in new window on mobile and touch devices...
- if (isMobile || hasTouch) {
+ var viewer = OC.generateUrl('/apps/files_reader/?file={file}&type={type}', {file: downloadUrl, type: fileType});
+ // launch in new window on mobile devices...
+ if (isMobile) {
window.open(viewer, downloadUrl);
} else {
$iframe = '';
@@ -108,48 +124,23 @@
*/
_extendFileActions: function(fileActions) {
var self = this;
- fileActions.registerAction({
- name: 'view-epub',
- displayName: 'View',
- mime: 'application/epub+zip',
- permissions: OC.PERMISSION_READ,
- actionHandler: function(fileName, context){
- return actionHandler(fileName, 'application/epub+zip', context);
- }
- });
- for (let i = 0; i < cbx_types.length; i++) {
- fileActions.registerAction({
- name: 'view-cbr',
- displayName: 'View',
- mime: cbx_types[i],
- permissions: OC.PERMISSION_READ,
- actionHandler: function(fileName, context) {
- return actionHandler(fileName, 'application/x-cbr', context);
- }
+ for (handler in mimeHandlers) {
+ const actionName = 'view-' + handler;
+ mimeHandlers[handler].mimeTypes.forEach(function(mimeType) {
+ fileActions.registerAction({
+ name: actionName,
+ displayName: 'View',
+ mime: mimeType,
+ permissions: OC.PERMISSION_READ,
+ actionHandler: function(fileName, context){
+ return actionHandler(fileName, mimeType, context);
+ }
+ });
+
+ if (mimeHandlers[handler].default === 'true')
+ fileActions.setDefault(mimeType, actionName);
});
}
- fileActions.registerAction({
- name: 'view-pdf',
- displayName: 'View',
- mime: 'application/pdf',
- permissions: OC.PERMISSION_READ,
- actionHandler: function(fileName, context) {
- return actionHandler(fileName, 'application/pdf', context);
- }
- });
-
-
-
-
- if (epub_enabled === 'true')
- fileActions.setDefault('application/epub+zip', 'view-epub');
- if (cbx_enabled === 'true') {
- for (let i = 0; i < cbx_types.length; i++) {
- fileActions.setDefault(cbx_types[i], 'view-cbr');
- }
- }
- if (pdf_enabled === 'true')
- fileActions.setDefault('application/pdf', 'view-pdf');
}
};
@@ -159,19 +150,11 @@ OC.Plugins.register('OCA.Files.FileList', OCA.Files_Reader.Plugin);
// FIXME: Hack for single public file view since it is not attached to the fileslist
$(document).ready(function(){
- const mimetype=$('#mimetype').val();
- if ($('#isPublic').val()
- && (mimetype === 'application/epub+zip'
- || mimetype === 'application/pdf'
- || mimetype === 'application/x-cbr'
- || mimetype.startsWith('application/comicbook'))
- ) {
- var sharingToken = $('#sharingToken').val();
- var downloadUrl = OC.generateUrl('/s/{token}/download', {token: sharingToken});
- var viewer = OCA.Files_Reader.Plugin;
- var mime = $('#mimetype').val();
- if (mimetype.startsWith('application/comicbook'))
- mime = 'application/x-cbr';
- viewer.show(downloadUrl, mime, false);
+ const viewer = OCA.Files_Reader.Plugin;
+ const fileType=viewer.getMapping($('#mimetype').val());
+ if ($('#isPublic').val() && fileType) {
+ const sharingToken = $('#sharingToken').val();
+ const downloadUrl = OC.generateUrl('/s/{token}/download', {token: sharingToken});
+ viewer.show(downloadUrl, fileType, false);
}
});
diff --git a/lib/Listeners/LoadPublicViewerListener.php b/lib/Listeners/LoadPublicViewerListener.php
index a420017..829c2c4 100644
--- a/lib/Listeners/LoadPublicViewerListener.php
+++ b/lib/Listeners/LoadPublicViewerListener.php
@@ -25,7 +25,7 @@ class LoadPublicViewerListener implements IEventListener {
private IInitialState $initialStateService;
public function __construct(
- IInitialState $initialStateService,
+ IInitialState $initialStateService
) {
$this->initialStateService = $initialStateService;
}