Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ebook reader doesn't save anything #44

Closed
illumina7 opened this issue Apr 12, 2017 · 44 comments
Closed

ebook reader doesn't save anything #44

illumina7 opened this issue Apr 12, 2017 · 44 comments

Comments

@illumina7
Copy link

Hello,
I'm using the ebook reader app 1.0.4 on my private nextcloud 11 server (latest stable build on ubuntu server 14.04).
It can read the ebooks without any issue and i can save bookmarks and annotations, but after closing and reopening an ebook all saves are gone. The reader isn't saving the last reading postion too and I need to search for my last opened page every time I want to continue reading.
Is this a common issue or is there just something wrong with my nextcloud installation?
Greetings from Germany!

@jryberg
Copy link

jryberg commented May 7, 2017

Hi,

I got the exact same issue

The only logs I have are this event every time I open the document:

{"reqId":"[REDACTED]","remoteAddr":"[REDACTED]","app":"PHP","message":"Undefined` index: title at /var/www/nextcloud/apps/files_reader/templates/epubreader.php#37","level":3,"time":"2017-05-07T14:24:39+00:00","method":"GET","url":"/index.php/apps/files_reader/?file=%2Fremote.php%2Fwebdav%2FDocuments%2FE-books%2F[REDACTED].epub&type=application%2Fepub%2Bzip","user":"[REDACTED]","version":"11.0.2.7"}

@Yetangitu
Copy link
Owner

Which database do you use?

@jryberg
Copy link

jryberg commented May 8, 2017

Hi,

MySQL: 5.7.18

Ubuntu 16.04.2 LTS
PHP: 7.0.15-0ubuntu0.16.04.4

Best regards Johan

@illumina7
Copy link
Author

Hello again,
I'am currently using:

Ubuntu Server 16.04.02 LTS (seems like I've been looking for the wrong VM last time)
Nextcloud: 11.0.3 stable
MySQL: 5.7.18
PHP: 7.0.15-0ubuntu0.16.04.04

This server is virtualized with virtualbox and I am using an apache reverse proxy with a ssl cert from letsencrypt.org sitting behind an ipfire firewall.

I've searched the Logs and find the same Error Log as @jryberg "Undefined index: title at /var/www/nextcloud/apps/files_reader/templates/epubreader.php#37".

Best regards

@Yetangitu
Copy link
Owner

I'll look into this when I have some time to dedicate to these apps...

@scurrvy2020
Copy link

Same issue here.
Ubuntu 16.04.2
MySQL: 5.7.18
PHP: 7.0.15

@Yetangitu
Copy link
Owner

OK, this seems to be a real issue so I'll just have to find some time. Stay tuned but don't hold your breath...

@scurrvy2020
Copy link

I did a little investigation... the oc_reader_bookmarks and oc_reader_preferences tables are created, but they are empty.

image

@LearnLinuxTV
Copy link

Same issue here.

@ghost
Copy link

ghost commented Jul 23, 2017

Same issue here.
Ubuntu Server 16.04.2
MMySQL 5.7.19
PHP 7.0.18
I can read eBooks very well, but nothing is saved.

mysql> select * from oc_reader_preferences;
Empty set (0,00 sec)
mysql> select * from oc_reader_bookmarks;
Empty set (0,00 sec)

@scurrvy2020
Copy link

Is there anything we can do to help you debug this?
I really miss having this functionality.

@mpodshivalin
Copy link

When changing preferences/adding bookmarks/switching pages, the app does POST-requests to save data, but they result in 404 error (routing doesn't work correctly):
image

@mpodshivalin
Copy link

I've just tried to reproduce this on a clean VM with ownCloud 10.0.3 (the app can only be installed manually because its maximum ownCloud version is set to 9.2). The app works exactly as in Nextcloud 12.0.3 - reading works, but saving data doesn't.

@mpodshivalin
Copy link

mpodshivalin commented Oct 11, 2017

I've managed to make a temporary fix for this issue.

  1. Go to your Nextcloud/ownCloud installation location

  2. Open /apps/files_reader/js/ready.js

  3. Find this line

options.session.basePath = $session.data('basepath');
  1. Change this line to
options.session.basePath = '<your Nextcloud/ownCloud server URL>/index.php/apps/files_reader/';
  1. Clear your web browser cache

After this, bookmarks, settings and navigation work, are saved and restored when opening the document.

The proper way to do this without hardcoding the URL would be to use official JS API, but I'm too inexperienced in making ownCloud/Nextcloud apps :)

@Yetangitu
Copy link
Owner

Good catch, I'll look into this ASAP

@Yetangitu
Copy link
Owner

The issue is caused by mismatched quoting in the templates (files_reader/templates/epubreader.php and files_reader/templates/cbreader.php) and can be fixed by changing the single quotes inside the data-basepath declaration to double quotes, like so:

data-basepath='<?php p($urlGenerator->linkTo("files_reader",""));?>'

I'll release a new version tomorrow which fixes this and adds PDF support. The PDF renderer is ready, the UI is more or less ready, only the position saving bits have not been wired up yet. That'll come soon enough...

@scurrvy2020
Copy link

Thanks!

@scurrvy2020
Copy link

hmmm. I changed the quotes in the line as you mentioned, rebooted the server, but I am still not able to save anything. Anyway, I'll wait for your updated app. Thanks!

@mpodshivalin
Copy link

scurrvy2020, maybe the problem is that there are two templates in files_reader/templates: cbreader.php and epubreader.php. Try Yetangitu's changes with both of these files.

Yetangitu, thanks again for the app! PDF support will be a great addition. And position saving will be a killer feature, since ownCloud/Nextcloud's PDF viewer doesn't support it.

@Yetangitu
Copy link
Owner

Change both templates to make sure you changed the correct one.

The PDF reader does not support position saving yet but that will come. It does support 2-page spreads though:

documents - files - nimbus - chromium_046

@LearnLinuxTV
Copy link

LearnLinuxTV commented Oct 12, 2017 via email

@Yetangitu
Copy link
Owner

Yetangitu commented Oct 12, 2017

Do you get any error messages in the javascript console (use 'inspect' to show the console, make sure it is set to show all messages)?

Did you restart the PHP container service (php-fpm, mod-php or whatever you use)? Sometimes it does not seem to pick up changes until after it has been restarted, even though it should 'just work'.

@LearnLinuxTV
Copy link

LearnLinuxTV commented Oct 12, 2017 via email

@mpodshivalin
Copy link

For some reason, in my case

p($urlGenerator->linkTo("files_reader",""));

returns /nextcloud/apps/files_reader/. This is the query that returns 404 error.

In my example above, I've hardcoded /nextcloud/index.php/apps/files_reader/. This query works.

@Yetangitu
Copy link
Owner

Yetangitu commented Oct 12, 2017

urlGenerator should return the correct URL (with or without index.php depending on whether you use rewrite rules to create 'pretty' URLs). The code lives in lib/private/urlGenerator.php in the OC/NC root, it uses the boolean $frontControllerActive to switch between 'pretty' and normal URLs:

$frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');

...

$urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
if ($frontControllerActive) {
    $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
}

If you get 'wrong' URLs it might be that you've got one of those parameters (htaccess.IgnoreFrontController or front_controller_active) wrongly set.

@mpodshivalin
Copy link

For some weird reason (in my case) pdfreader makes requests to URLs with index.php, while files_reader makes requests to URLs without index.php. I've even downloaded clean Bitnami ownCloud VM and got the same results. I've made a fix for myself and everything works fine, but I'm afraid others will be affected by this issue.

Maybe the reason why pdfreader works is because it generates PHP URLs in PHP urlGenerator and JS URLs in JavaScript's OC.generateUrl?

You're definitely right that OC/NC's urlGenerator should return correct URLs, so it's not plugin's fault.

@scurrvy2020
Copy link

mpodshivalin, I've tried adding the url with index.php to the ready.js file, but it still doesn't work :-/

I'm still getting 404 errors. I've rebooted the server as well. If I edit the message and add "index.php" to the referrer url, the message will successfully post.

Did you do anything else to hardcode the index.php into the url?

@mpodshivalin
Copy link

Did you clear your web browser's cache after editing ready.js file?

@scurrvy2020
Copy link

yes, cleared the cache, tried different browsers, different computers. nothing worked

@Yetangitu
Copy link
Owner

The Javascript-version of the urlgenerator (OC.generateUrl in core/js/js.js) takes a different path to decide whether or not to add index.php to the generated URL:

        if(oc_config.modRewriteWorking == true) {
            return OC.webroot + _build(url, params);
        }

        return OC.webroot + '/index.php' + _build(url, params);

...where oc_config.modRewriteWorking is populated (in /lib/private/Template/JSConfigHelper.php) as:

'modRewriteWorking' => (\OC::$server->getConfig()->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')

The path taken is different but the logic used is similar.

You can view the contents of oc_config by requesting <OC_NC_ROOT>/core/js/oc.js using a GET request (i.e. just use a browser), the result looks somewhat like this:

...
var oc_config={"session_lifetime":1440,"session_keepalive":true,"version":"11.0.2.7","versionstring":"11.0.2","enable_avatars":true,"lost_password_link":null,"modRewriteWorking":true};
...

Look for the value of modRewriteWorking, if this is true the Javascript version (OC.generateUrl) does not add index.php to the generated URL. If the PHP version acts differently something is amiss, somewhere. The question remains, where? I could just use the Javascript version but that would be a cop-out. I'll dig some deeper.

@scurrvy2020
Copy link

scurrvy2020 commented Oct 13, 2017

I had to go to domain/nextcloud/index.php/core/js/oc.js to get the output in the browser

var oc_config={"session_lifetime":1440,"session_keepalive":true,"version":"12.0.3.3","versionstring":"12.0.3","enable_avatars":true,"lost_password_link":null,"modRewriteWorking":false,"sharing.maxAutocompleteResults":0,"sharing.minSearchStringLength":0,"blacklist_files_regex":"\\.(part|filepart)$"};

looks like mine is false...

@scurrvy2020
Copy link

scurrvy2020 commented Oct 14, 2017

I added these two lines to my config.php and used sudo -u www-data php occ maintenance:update:htaccess to regenerate the .htaccess file.

  'htaccess.IgnoreFrontController' => true,
  'htaccess.RewriteBase' => '/nextcloud',

After rebooting the server and clearing the browser cache I am now able to save items in the reader app. However, there are some icons in the header of nextcloud that are giving error 404. (update: disabling the theming app fixes the icons, there is a known bug with theming and rewrite: https://help.nextcloud.com/t/icons-missing-path-not-rewritten/4722/18)
So, it looks like rewrite was not properly detected by nextcloud, correct?

@Yetangitu
Copy link
Owner

I don't use htaccess myself, using nginx with php-fpm. As such I do not track the routines around updating that file but the mere presence of that command in occ does make me think this step is mandatory to get the file to be updated.

@LearnLinuxTV
Copy link

A new version was released today, but unfortunately, this issue still remains. :(

@Yetangitu
Copy link
Owner

Same messages in the console?

I mean this one: POST <nextcloud_url>/apps/files_reader/bookmark 404 (Not Found)

Does the link work if you include index.php before /apps?

@LearnLinuxTV
Copy link

I see this:

POST https://nextcloud.mydomain.net/apps/files_reader/bookmark 404 (Not Found)
send @ jquery.min.js?v=1.1.0.0071:4
ajax @ jquery.min.js?v=1.1.0.0071:4
n.(anonymous function) @ jquery.min.js?v=1.1.0.0071:4
options.session.setBookmark @ ready.js?v=1.1.0.0071:65
EPUBJS.Reader.addAnnotation @ reader.min.js?v=1.1.0.0071:1
EPUBJS.Reader.addBookmark @ reader.min.js?v=1.1.0.0071:1
(anonymous) @ reader.min.js?v=1.1.0.0071:1
dispatch @ jquery.min.js?v=1.1.0.0071:3
r.handle @ jquery.min.js?v=1.1.0.0071:3
jquery.min.js?v=1.1.0.0071:4 DELETE https://nextcloud.mydomain.net/apps/files_reader/bookmark/1171/epubcfi62cover4page10 405 (Method Not Allowed)

As far as including index.php before /apps, how would I do that? Is there a file I would edit somewhere to add that?

Thanks!

@Yetangitu
Copy link
Owner

Try the following query in a browser in which you're logged in to your instance of NC:

https://nextcloud.mydomain.net/apps/files_reader/bookmark/cursor/1171

This should produce a JSON response containing the last visited location in that publication, like so:

{"name":"__CURSOR__","type":"bookmark","value":14,"content":null,"lastModified":"1516640984881243"}

I got the file_id (1171 in the url) from your previous response so I assume a file with that id exists on your instance. If there is no cursor set it will give a null reply. If the query redirects to the NC front page there is something wrong with your install. In that case try the following query:

https://nextcloud.mydomain.net/index.php/apps/files_reader/bookmark/cursor/1171

If that query works (i.e. you get either a JSON or null response) there is something wrong with the URL rewrite logic.

@LearnLinuxTV
Copy link

For some reason my reply shows before yours. The first link doesn't work but the second one does. You mentioned that there may be something wrong with the rewrite logic, can you please elaborate more?

@Yetangitu
Copy link
Owner

Which webserver do you use? The rewrite rules for Apache are kept in the .htaccess file in the NC root directory, this file can be updated using occ maintenance:update:htaccess but as I do not use Apache I can not vow for the efficacy of this command. If you use nginx (like I do) you should have configured the rewrite rules in your site directory (e.g. /etc/nginx/sites-enabled/your_site_name or something similar, see https://docs.nextcloud.com/server/12/admin_manual/installation/nginx.html for more information and examples.

@LearnLinuxTV
Copy link

This server is using Apache. The .htaccess file is default, I've made no changes to it. I have read the documentation regarding Apache, and it mentions to make sure that the .htaccess file is writable by the Apache user (it is), that mod env and rewrite are enabled (they are) and config.php has:
'overwrite.cli.url' => 'https://nextcloud.mydomain.net'

From an Apache perspective, everything seems fine according to the documentation. Perhaps there's an issue with the .htaccess file that ships with Nextcloud and I need to file a bug against it?

Thanks!

@LearnLinuxTV
Copy link

LearnLinuxTV commented Feb 1, 2018

This is resolved for me. I fixed it by getting "pretty urls" to work with Apache following the documentation. I didn't really understand what you guys were referring to with the different URLs but now I understand it.

However, my thought process right now is why does this app require pretty urls? Why can't it work without it? All the other apps I've used with Nextcloud all work perfectly fine right out of the box but for some reason this one doesn't.

I'm glad it's working now, though. Thank you all for your assistance.

@Yetangitu
Copy link
Owner

Reader does not require 'pretty URLs', it works just fine with ugly ones as well (which I used myself until recently). The way Reader works probably makes it more sensitive to problems in the rewrite logic, it is implemented as a plugin to the Files app and uses it in the background to download publications to show in the browser.

@Yetangitu
Copy link
Owner

Closing this as all known problems in Reader seem to be resolved; problems caused by faulty rewrite logic lie outside of the scope of this bug tracker.

@fogcake
Copy link

fogcake commented Jul 9, 2018

Hello,

I am struggling to make the history and bookmarks working for files_reader.

I am using nginx, so I followed these guide to add rewrite rules:
https://doc.owncloud.org/server/9.1/admin_manual/installation/nginx_examples.html

I am having exactly the same problems with POST queries getting 404 as an answer. So both oc_reader_bookmarks and oc_reader_preferences tables are not populated.

Any hints will be very appreciated.

Best regards,
Andriy
UPDATE: Fixed by hardcoding url as @mpodshivalin suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants