зеркало из https://github.com/nextcloud/text.git
Add direct editing endpoint for workspaces
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Родитель
5f7f70c75e
Коммит
a6bd99213f
|
@ -43,5 +43,7 @@ return [
|
|||
'ocs' => [
|
||||
['name' => 'Workspace#folder', 'url' => '/workspace', 'verb' => 'GET'],
|
||||
['name' => 'Workspace#publicFolder', 'url' => '/public/workspace', 'verb' => 'GET'],
|
||||
['name' => 'Workspace#direct', 'url' => '/workspace/direct', 'verb' => 'GET'],
|
||||
|
||||
]
|
||||
];
|
||||
|
|
|
@ -54,10 +54,13 @@ use OCP\AppFramework\Http;
|
|||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\DirectEditing\IManager as IDirectEditingManager;
|
||||
use OCP\DirectEditing\RegisterDirectEditorEvent;
|
||||
use OCP\Files\Folder;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IRequest;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\Share\Exceptions\ShareNotFound;
|
||||
use OCP\Share\IManager;
|
||||
|
||||
|
@ -72,16 +75,29 @@ class WorkspaceController extends OCSController {
|
|||
/** @var WorkspaceService */
|
||||
private $workspaceService;
|
||||
|
||||
/** @var string */
|
||||
/** @var string|null */
|
||||
private $userId;
|
||||
|
||||
/** @var IDirectEditingManager */
|
||||
private $directEditingManager;
|
||||
|
||||
public function __construct($appName, IRequest $request, IRootFolder $rootFolder, IManager $shareManager, WorkspaceService $workspaceService, $userId) {
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
private const SUPPORTED_FILENAMES = [
|
||||
'README.md',
|
||||
'Readme.md',
|
||||
'readme.md'
|
||||
];
|
||||
|
||||
public function __construct($appName, IRequest $request, IRootFolder $rootFolder, IManager $shareManager, IDirectEditingManager $directEditingManager, IURLGenerator $urlGenerator, WorkspaceService $workspaceService, $userId) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->shareManager = $shareManager;
|
||||
$this->workspaceService = $workspaceService;
|
||||
$this->userId = $userId;
|
||||
$this->directEditingManager = $directEditingManager;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,4 +161,41 @@ class WorkspaceController extends OCSController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function direct(string $path): DataResponse {
|
||||
try {
|
||||
$folder = $this->rootFolder->getUserFolder($this->userId)->get($path);
|
||||
if ($folder instanceof Folder) {
|
||||
$file = $this->getFile($folder);
|
||||
if ($file === null) {
|
||||
$token = $this->directEditingManager->open($file->getId(), Application::APP_NAME);
|
||||
return new DataResponse([
|
||||
'url' => $this->urlGenerator->linkToRouteAbsolute('files.DirectEditingView.edit', ['token' => $token])
|
||||
]);
|
||||
}
|
||||
$token = $this->directEditingManager->create($path . '/'. self::SUPPORTED_FILENAMES[0], Application::APP_NAME, 'textdocument');
|
||||
return new DataResponse([
|
||||
'url' => $this->urlGenerator->linkToRouteAbsolute('files.DirectEditingView.edit', ['token' => $token])
|
||||
]);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->logger->logException($e, ['message' => 'Exception when creating a new file through direct editing']);
|
||||
return new DataResponse('Failed to create file', Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
private function getFile(Folder $folder) {
|
||||
$file = null;
|
||||
foreach (self::SUPPORTED_FILENAMES as $filename) {
|
||||
if ($folder->nodeExists($filename)) {
|
||||
$file = $folder->get($filename);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return $file;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче