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

Recognize further file extensions as text files (to be opened in the "in-app" text editor) #7098

Closed
AndyScherzinger opened this issue Nov 7, 2017 · 19 comments
Labels
1. to develop Accepted and waiting to be taken care of enhancement feature: filesystem

Comments

@AndyScherzinger
Copy link
Member

This is a clone of nextcloud/android#1756 which asked for further file extensions to be opened in the Android client's in-app viewer. So for consistency reasons if this is to be implemented it should be implemented across the eco system as-in webUI and clients (at least Android and iOS)

Expected behaviour

  1. Create a file text with extension .adoc, .rc, .conf, .gitignore, .todo, .cfg, or without any extension
  2. Click on the file
  3. File opens in the webUI text editor

Actual behaviour

.adoc, .rc, .conf, .gitignore, .todo, .cfg are treated as generic file

Environment data

Android version: 5.1.1

Stock or customized device OS: Customized

Nextcloud Android app version: 2.0.1, from FDroid

Nextcloud server version: 12

@MorrisJobke
Copy link
Member

@icewind1991 @rullzer Ideas for this?

@j-ed
Copy link
Contributor

j-ed commented Nov 7, 2017

Wouldn't be possible to automatically identify the file type based on its mime-type instead of pinning it to file extensions? It was a common trick in the past to fake a file extension to bypass email block list etc.
See: https://stackoverflow.com/questions/457797/best-way-to-recognize-a-filetype-in-php

@MorrisJobke
Copy link
Member

Wouldn't be possible to automatically identify the file type based on its mime-type instead of pinning it to file extensions? It was a common trick in the past to fake a file extension to bypass email block list etc.

The fileinfo command is used as fallback, because it is usually a lot slower and the file needs to be loaded into memory for this. Thus it is not that performant if you need to detect the mime type for a lot of files in a batch. But for uploads this should be fine. On the other side it is then bad to use one approach for file uploads but another one for files:scan. 😕

cc @icewind1991

@j-ed
Copy link
Contributor

j-ed commented Nov 8, 2017

@MorrisJobke Thank you for the explanation. I agree, for uploading single files it might be justified to spend that additional time to evaluate the correct mime-type but for batch runs it might be better to rely on the database information or a different approach need to be find.
Due to the fact that all kind of house keeping tasks are running in the background of Nextcloud, wouldn't it make sense to also double-check the mime-type of newly added files by e.g. executing the external file-command. The command is relatively fast and could also run on whole directories - just an idea.

@AndyScherzinger
Copy link
Member Author

But for uploads this should be fine. On the other side it is then bad to use one approach for file uploads but another one for files:scan.

Besides that looking at the client we do not receive mime type information from the server that is why the clients also rely on the file extension to predict the mime type.

@j-ed
Copy link
Contributor

j-ed commented Nov 8, 2017

@AndyScherzinger From what I've seen mime type information exist for all files on the server. Wouldn't it make sense to enhance the used API so that that piece of information is transferred too?

@AndyScherzinger
Copy link
Member Author

@j-ed can't tell for the server part and yes having this info transferred from the server would help since we could (to some extend) drop mime-type calculation on the client(s) afaik the mime type information (at least via file extension) is the same on webUI and Android client. So if the webUI thinks a file is text-based than the Android client should do so too (if file extension based of course).

@tobiasKaminsky
Copy link
Member

Besides that looking at the client we do not receive mime type information from the server that is why the clients also rely on the file extension to predict the mime type.

We do get the mimetype:
Getting from webdav to RemoteFile:
https://github.com/nextcloud/android-library/blob/master/src/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java#L167

From RemoteFile to OCFile:
https://github.com/nextcloud/android/blob/8fef61ea93fb1307d431de1d594b473f1f6e4b2d/src/main/java/com/owncloud/android/utils/FileStorageUtils.java#L222-L222

Were do we rely on the file extension? Maybe only on local files?

@AndyScherzinger
Copy link
Member Author

AndyScherzinger commented Nov 8, 2017

Were do we rely on the file extension? Maybe only on local files?

We always do for Android, see FileListListAdapter for example

@tobiasKaminsky
Copy link
Member

Then we should adapt this: use mimeType from server as often as possible and rely on the extension only as fallback.

@AndyScherzinger
Copy link
Member Author

Sounds good to me for Android 👍

@nextcloud/ios how is this handled in the iOS client?

@marinofaggiana
Copy link
Member

I use the UTI, but if possible the mimeType from server is better !

@Spartachetto
Copy link

I hope not to derail the discussion but, as you are considering to extend the files recognized as some that could be open via text editor, I'd like to remember the proposal of other extensions.

Look here (nextcloud/files_texteditor#16) and here (nextcloud/files_texteditor#15) for different syntax files which could be nice to open.

Thank you

@nextcloud-bot nextcloud-bot added the stale Ticket or PR with no recent activity label Jun 20, 2018
@skjnldsv skjnldsv added the 1. to develop Accepted and waiting to be taken care of label Jun 12, 2019
@ghost ghost removed the stale Ticket or PR with no recent activity label Jun 12, 2019
@szaimen
Copy link
Contributor

szaimen commented May 21, 2021

I'm closing this issue due to inactivity. Please reopen if you still want to implement this.

@szaimen szaimen closed this as completed May 21, 2021
@szaimen
Copy link
Contributor

szaimen commented May 27, 2021

I was at least able to open .conf files with the built in text editor. So I think this is at least partially implemented.

@tobiasKaminsky
Copy link
Member

Also on Android with built in text editor?

@szaimen
Copy link
Contributor

szaimen commented May 27, 2021

Yes

@szaimen
Copy link
Contributor

szaimen commented May 27, 2021

Tough I wonder why this is in the server repository if it is an android ticket? 🤔

@Spartachetto
Copy link

@szaimen this issue pops out several times in seemingly unrelated subjects.
I think that even the discussion in Text app about non destructive editing (nextcloud/text#439 ) could be considered as related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. to develop Accepted and waiting to be taken care of enhancement feature: filesystem
Projects
None yet
Development

No branches or pull requests

9 participants