Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions keeweb/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@

namespace OCA\Keeweb\AppInfo;

use OC\Files\Type\Detection;
use OCP\AppFramework\App;
use OCA\Keeweb\Controller\PageController;

$mimeTypeDetector = \OC::$server->getMimeTypeDetector();
if ($mimeTypeDetector instanceof Detection) {
/** registerType without getAllMappings will prevent loading nextcloud's default mappings. */
$mimeTypeDetector->getAllMappings();
$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.

/** For dav requests it should be enough to register the mime type and skip the rest of the app initialization. */
return;
}

require_once __DIR__ . '/autoload.php';

class Application extends App {
Expand Down Expand Up @@ -58,13 +71,6 @@ public function __construct(array $urlParams=array()){
];
});

$mimeTypeDetector = \OC::$server->getMimeTypeDetector();
$mimeTypeLoader = \OC::$server->getMimeTypeLoader();

// Register custom mimetype we can hook in the frontend
$mimeTypeDetector->getAllMappings();
$mimeTypeDetector->registerType('kdbx', 'application/x-kdbx', 'application/x-kdbx');

// Script for registering file actions
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener(
Expand Down
3 changes: 3 additions & 0 deletions keeweb/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Please read https://github.com/jhass/nextcloud-keeweb/blob/master/README.md#mime
<licence>agpl</licence>
<author>Jonne Haß</author>
<namespace>Keeweb</namespace>
<types>
<filesystem/>
</types>
<category>tools</category>
<category>integration</category>
<website>https://github.com/jhass/nextcloud-keeweb</website>
Expand Down
33 changes: 15 additions & 18 deletions keeweb/lib/Migration/AddMimetypeToFilecache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@

namespace OCA\Keeweb\Migration;

use OCP\Migration\IRepairStep;
use OCP\IDBConnection;
use OCP\Files\IMimeTypeLoader;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class AddMimetypeToFilecache implements IRepairStep {
public function __construct(IDBConnection $connection) {}

public function getName() {
return "Add custom mimetype to filecache";
}

public function run(IOutput $output) {
$mimeTypeDetector = \OC::$server->getMimeTypeDetector();
$mimeTypeLoader = \OC::$server->getMimeTypeLoader();
private $mimeTypeLoader;

// Register custom mimetype
$mimeTypeDetector->getAllMappings();
$mimeTypeDetector->registerType('kdbx', 'x-application/kdbx', 'x-application/kdbx');
public function __construct(IMimeTypeLoader $mimeTypeLoader) {
$this->mimeTypeLoader = $mimeTypeLoader;
}

// 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.

$mimeTypeLoader->updateFilecache('%.kdbx', $mimetypeId);
public function getName() {
return 'Add custom mimetype to filecache';
}

$output->info("Added custom mimetype to filecache.");
}
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.

$output->info('Added custom mimetype to filecache.');
}
}
28 changes: 16 additions & 12 deletions keeweb/lib/Migration/RemoveMimetypeFromFilecache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

namespace OCA\Keeweb\Migration;

use OCP\Migration\IRepairStep;
use OCP\IDBConnection;
use OCP\Files\IMimeTypeLoader;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;

class RemoveMimetypeFromFilecache implements IRepairStep {
public function __construct(IDBConnection $connection) {}

public function getName() {
return "Remove custom mimetype from filecache";
}
private $mimeTypeLoader;

public function __construct(IMimeTypeLoader $mimeTypeLoader) {
$this->mimeTypeLoader = $mimeTypeLoader;
}

public function getName() {
return 'Remove custom mimetype from filecache';
}

public function run(IOutput $output) {
$mimeTypeLoader = \OC::$server->getMimeTypeLoader();
$mimetypeId = $mimeTypeLoader->getId('application/octet-stream');
$mimeTypeLoader->updateFilecache('%.kdbx', $mimetypeId);
$output->info("Removed custom mimetype from filecache.");
}
public function run(IOutput $output) {
$mimetypeId = $this->mimeTypeLoader->getId('application/octet-stream');
$this->mimeTypeLoader->updateFilecache('kdbx', $mimetypeId);
$output->info('Removed custom mimetype from filecache.');
}
}