Add option for denying directly downloading textures

This commit is contained in:
Pig Fang 2018-07-22 09:38:42 +08:00
parent 6031562851
commit 10a0cd09db
7 changed files with 24 additions and 2 deletions

View File

@ -205,6 +205,8 @@ class AdminController extends Controller
$form->checkbox('auto_del_invalid_texture')->label()->hint();
$form->checkbox('allow_downloading_texture')->label();
$form->text('texture_name_regexp')->hint()->placeholder();
$form->textarea('comment_script')->rows(6)->description();

View File

@ -201,6 +201,10 @@ class TextureController extends Controller
}
public function raw($tid) {
if (!option('allow_downloading_texture')) {
abort(404);
}
if ($t = Texture::find($tid)) {
if (Storage::disk('textures')->has($t->hash)) {

View File

@ -32,6 +32,7 @@ return [
'update_source' => 'https://work.prinzeugen.net/update.json',
'copyright_text' => '<strong>Copyright &copy; '.getdate()['year'].' <a href="{site_url}">{site_name}</a>.</strong> All rights reserved.',
'auto_del_invalid_texture' => 'false',
'allow_downloading_texture' => 'true',
'texture_name_regexp' => '',
'return_200_when_notfound' => 'false',
'cache_expire_time' => '31536000',

View File

@ -103,6 +103,9 @@ general:
title: Invalid Textures
label: Delete invalid textures automatically.
hint: Delete textures records whose file no longer exists from skinlib.
allow_downloading_texture:
title: Downloading Textures
label: Allow users to directly download the source file of a skinlib item.
texture_name_regexp:
title: Texture Name Rules
hint: The RegExp for validating name of uploaded textures. Leave empty to allow any character except single, double quote and backslash.

View File

@ -103,6 +103,9 @@ general:
title: 失效材质
label: 自动删除失效材质
hint: 自动从皮肤库中删除文件不存在的材质记录
allow_downloading_texture:
title: 直接下载材质
label: 允许用户直接下载皮肤库中材质的原始文件
texture_name_regexp:
title: 材质名称规则
hint: 皮肤库上传材质时名称的正则表达式。留空表示允许使用除半角单双引号、反斜杠以外的任意字符。

View File

@ -68,10 +68,16 @@
</tr>
<tr>
<td>Hash
@if (option('allow_downloading_texture'))
<i class="fa fa-question-circle" title="@lang('skinlib.show.download-raw')" data-toggle="tooltip" data-placement="top"></i>
@endif
</td>
<td>
@if (option('allow_downloading_texture'))
<a href="{{ url('raw/'.$texture->tid) }}.png" title="{{ $texture->hash }}">{{ substr($texture->hash, 0, 15) }}...</a>
@else
<span title="{{ $texture->hash }}">{{ substr($texture->hash, 0, 15) }}...</span>
@endif
</td>
</tr>
<tr>

View File

@ -249,7 +249,10 @@ class TextureControllerTest extends TestCase
// Texture is deleted
Storage::disk('textures')->delete($steve->hash);
$this->get("/raw/{$steve->tid}.png")
->assertSee(trans('general.texture-deleted'));
$this->get("/raw/{$steve->tid}.png")->assertNotFound();
// Disallow downloading texture directly
config(['allow_downloading_texture' => false]);
$this->get("/raw/{$steve->tid}.png")->assertNotFound();
}
}