remove auto update check

This commit is contained in:
Pig Fang 2020-01-05 17:37:56 +08:00
parent c3a0018219
commit d7a60a842d
12 changed files with 3 additions and 211 deletions

View File

@ -58,21 +58,6 @@ class MarketController extends Controller
return $plugins;
}
public function checkUpdates(PluginManager $manager)
{
$pluginsHaveUpdate = collect($this->getAllAvailablePlugins())
->filter(function ($item) use ($manager) {
$plugin = $manager->get($item['name']);
return $plugin && Comparator::greaterThan($item['version'], $plugin->version);
});
return json([
'available' => $pluginsHaveUpdate->isNotEmpty(),
'plugins' => $pluginsHaveUpdate->values()->all(),
]);
}
public function download(Request $request, PluginManager $manager, PackageManager $package)
{
$name = $request->get('name');

View File

@ -38,11 +38,6 @@ class UpdateController extends Controller
return view('admin.update', compact('info', 'error', 'extra'));
}
public function checkUpdates()
{
return json(['available' => $this->canUpdate()]);
}
public function download(Request $request, PackageManager $package, Filesystem $filesystem)
{
if (!$this->canUpdate()) {

View File

@ -51,9 +51,6 @@ class FootComposer
if ($pluginI18n = $this->javascript->plugin($locale)) {
$scripts[] = $pluginI18n;
}
if ($this->request->is('admin*') && auth()->user()->permission >= User::SUPER_ADMIN) {
$scripts[] = $this->webpack->url('check-updates.js');
}
if (Str::startsWith(config('app.asset.env'), 'dev')) {
$scripts[] = $this->webpack->url('style.js');
}

View File

@ -1,39 +0,0 @@
// KEEP THIS FILE DEPENDENCY-FREE!
const init: RequestInit = {
credentials: 'same-origin',
headers: new Headers({
Accept: 'application/json',
}),
}
export async function checkForUpdates(): Promise<void> {
const response = await fetch(`${blessing.base_url}/admin/update/check`, init)
if (response.ok) {
const data = await response.json()
const el = document.querySelector(`[href="${blessing.base_url}/admin/update"] p`)
if (data.available && el) {
el.innerHTML += '<span class="right badge badge-primary">New</span>'
}
}
}
export async function checkForPluginUpdates(): Promise<void> {
const response = await fetch(`${blessing.base_url}/admin/plugins/market/check`, init)
if (response.ok) {
const data = await response.json()
const el = document.querySelector(`[href="${blessing.base_url}/admin/plugins/market"] p`)
if (data.available && el) {
const length = data.plugins.length as number
el.innerHTML += `<span class="right badge badge-success">${length}</span>`
}
}
}
// istanbul ignore next
if (process.env.NODE_ENV !== 'test') {
checkForUpdates()
checkForPluginUpdates()
}

View File

@ -1,69 +0,0 @@
import {
checkForUpdates,
checkForPluginUpdates,
} from '@/scripts/check-updates'
import { init } from '@/scripts/net'
test('check for BS updates', async () => {
window.fetch = jest.fn()
.mockResolvedValueOnce({ ok: false })
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ available: false }),
})
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ available: true }),
})
document.body.innerHTML = '<a href="/admin/update"><p></p></a>'
await checkForUpdates()
expect(window.fetch).toBeCalledWith('/admin/update/check', init)
expect(document.querySelector('p')!.innerHTML).toBe('')
await checkForUpdates()
expect(document.querySelector('p')!.innerHTML).toBe('')
await checkForUpdates()
expect(document.querySelector('p')!.innerHTML).toContain('New')
})
test('check for plugins updates', async () => {
window.fetch = jest.fn()
.mockResolvedValueOnce({ ok: false })
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ available: false }),
})
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ available: true, plugins: [{}] }),
})
document.body.innerHTML = '<a href="/admin/plugins/market"><p></p></a>'
await checkForPluginUpdates()
expect(window.fetch).toBeCalledWith('/admin/plugins/market/check', init)
expect(document.querySelector('p')!.innerHTML).toBe('')
await checkForPluginUpdates()
expect(document.querySelector('p')!.innerHTML).toBe('')
await checkForPluginUpdates()
expect(document.querySelector('p')!.innerHTML).toContain('1')
})
test('do not update anything if element not found', async () => {
window.fetch = jest.fn()
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ available: true, latest: '4.0.0' }),
})
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve({ available: true, plugins: [{}] }),
})
await Promise.all([checkForUpdates, checkForPluginUpdates])
})

View File

@ -62,6 +62,7 @@
- Removed enabling or disabling Redis via Web UI.
- Removed Legacy API from core. (Install plugin if you need it.)
- Removed Universal Skin API from core. (Install plugin if you need it.)
- Removed auto update check.
## Internal Changes

View File

@ -62,6 +62,7 @@
- 移除通过 UI 来开启或关闭 Redis 的功能
- 移除「传统皮肤加载方式」(如有需要,请安装插件)
- 移除 Universal Skin API如有需要请安装插件
- 移除自动更新检查
## 内部更改

View File

@ -158,13 +158,11 @@ Route::group(['middleware' => ['authorize', 'admin'], 'prefix' => 'admin'], func
Route::view('/market', 'admin.market');
Route::get('/market-data', 'MarketController@marketData');
Route::get('/market/check', 'MarketController@checkUpdates');
Route::post('/market/download', 'MarketController@download');
});
Route::group(['prefix' => 'update', 'middleware' => 'super-admin'], function () {
Route::any('', 'UpdateController@showUpdatePage');
Route::get('/check', 'UpdateController@checkUpdates');
Route::any('/download', 'UpdateController@download');
});
});

View File

@ -91,58 +91,6 @@ class MarketControllerTest extends TestCase
]);
}
public function testCheckUpdates()
{
$this->setupGuzzleClientMock();
$fakeRegistry = json_encode(['packages' => [
[
'name' => 'fake',
'version' => '0.0.1',
'dist' => ['url' => 'http://nowhere.test/', 'shasum' => 'deadbeef'],
],
]]);
// Not installed
$this->appendToGuzzleQueue(200, [], $fakeRegistry);
$this->getJson('/admin/plugins/market/check')
->assertJson([
'available' => false,
'plugins' => [],
]);
$this->mock(PluginManager::class, function ($mock) {
$mock->shouldReceive('get')
->with('fake')
->twice()
->andReturn(new Plugin('', ['name' => 'fake', 'version' => '0.0.1']));
});
// Plugin up-to-date
$this->appendToGuzzleQueue(200, [], $fakeRegistry);
$this->getJson('/admin/plugins/market/check')
->assertJson([
'available' => false,
'plugins' => [],
]);
// New version available
$fakeRegistry = json_encode(['packages' => [
[
'name' => 'fake',
'version' => '2.3.3',
'dist' => ['url' => 'http://nowhere.test/', 'shasum' => 'deadbeef'],
],
]]);
$this->appendToGuzzleQueue(200, [], $fakeRegistry);
$this->getJson('/admin/plugins/market/check')
->assertJson([
'available' => true,
'plugins' => [[
'name' => 'fake',
]],
]);
}
public function testMarketData()
{
$this->setupGuzzleClientMock([

View File

@ -54,21 +54,6 @@ class UpdateControllerTest extends TestCase
$this->get('/admin/update')->assertSee(config('app.version'))->assertSee('8.9.3');
}
public function testCheckUpdates()
{
$this->setupGuzzleClientMock();
// Update source is unavailable
$this->appendToGuzzleQueue([
new RequestException('Connection Error', new Request('GET', 'whatever')),
]);
$this->getJson('/admin/update/check')->assertJson(['available' => false]);
// New version available
$this->appendToGuzzleQueue(200, [], $this->mockFakeUpdateInfo('8.9.3'));
$this->getJson('/admin/update/check')->assertJson(['available' => true]);
}
public function testDownload()
{
$this->setupGuzzleClientMock();

View File

@ -38,10 +38,6 @@ class FootComposerTest extends TestCase
$this->mock(Webpack::class, function ($mock) {
$mock->shouldReceive('url')->with('style.css');
$mock->shouldReceive('url')->with('skins/skin-blue.min.css');
$mock->shouldReceive('url')
->with('check-updates.js')
->once()
->andReturn('check-updates.js');
$mock->shouldReceive('url')
->with('style.js')
->atLeast(1)
@ -55,12 +51,7 @@ class FootComposerTest extends TestCase
$this->get('/user')
->assertSee('en.js')
->assertSee('en_plugin.js')
->assertSee('app.js')
->assertDontSee('check-updates.js');
$superAdmin = factory(User::class, 'superAdmin')->make();
$this->actingAs($superAdmin);
$this->get('/admin')->assertSee('check-updates.js');
->assertSee('app.js');
}
public function testAddExtra()

View File

@ -13,7 +13,6 @@ const config = {
mode: devMode ? 'development' : 'production',
entry: {
app: './resources/assets/src/index.ts',
'check-updates': './resources/assets/src/scripts/check-updates.ts',
'language-chooser': './resources/assets/src/scripts/language-chooser.ts',
style: [
'bootstrap/dist/css/bootstrap.min.css',