-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add application/x-kdbx to mimetypemapping.json
Signed-off-by: Daniel Kesselberg <[email protected]>
- Loading branch information
Showing
6 changed files
with
119 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace OCA\Keeweb\Migration; | ||
|
||
use OCP\Files\IMimeTypeLoader; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\IRepairStep; | ||
|
||
class RegisterMimeType implements IRepairStep | ||
{ | ||
private $mimeTypeLoader; | ||
|
||
public function __construct(IMimeTypeLoader $mimeTypeLoader) | ||
{ | ||
$this->mimeTypeLoader = $mimeTypeLoader; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'Register MIME type for "application/x-kdbx"'; | ||
} | ||
|
||
private function registerForExistingFiles() | ||
{ | ||
$mimetypeId = $this->mimeTypeLoader->getId('application/x-kdbx'); | ||
$this->mimeTypeLoader->updateFilecache('kdbx', $mimetypeId); | ||
} | ||
|
||
private function registerForNewFiles() | ||
{ | ||
$mapping = ['kdbx' => ['application/x-kdbx']]; | ||
$mappingFile = \OC::$configDir . 'mimetypemapping.json'; | ||
|
||
if (file_exists($mappingFile)) { | ||
$existingMapping = json_decode(file_get_contents($mappingFile), true); | ||
if (json_last_error() === JSON_ERROR_NONE) { | ||
$mapping = array_merge($existingMapping, $mapping); | ||
} | ||
} | ||
|
||
file_put_contents($mappingFile, json_encode($mapping, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); | ||
} | ||
|
||
public function run(IOutput $output) | ||
{ | ||
$this->logger->info('Registering the mimetype...'); | ||
|
||
// Register the mime type for existing files | ||
$this->registerForExistingFiles(); | ||
|
||
// Register the mime type for new files | ||
$this->registerForNewFiles(); | ||
|
||
$this->logger->info('The mimetype was successfully registered.'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace OCA\Keeweb\Migration; | ||
|
||
use OCP\Files\IMimeTypeLoader; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\IRepairStep; | ||
|
||
class UnregisterMimeType implements IRepairStep | ||
{ | ||
private $mimeTypeLoader; | ||
|
||
public function __construct(IMimeTypeLoader $mimeTypeLoader) | ||
{ | ||
$this->mimeTypeLoader = $mimeTypeLoader; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'Unregister MIME type for "application/x-kdbx"'; | ||
} | ||
|
||
private function registerForExistingFiles() | ||
{ | ||
$mimetypeId = $this->mimeTypeLoader->getId('application/octet-stream'); | ||
$this->mimeTypeLoader->updateFilecache('kdbx', $mimetypeId); | ||
} | ||
|
||
private function registerForNewFiles() | ||
{ | ||
$mappingFile = \OC::$configDir . 'mimetypemapping.json'; | ||
|
||
if (file_exists($mappingFile)) { | ||
$mapping = json_decode(file_get_contents($mappingFile), true); | ||
if (json_last_error() === JSON_ERROR_NONE) { | ||
unset($mapping['kdbx']); | ||
} else { | ||
$mapping = []; | ||
} | ||
file_put_contents($mappingFile, json_encode($mapping, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)); | ||
} | ||
} | ||
|
||
public function run(IOutput $output) | ||
{ | ||
$this->logger->info('Unregistering the mimetype...'); | ||
|
||
// Register the mime type for existing files | ||
$this->registerForExistingFiles(); | ||
|
||
// Register the mime type for new files | ||
$this->registerForNewFiles(); | ||
|
||
$this->logger->info('The mimetype was successfully unregistered.'); | ||
} | ||
} |