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

Register application/x-kdbx the right way #124

Merged
merged 7 commits into from
Jan 19, 2020

Conversation

kesselb
Copy link
Contributor

@kesselb kesselb commented Dec 7, 2019

Hi @jhass,

Thanks for your app 👍 Some people at nextcloud/server (e.g. nextcloud/server#17217) and also over here are reporting issues. *.kdbx files are not opened with the app 😞

This pull request should fix most of these issues and also make the manual changes to mimetypemapping.json superfluous (at least on my setup).

I'm not a heavy user of keeweb. We probably need some testers ;)

- Change x-application/kdbx to application/x-kdbx (as in viewer.js)
- Fix call to updateFilecache (extension is requested not a pattern)
- Inject IMimeTypeLoader via DI

Signed-off-by: Daniel Kesselberg <[email protected]>
- Fix call to updateFilecache (extension is requested not a pattern)
- Inject IMimeTypeLoader via DI

Signed-off-by: Daniel Kesselberg <[email protected]>
Signed-off-by: Daniel Kesselberg <[email protected]>
I'm not 100% sure about this change. It should not be necessary to call getAllMappings to register a new mime type. Probably a definition with config/mimetypemapping.json will overwrite this definition later. App initialization should be cheap. Expensive jobs like getAllMappings are bad.

Signed-off-by: Daniel Kesselberg <[email protected]>
public function run(IOutput $output) {
// And update the filecache for it.
$mimetypeId = $this->mimeTypeLoader->getId('application/x-kdbx');
$this->mimeTypeLoader->updateFilecache('kdbx', $mimetypeId);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateFilecache is looking for a extension. A pattern like %.kdbx do not work.


// And update the filecache for it.
$mimetypeId = $mimeTypeLoader->getId('x-application/kdbx');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mime: 'application/x-kdbx',

Do not work because they mimetype is created as x-application/kdbx over here.

@maurerle
Copy link
Contributor

maurerle commented Dec 8, 2019

can confirm this is working (tested in newly setup nc-docker with nc 17).
executing select * from oc_mimetypes; contains application/x-kdbx as it should.
And selecting kdbx opens the keeweb application.

this should definitly get merged

@maurerle
Copy link
Contributor

maurerle commented Dec 8, 2019

New files or edited files are not detected correctly.

  1. Use this patch, existing file is recognized correctly.
  2. Add a new kdbx file.
  3. New kdbx file is not available to open with keeweb

As the mimetypes are correctly in the database it seems that there is something wrong with detecting the mimetype correctly.
Running php occ maintenance:mimetype:update-db --repair-filecache resolves this until the next save.

Could you look into that?

Filesystem loads the app also for request via dav. This is required to assign the mime type.

Signed-off-by: Daniel Kesselberg <[email protected]>
- Register mime type before app initialization
- Skip the app initialization for dav requests

Signed-off-by: Daniel Kesselberg <[email protected]>
@kesselb
Copy link
Contributor Author

kesselb commented Dec 8, 2019

Thanks @maurerle 👍

Make sense to me. Keeweb app is not loaded for dav requests and therefore the mime type (.kdbx => application/x-kdbx) unknown. Added the app to dav requests (types: filesystem). Nextcloud caches the types information in oc_appconfig table. You probably have to modify the types row for keeweb and add filesystem.

$mimeTypeDetector = \OC::$server->getMimeTypeDetector();
$mimeTypeDetector->registerType('kdbx', 'application/x-kdbx', 'application/x-kdbx');

if (\OC::$REQUESTEDAPP === 'dav') {
Copy link
Contributor Author

@kesselb kesselb Dec 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @rullzer @nickvergessen does that make sense? ;) For a dav request we need to announce the mime type to nextcloud. The app itself is not required. I'm trying to save some resources by skipping the app initialization.

@maurerle
Copy link
Contributor

maurerle commented Dec 8, 2019

This works! 😄
So types-filesystem loads this app with every filesystem or dav request. And loading the app runs the mimetype detection?

So when doing it through mimetypemapping.json this process is done by the core mimetype detector right?

@kesselb
Copy link
Contributor Author

kesselb commented Dec 8, 2019

So types-filesystem loads this app with every filesystem or dav request. And loading the app runs the mimetype detection?

Loading the app tells nextcloud that files with kdbx extension should have the mime type application/x-kdbx. For dav request we don't initialize the app to save resources.

$mimeTypeDetector = \OC::$server->getMimeTypeDetector();
$mimeTypeDetector->registerType('kdbx', 'application/x-kdbx', 'application/x-kdbx');
if (\OC::$REQUESTEDAPP === 'dav') {
/** For dav requests it should be enough to register the mime type and skip the rest of the app initialization. */
return;
}

So when doing it through mimetypemapping.json this process is done by the core mimetype detector right?

Yes. A entry in mimetypemapping.json tells nextcloud that files with kdbx extension should have the mime type application/x-kdbx.

It's required to call getAllMappings before registerType otherwise the default mappings are not loaded.

Signed-off-by: Daniel Kesselberg <[email protected]>
@kesselb
Copy link
Contributor Author

kesselb commented Dec 9, 2019

Nextcloud 18 will contain kdbx => application/x-kdbx by default. We should keep this approach until 17 is EOL or release different version fors 17/18.

@jhass
Copy link
Owner

jhass commented Jan 19, 2020

So with this we can drop the instructions from the readme right?

Sorry for not responding earlier here. To be honest I don't know enough about Nextcloud to fully verify this is sane, but it sounds like you know what you're doing here. So I'm sure it won't be any more broken than it is right now, so I'll merge this for now. Btw if you're interested in (co-) maintaining... ;)

@kesselb
Copy link
Contributor Author

kesselb commented Jan 21, 2020

Thanks for merging 👍

you know what you're doing her

I hope 🙈

Btw if you're interested in (co-) maintaining

Sorry 😞 I don't have enough time for co-maintaining a app. Luckily there seems to be some progress with the documentation for developers so it should be easier to keep up with the latest changes and better instructions how to migrate code. I think that most of the issues reports here should be solved with this PR. That will hopefully reduce your workload. Ping me if you're stuck somehow. I'll try to have a look.

@kesselb kesselb deleted the fix/register-mime-type branch January 21, 2020 14:00
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

Successfully merging this pull request may close these issues.

3 participants