nextcloud / files_texteditor

:page_facing_up: Text editor for plaintext files
72 stars 41 forks source link

Allow Custom File Extensions To Be Edited By Text Editor When Clicked Instead Of Downloading #266

Open Sheepings opened 4 years ago

Sheepings commented 4 years ago

-## Steps to reproduce

  1. Upload a unknown file extension like file.cs or file_x.aspx
  2. Click the file you uploaded
  3. It will download, but it should open in an editor...

Expected behaviour

I'd expect there would be an interface for adding file extensions which would open custom file types in text/code editor. The expected files should open in an editor. But there is no way to add custom file extensions manually through the Nextcloud web interface, and have them files open in an editor, instead of bring forced to download.

Actual behaviour

The file clicked will start downloading, instead of opening in a text editor. There isn't any menu option to open with text editor either.

UBuntu 18.04:

Web server:

Database: MySQL 5.7.31

PHP version: 7.2.33

Nextcloud version: 19 (see Nextcloud admin page)

Client configuration

Browser: Opera

Operating system: Ubuntu 18.04

biguenique commented 3 years ago

You can set file extensions to treat as text files by mapping the file extension to a mime type in Nextcloud. This is not defined by Texteditor but in Nextcloud.

  1. Create (or edit) a file named <nextcloud>/config/mimetypemapping.json and add your mappings, eg.:

    {
    "aspx": ["text/code"],
    "cs" : ["text/code"]
    }
  2. Update Nextcloud's mapping (run with your www-data user):

    $ php occ maintenance:mimetype:update-js
  3. Important! Rescan your files to apply changes to existing files (run with www-data user):

    $ php occ files:scan --all

References (read them!) :