-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add endpoint for public editor previews #71
Conversation
What is needed? |
Well, we need to load (in read only for now) the editor. So that it will display the preview in the editor (just like it does in the sidebar). Else we can't display non utf-8 (and non ascii) encoded text files properly. |
Nothing for 13 it seems -> moving |
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This will be needed in a following commit when plain text previews generated by this app are introduced. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
The children elements are not attached again later, so they can be removed instead of just detached. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
The default plain text previews always assume that the text file uses UTF-8 encoding, so when it uses a different one the characters are not properly parsed by the browser. The "public" endpoint from this app tries to guess the actual encoding of the file and then converts the data sent to the browser to UTF-8. Thus, now the default plain text previews are overriden with the preview generated by this app. Note that this does not prevent the default plain text preview from being generated, though; it is simply hidden. Following the same approach used for Markdown previews, ".preview" is added to the "#imgframe" element, which is the parent element for the default plain text preview. This removes the default plain text preview thanks to the CSS rules. However, as the "overrider" plain text preview is also a descendant of ".preview", a special CSS class has to be added to the "overrider" plain text preview to prevent it from being hidden. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
2af9a0c
to
4060462
Compare
I have rebased onto current master and added the needed changes to show the plain text preview. However, as it is read-only, I just used (almost) the same code as for the default plain text previews instead of bothering to add the editor in read-only mode ;-) Basically it is the same as the default plain text previews, but with better encoding support (provided by the public endpoint added by @rullzer). A better long term solution would be to refactor the sidebar previews and the public previews to a generic preview system, but for now these changes fix the bug and should be easily backporteable ;-) |
@danxuliu ok so no editing if you share it with write permissions yet ;) |
Mmm, it seems that the |
@danxuliu o that I can fix if needed ;) |
@rullzer Please :-) |
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@danxuliu done. |
@rullzer Mmm, it does not work here. But it seems to work in your screenshot... although I do not know why :-P If I am not mistaken, the range affects the whole response contents, not only the file contents. Thus, although the file contents length is limited to the range, the response is still cut before the end and the JSON parsing fails; the whole response would be
I used just 1KB because that is what is used in the default plain text preview. I have no preference in that regard, feel fee to change it if you want ;-)
I have noticed that (...) sometimes appears when it should be hidden; I intended to fix that in a following pull request because it is not caused by the changes made here. However I have never seen it double :-S
Selecting the text was explicitly disabled when default plain text previews were added. This is just a guess, but I think that it was disabled due to the height limit of the preview. If the browser window is short and a large text preview is shown the bottom part of the text would not be visible, but if you select the text by dragging down until the Download button even the text that is not visible would be selected, which could be a bit surprising for the user. |
@nextcloud/designers Some questions about plain text file previews:
|
The download button will be (is already?) moved to the header anyways.
It should be selectable IMO - @nextcloud/designers |
So the download button could even go I guess since we have that on the top now. |
Anyway I'd say lets get this in now and fix more stuff in later PR's. |
Sure... once the range is fixed ;-) (I have checked again and it fails as explained in the first part of that comment; I still do not know why it works for you :-S Cached JavaScript, maybe?) |
Maybe it is your webserver... |
Of course for a read only endpoint we could just return the text (not in json) as it makes no real sense anyway. If we want at some point to have a real editor then we need to return the whole text anyways... |
You are right, it was related to my webserver. With the PHP built-in webserver the preview loads, but with Apache it does not (at least, with the official Docker image for Nextcloud and the official Docker image for PHP on Apache (which the Nextcloud one is based on); I have not tested it in other environments). However, it seems that the reason that it works with the PHP built-in webserver is simply because it ignores the Having said that, I have noticed that although the sidebar preview uses a Anyway, in order to return JSON and also use the Another option would be to somehow prevent the webserver to apply the And another option would be to remove the
Returning the text itself would easily solve all of the above, so fine by me ;-) However, if at some point a real editor is added I guess that the JSON response would be needed (for example, to know whether the file is writable or not), so all of the above would need to be taken into account again. |
As @MorrisJobke said, the text should be selectable. Just like we do for Markdown shares, directly show the text in nice formatting so you can quickly share notes. Show as much of the text as possible – ideally everything. |
For markdown we also just show the first 512 KB or so, but this is already quite some text (~70k to 80k words). |
@danxuliu well if we allow real editing we can't do range requests anyway. I'll convert the controller later. |
* Fix JS * Request more data Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@danxuliu please test again. |
@rullzer The |
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
@danxuliu now it is set as text-plain. However now I see no newlines (I just see |
@danxuliu Could you have a look at this? |
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works 👍
Pending issues mentioned in comments will be fixed in other pull requests.
@MorrisJobke please review as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works 👍
Sorry to bump in too late, but it is still not working for me ? Any work around for this ? I don't want user to download the text file, I just want them to view it and if needed edit online. |
Simple endpoint for single file shares to get an editor preview:
so:
<server>/apps/files_texteditor/public/<token>
gives you back what is required.@MorrisJobke @icewind1991 could one of you look into the fancy javascript stuff?