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

Don't load app for dav requests #135

Merged
merged 3 commits into from
Aug 24, 2020
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
12 changes: 0 additions & 12 deletions keeweb/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@
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') {
/** 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
14 changes: 7 additions & 7 deletions keeweb/appinfo/info.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
<id>keeweb</id>
<name>Keeweb</name>
<summary>Open Keepass stores</summary>
Expand All @@ -8,24 +8,24 @@
<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>
<bugs>https://github.com/jhass/nextcloud-keeweb/issues</bugs>
<repository>https://github.com/jhass/nextcloud-keeweb</repository>
<screenshot>https://cloud.aeshna.de/keeweb.gif</screenshot>
<dependencies>
<nextcloud min-version="11" max-version="18" />
<nextcloud min-version="11" max-version="18"/>
</dependencies>
<repair-steps>
<install>
<step>OCA\Keeweb\Migration\AddMimetypeToFilecache</step>
<step>OCA\Keeweb\Migration\RegisterMimeType</step>
</install>
<post-migrate>
<step>OCA\Keeweb\Migration\RegisterMimeType</step>
</post-migrate>
<uninstall>
<step>OCA\Keeweb\Migration\RemoveMimetypeFromFilecache</step>
<step>OCA\Keeweb\Migration\UnregisterMimeType</step>
</uninstall>
</repair-steps>
</info>
Expand Down
27 changes: 0 additions & 27 deletions keeweb/lib/Migration/AddMimetypeToFilecache.php

This file was deleted.

19 changes: 19 additions & 0 deletions keeweb/lib/Migration/MimeTypeMigration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace OCA\Keeweb\Migration;

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

abstract class MimeTypeMigration implements IRepairStep
{
const CUSTOM_MIMETYPEMAPPING = 'mimetypemapping.json';

protected $mimeTypeLoader;

public function __construct(IMimeTypeLoader $mimeTypeLoader)
{
$this->mimeTypeLoader = $mimeTypeLoader;
}
}
49 changes: 49 additions & 0 deletions keeweb/lib/Migration/RegisterMimeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace OCA\Keeweb\Migration;

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

class RegisterMimeType extends MimeTypeMigration
{
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 . self::CUSTOM_MIMETYPEMAPPING;

if (file_exists($mappingFile)) {
$existingMapping = json_decode(file_get_contents($mappingFile), true);
if (json_last_error() === JSON_ERROR_NONE && is_array($existingMapping)) {
$mapping = array_merge($existingMapping, $mapping);
}
}

file_put_contents($mappingFile, json_encode($mapping, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}

public function run(IOutput $output)
{
$output->info('Registering the mimetype...');

// Register the mime type for existing files
$this->registerForExistingFiles();

// Register the mime type for new files
$this->registerForNewFiles();

$output->info('The mimetype was successfully registered.');
}
}
26 changes: 0 additions & 26 deletions keeweb/lib/Migration/RemoveMimetypeFromFilecache.php

This file was deleted.

49 changes: 49 additions & 0 deletions keeweb/lib/Migration/UnregisterMimeType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace OCA\Keeweb\Migration;

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

class UnregisterMimeType extends MimeTypeMigration
{
public function getName()
{
return 'Unregister MIME type for "application/x-kdbx"';
}

private function unregisterForExistingFiles()
{
$mimeTypeId = $this->mimeTypeLoader->getId('application/octet-stream');
$this->mimeTypeLoader->updateFilecache('kdbx', $mimeTypeId);
}

private function unregisterForNewFiles()
{
$mappingFile = \OC::$configDir . self::CUSTOM_MIMETYPEMAPPING;

if (file_exists($mappingFile)) {
$mapping = json_decode(file_get_contents($mappingFile), true);
if (json_last_error() === JSON_ERROR_NONE && is_array($mapping)) {
unset($mapping['kdbx']);
} else {
$mapping = [];
}
file_put_contents($mappingFile, json_encode($mapping, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
}

public function run(IOutput $output)
{
$output->info('Unregistering the mimetype...');

// Register the mime type for existing files
$this->unregisterForExistingFiles();

// Register the mime type for new files
$this->unregisterForNewFiles();

$output->info('The mimetype was successfully unregistered.');
}
}