Browse Source

Support serving a file within a shared directory

tags/v0.1.0
Gerben 6 years ago
parent
commit
ed6f9c2c8c
2 changed files with 28 additions and 1 deletions
  1. +2
    -0
      appinfo/routes.php
  2. +26
    -1
      lib/Controller/PubPageController.php

+ 2
- 0
appinfo/routes.php View File

@@ -3,6 +3,8 @@
return [ return [
'routes' => [ 'routes' => [
['name' => 'pubPage#getByToken', 'url' => '/s/{token}', 'verb' => 'GET'], ['name' => 'pubPage#getByToken', 'url' => '/s/{token}', 'verb' => 'GET'],
['name' => 'pubPage#getByTokenAndPath', 'url' => '/s/{token}/{path}', 'verb' => 'GET',
'requirements' => array('path' => '.+')],
['name' => 'privatePage#getByPath', 'url' => '/files/{path}', 'verb' => 'GET', ['name' => 'privatePage#getByPath', 'url' => '/files/{path}', 'verb' => 'GET',
'requirements' => array('path' => '.+')], 'requirements' => array('path' => '.+')],
] ]


+ 26
- 1
lib/Controller/PubPageController.php View File

@@ -1,6 +1,7 @@
<?php <?php
namespace OCA\Raw\Controller; namespace OCA\Raw\Controller;


use \Exception;
use OCP\IRequest; use OCP\IRequest;
use OCP\Share\IManager; use OCP\Share\IManager;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
@@ -28,9 +29,33 @@ class PubPageController extends Controller {
public function getByToken($token) { public function getByToken($token) {
$share = $this->manager->getShareByToken($token); $share = $this->manager->getShareByToken($token);
$node = $share->getNode(); $node = $share->getNode();
// if ($node->getType() === 'dir') { TODO }
if ($node->getType() === 'dir') {
// Is there some reasonable thing to return for a directory? An html index? A tarball?
throw new Exception("Requested share is a directory, not a file.");
}
$content = $node->getContent(); $content = $node->getContent();
$mimetype = $node->getMimeType(); $mimetype = $node->getMimeType();
$this->returnRawResponse($content, $mimetype); $this->returnRawResponse($content, $mimetype);
} }

/**
* @PublicPage
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getByTokenAndPath($token, $path) {
$share = $this->manager->getShareByToken($token);
$dirNode = $share->getNode();
if ($dirNode->getType() !== 'dir') {
throw new Exception("Received a sub-path for a share that is not a directory");
}
$fileNode = $dirNode->get($path);
if ($fileNode->getType() === 'dir') {
// Is there some reasonable thing to return for a directory? An html index? A tarball?
throw new Exception("Requested share is a directory, not a file.");
}
$content = $fileNode->getContent();
$mimetype = $fileNode->getMimeType();
$this->returnRawResponse($content, $mimetype);
}
} }

Loading…
Cancel
Save