Skip to content

Commit 389d861

Browse files
author
Andrew Welch
committed
Added a $enableDownloadFileEndpoint settings/config option (set to false by default) to control whether the download files action is publicly accessible
1 parent da884cc commit 389d861

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

src/Transcoder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ class Transcoder extends Plugin
5555
*/
5656
public static $plugin;
5757

58+
/**
59+
* @var Settings
60+
*/
61+
public static $settings;
62+
5863
// Public Methods
5964
// =========================================================================
6065

@@ -65,6 +70,8 @@ public function init()
6570
{
6671
parent::init();
6772
self::$plugin = $this;
73+
// Initialize properties
74+
self::$settings = self::$plugin->getSettings();
6875
// Handle console commands
6976
if (Craft::$app instanceof ConsoleApplication) {
7077
$this->controllerNamespace = 'nystudio107\transcoder\console\controllers';

src/config.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
'gif' => '@web/transcoder/gif/',
5555
],
5656

57+
// Determines whether the download file endpoint should be enabled for anonymous frontend access
58+
'enableDownloadFileEndpoint' => false,
59+
5760
// Use a md5 hash for the filenames instead of parameterized naming
5861
'useHashedNames' => false,
5962

src/controllers/DefaultController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace nystudio107\transcoder\controllers;
1212

13+
use nystudio107\transcoder\Transcoder;
14+
1315
use Craft;
1416
use craft\web\Controller;
1517
use craft\helpers\Json;
@@ -38,6 +40,18 @@ class DefaultController extends Controller
3840
// Public Methods
3941
// =========================================================================
4042

43+
/**
44+
* @inheritDoc
45+
*/
46+
public function beforeAction($action)
47+
{
48+
if (!Transcoder::$settings->enableDownloadFileEndpoint) {
49+
$this->allowAnonymous = false;
50+
}
51+
52+
return parent::beforeAction($action);
53+
}
54+
4155
/**
4256
* Force the download of a given $url. We do it this way to prevent people
4357
* from downloading things that are outside of the server root.

src/models/Settings.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,31 @@
2222
*/
2323
class Settings extends Model
2424
{
25-
// Static Methods
25+
// Public Properties
2626
// =========================================================================
2727

2828
/**
2929
* The path to the ffmpeg binary
3030
*
3131
* @var string
3232
*/
33+
3334
public $ffmpegPath = '/usr/bin/ffmpeg';
3435

35-
// Public Properties
36-
// =========================================================================
3736
/**
3837
* The path to the ffprobe binary
3938
*
4039
* @var string
4140
*/
4241
public $ffprobePath = '/usr/bin/ffprobe';
42+
4343
/**
4444
* The options to use for ffprobe
4545
*
4646
* @var string
4747
*/
4848
public $ffprobeOptions = '-v quiet -print_format json -show_format -show_streams';
49+
4950
/**
5051
* The path where the transcoded videos are stored; must have a trailing /
5152
* Yii2 aliases are supported here
@@ -59,6 +60,7 @@ class Settings extends Model
5960
'thumbnail' => '@webroot/transcoder/',
6061
'gif' => '@webroot/transcoder/',
6162
];
63+
6264
/**
6365
* The URL where the transcoded videos are stored; must have a trailing /
6466
* Yii2 aliases are supported here
@@ -72,25 +74,34 @@ class Settings extends Model
7274
'thumbnail' => '@web/transcoder/',
7375
'gif' => '@web/transcoder/',
7476
];
77+
78+
/**
79+
* @var bool Determines whether the download file endpoint should be enabled for anonymous frontend access
80+
*/
81+
public $enableDownloadFileEndpoint = false;
82+
7583
/**
7684
* Use a md5 hash for the filenames instead of parameterized naming
7785
*
7886
* @var bool
7987
*/
8088
public $useHashedNames = false;
89+
8190
/**
8291
* if a upload location has a subfolder defined, add this to the transcoder
8392
* paths too
8493
*
8594
* @var bool
8695
*/
8796
public $createSubfolders = true;
97+
8898
/**
8999
* clear caches when somebody clears all caches from the CP?
90100
*
91101
* @var bool
92102
*/
93103
public $clearCaches = false;
104+
94105
/**
95106
* Preset video encoders
96107
*
@@ -123,6 +134,7 @@ class Settings extends Model
123134
'threads' => '0',
124135
],
125136
];
137+
126138
/**
127139
* Preset audio encoders
128140
*
@@ -152,6 +164,7 @@ class Settings extends Model
152164
'threads' => '0',
153165
],
154166
];
167+
155168
/**
156169
* Default options for encoded videos
157170
*
@@ -174,6 +187,7 @@ class Settings extends Model
174187
'aspectRatio' => 'letterbox',
175188
'letterboxColor' => '',
176189
];
190+
177191
/**
178192
* Default options for video thumbnails
179193
*
@@ -189,6 +203,7 @@ class Settings extends Model
189203
'aspectRatio' => 'letterbox',
190204
'letterboxColor' => '',
191205
];
206+
192207
/**
193208
* Default options for encoded videos
194209
*
@@ -202,6 +217,7 @@ class Settings extends Model
202217
'synchronous' => false,
203218
'stripMetadata' => false
204219
];
220+
205221
/**
206222
* Default options for encoded GIF
207223
*
@@ -263,6 +279,7 @@ public function rules()
263279
['transcoderPaths', ArrayValidator::class],
264280
['transcoderPaths', 'required'],
265281
['transcoderUrls', ArrayValidator::class],
282+
['enableDownloadFileEndpoint', 'boolean'],
266283
['useHashedNames', 'boolean'],
267284
['createSubfolders', 'boolean'],
268285
['clearCaches', 'boolean'],

0 commit comments

Comments
 (0)