Build "static-file-cdn" into core

This commit is contained in:
Pig Fang 2019-03-16 19:56:50 +08:00
parent e2d63da311
commit 3bf9b18d64
5 changed files with 40 additions and 12 deletions

View File

@ -7,6 +7,7 @@ use Carbon\Carbon;
use App\Models\User;
use App\Models\Player;
use App\Models\Texture;
use Illuminate\Support\Str;
use App\Services\OptionForm;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
@ -218,7 +219,23 @@ class AdminController extends Controller
$form->checkbox('return_204_when_notfound')->label()->description();
$form->text('cache_expire_time')->hint(OptionForm::AUTO_DETECT);
})->type('warning')->hint(OptionForm::AUTO_DETECT)->handle();
$form->text('cdn_address')
->hint(OptionForm::AUTO_DETECT)
->description(OptionForm::AUTO_DETECT);
})
->type('warning')
->hint(OptionForm::AUTO_DETECT)
->after(function () {
$cdnAddress = request('cdn_address');
if ($cdnAddress == null) {
$cdnAddress = '';
}
if (Str::endsWith($cdnAddress, '/')) {
$cdnAddress = substr($cdnAddress, 0, -1);
}
Option::set('cdn_address', $cdnAddress);
})
->handle();
return view('admin.options')->with('forms', compact('general', 'resources', 'announ'));
}

View File

@ -52,7 +52,8 @@ if (! function_exists('webpack_assets')) {
if (app()->environment('development')) {
return "http://127.0.0.1:8080/public/$relativeUri";
} else {
return url("app/$relativeUri");
$cdn = option('cdn_address');
return $cdn ? "$cdn/app/$relativeUri" : url("app/$relativeUri");
}
}
}

View File

@ -143,13 +143,10 @@ resources:
cache_expire_time:
title: Cache Exipre Time
hint: In seconds, 86400 = one day, 31536000 = one year.
update:
title: Check Update
check_update:
title: Check Update
label: Check available updates automatically and notify me.
update_source:
title: Update Source
description: 'Available update source list can be found at: <a href="https://github.com/printempw/blessing-skin-server/wiki/%E6%9B%B4%E6%96%B0%E6%BA%90%E5%88%97%E8%A1%A8">@GitHub Wiki</a>.'
cdn_address:
title: Front-end Assets CDN
hint: Front-end files won't be loaded if URL is unavailable.
description: |
The CDN URL you give must refer to a mirror of <code>/public</code> directory,
all the files of that directory will be loaded as CDN.<br>
<b>How to verify?</b> Verify if <code>{Your CDN URL}/app/index.js</code> can be accessed.

View File

@ -143,3 +143,9 @@ resources:
cache_expire_time:
title: 缓存失效时间
hint: 秒数86400 = 一天31536000 = 一年
cdn_address:
title: 前端资源文件 CDN
hint: 如果地址不对将导致前端文件无法加载
description: |
填写的 CDN 地址必须是 <code>/public</code> 目录的镜像,此目录下的所有文件都将会从 CDN 加载。<br>
<b>测试方法</b>:检查 <code>{填写的地址}/app/index.js</code> 是否能够访问。

View File

@ -137,11 +137,18 @@ class AdminControllerTest extends BrowserKitTestCase
->uncheck('auto_detect_asset_url')
->check('return_204_when_notfound')
->type('0', 'cache_expire_time')
->type('url/', 'cdn_address')
->press('submit_resources');
$this->assertTrue(option('force_ssl'));
$this->assertFalse(option('auto_detect_asset_url'));
$this->assertTrue(option('return_204_when_notfound'));
$this->assertEquals('0', option('cache_expire_time'));
$this->visit('/')->see('url/app/index.js');
$this->visit('/admin/options')
->type('', 'cdn_address')
->press('submit_resources');
$this->visit('/')->dontSee('url/app/index.js');
}
public function testUsers()