Skip to content

Commit

Permalink
Adapt content-disposition to inline for pdfs, images and videos
Browse files Browse the repository at this point in the history
  • Loading branch information
tikiatua committed Mar 27, 2023
1 parent 5e98a87 commit 7094b74
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"pluginName": "Internal Assets",
"pluginDescription": "A simple plugin to restrict access to assets for permitted users only. Access to a given asset is only granted if the user has view-permissions for the given source (this can be set in the user- or group-settings).\r\n\r\nThe asset source folder should be moved out of the web root folder so the files are never accessible without this plugin.",
"pluginVersion": "4.1.0",
"pluginVersion": "4.1.1",
"pluginAuthorName": "Ramon Saccilotto",
"pluginVendorName": "saccilottoconsulting",
"pluginAuthorUrl": "https://github.com/tikiatua",
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 4.1.1 - 2023-03-27
## Changed
- Use Content-Dispositon inline for pdfs, images and videos to open the respective
assets directly in the browser instead of downloading them.

## 4.1.0 - 2023-03-27
## Changed
- Use streamAsFile method to return file content to browser, this should
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "saccilottoconsulting/craft-internal-assets",
"description": "A simple plugin to restrict access to assets for permitted users only. Access to a given asset is only granted if the user has view-permissions for the given source (this can be set in the user- or group-settings). The asset source folder should be moved out of the web root folder so the files are never accessible without this plugin.",
"type": "craft-plugin",
"version": "4.1.0",
"version": "4.1.1",
"keywords": [
"craft",
"cms",
Expand Down
11 changes: 10 additions & 1 deletion src/controllers/AccessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ public function actionFetch(string $path)
$mimeType = FileHelper::getMimeTypeByExtension($filename);

// display pdfs inline
$inline = $mimeType == "application/pdf";
$inline = false;
if ($mimeType == "application/pdf") {
$inline = true;
}
if (str_starts_with($mimeType, "image/")) {
$inline = true;
}
if (str_starts_with($mimeType, "video/")) {
$inline = true;
}

$stream = $fs->getFileStream($filepath);
return $this->response->sendStreamAsFile($stream, $filename, [
Expand Down

0 comments on commit 7094b74

Please sign in to comment.