|
|
@ -11,6 +11,7 @@ use OCP\AppFramework\Http\Attribute\OpenAPI; |
|
|
|
use OCP\AppFramework\Http\Attribute\PublicPage; |
|
|
|
use OCP\AppFramework\Http\Attribute\PublicPage; |
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
|
|
use OCP\AppFramework\Http\FileDisplayResponse; |
|
|
|
use OCP\AppFramework\Http\FileDisplayResponse; |
|
|
|
|
|
|
|
use OCP\AppFramework\Http\RedirectResponse; |
|
|
|
use OCP\AppFramework\PublicShareController; |
|
|
|
use OCP\AppFramework\PublicShareController; |
|
|
|
use OCP\Constants; |
|
|
|
use OCP\Constants; |
|
|
|
use OCP\Files\Folder; |
|
|
|
use OCP\Files\Folder; |
|
|
@ -18,6 +19,7 @@ use OCP\Files\NotFoundException; |
|
|
|
use OCP\IPreview; |
|
|
|
use OCP\IPreview; |
|
|
|
use OCP\IRequest; |
|
|
|
use OCP\IRequest; |
|
|
|
use OCP\ISession; |
|
|
|
use OCP\ISession; |
|
|
|
|
|
|
|
use OCP\Preview\IMimeIconProvider; |
|
|
|
use OCP\Share\Exceptions\ShareNotFound; |
|
|
|
use OCP\Share\Exceptions\ShareNotFound; |
|
|
|
use OCP\Share\IManager as ShareManager; |
|
|
|
use OCP\Share\IManager as ShareManager; |
|
|
|
use OCP\Share\IShare; |
|
|
|
use OCP\Share\IShare; |
|
|
@ -33,6 +35,7 @@ class PublicPreviewController extends PublicShareController { |
|
|
|
private ShareManager $shareManager, |
|
|
|
private ShareManager $shareManager, |
|
|
|
ISession $session, |
|
|
|
ISession $session, |
|
|
|
private IPreview $previewManager, |
|
|
|
private IPreview $previewManager, |
|
|
|
|
|
|
|
private IMimeIconProvider $mimeIconProvider, |
|
|
|
) { |
|
|
|
) { |
|
|
|
parent::__construct($appName, $request, $session); |
|
|
|
parent::__construct($appName, $request, $session); |
|
|
|
} |
|
|
|
} |
|
|
@ -63,9 +66,11 @@ class PublicPreviewController extends PublicShareController { |
|
|
|
* @param int $x Width of the preview |
|
|
|
* @param int $x Width of the preview |
|
|
|
* @param int $y Height of the preview |
|
|
|
* @param int $y Height of the preview |
|
|
|
* @param bool $a Whether to not crop the preview |
|
|
|
* @param bool $a Whether to not crop the preview |
|
|
|
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, list<empty>, array{}> |
|
|
|
* @param bool $mimeFallback Whether to fallback to the mime icon if no preview is available |
|
|
|
|
|
|
|
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, list<empty>, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}> |
|
|
|
* |
|
|
|
* |
|
|
|
* 200: Preview returned |
|
|
|
* 200: Preview returned |
|
|
|
|
|
|
|
* 303: Redirect to the mime icon url if mimeFallback is true |
|
|
|
* 400: Getting preview is not possible |
|
|
|
* 400: Getting preview is not possible |
|
|
|
* 403: Getting preview is not allowed |
|
|
|
* 403: Getting preview is not allowed |
|
|
|
* 404: Share or preview not found |
|
|
|
* 404: Share or preview not found |
|
|
@ -79,6 +84,7 @@ class PublicPreviewController extends PublicShareController { |
|
|
|
int $x = 32, |
|
|
|
int $x = 32, |
|
|
|
int $y = 32, |
|
|
|
int $y = 32, |
|
|
|
$a = false, |
|
|
|
$a = false, |
|
|
|
|
|
|
|
bool $mimeFallback = false, |
|
|
|
) { |
|
|
|
) { |
|
|
|
$cacheForSeconds = 60 * 60 * 24; // 1 day |
|
|
|
$cacheForSeconds = 60 * 60 * 24; // 1 day |
|
|
|
|
|
|
|
|
|
|
@ -124,6 +130,12 @@ class PublicPreviewController extends PublicShareController { |
|
|
|
$response->cacheFor($cacheForSeconds); |
|
|
|
$response->cacheFor($cacheForSeconds); |
|
|
|
return $response; |
|
|
|
return $response; |
|
|
|
} catch (NotFoundException $e) { |
|
|
|
} catch (NotFoundException $e) { |
|
|
|
|
|
|
|
// If we have no preview enabled, we can redirect to the mime icon if any |
|
|
|
|
|
|
|
if ($mimeFallback) { |
|
|
|
|
|
|
|
if ($url = $this->mimeIconProvider->getMimeIconUrl($file->getMimeType())) { |
|
|
|
|
|
|
|
return new RedirectResponse($url); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
|
|
return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
|
|
} catch (\InvalidArgumentException $e) { |
|
|
|
} catch (\InvalidArgumentException $e) { |
|
|
|
return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
|
|
return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
|
|