-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Julius Härtl <jus@bitgrid.net>
- Loading branch information
1 parent
35bdf79
commit 32f13da
Showing
4 changed files
with
110 additions
and
20 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 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,60 @@ | ||
<?php | ||
|
||
namespace OCA\Text\DAV; | ||
|
||
|
||
use OC\Files\Node\File; | ||
use OCA\DAV\Connector\Sabre\Directory; | ||
use OCA\DAV\Files\FilesHome; | ||
use OCA\Text\Service\WorkspaceService; | ||
use Sabre\DAV\INode; | ||
use Sabre\DAV\PropFind; | ||
use Sabre\DAV\Server; | ||
use Sabre\DAV\ServerPlugin; | ||
|
||
|
||
class WorkspacePlugin extends ServerPlugin { | ||
|
||
const WORKSPACE = '{http://nextcloud.org/ns}workspace'; | ||
/** | ||
* @var Server | ||
*/ | ||
private $server; | ||
|
||
/** | ||
* This initializes the plugin. | ||
* | ||
* This function is called by Sabre\DAV\Server, after | ||
* addPlugin is called. | ||
* | ||
* This method should set up the required event subscriptions. | ||
* | ||
* @param Server $server | ||
* @return void | ||
*/ | ||
function initialize(Server $server) { | ||
$this->server = $server; | ||
|
||
$this->server->on('propFind', [$this, 'propFind']); | ||
} | ||
|
||
|
||
public function propFind(PropFind $propFind, INode $node) { | ||
if (!$node instanceof Directory && !$node instanceof FilesHome) { | ||
return; | ||
} | ||
|
||
$propFind->handle(self::WORKSPACE, function () use ($node) { | ||
$folder = \OC::$server->getUserFolder()->getById($node->getId())[0]; | ||
/** @var WorkspaceService $workspaceService */ | ||
$workspaceService = \OC::$server->query(WorkspaceService::class); | ||
/** @var File $file */ | ||
$file = $workspaceService->getFile($folder); | ||
if ($file instanceof File) { | ||
return $file->getContent(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
} |
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,31 @@ | ||
<?php | ||
|
||
|
||
namespace OCA\Text\Service; | ||
|
||
|
||
use OCP\Files\Folder; | ||
use OCP\Files\NotFoundException; | ||
|
||
class WorkspaceService { | ||
|
||
private const SUPPORTED_FILENAMES = [ | ||
'README.md', | ||
'Readme.md', | ||
'readme.md' | ||
]; | ||
|
||
public function getFile(Folder $folder) { | ||
$file = null; | ||
foreach (self::SUPPORTED_FILENAMES as $filename) { | ||
if ($folder->nodeExists($filename)) { | ||
try { | ||
$file = $folder->get($filename); | ||
} catch (NotFoundException $e) { | ||
} | ||
continue; | ||
} | ||
} | ||
return $file; | ||
} | ||
} |