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
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 0 additions & 4 deletions keeweb/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,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
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.');
}
}