1
0
mirror of https://github.com/Kovah/LinkAce.git synced 2025-01-18 05:38:40 +01:00

Rewrite of the LinkAce version handling and update checks

This commit is contained in:
Kovah 2020-07-02 17:14:29 +02:00
parent c11e0e8411
commit 113a865019
No known key found for this signature in database
GPG Key ID: AAAA031BA9830D7B
7 changed files with 55 additions and 10 deletions

View File

@ -24,7 +24,7 @@ class UpdateHelper
*/
public static function checkForUpdates()
{
$currentVersion = config('linkace.version');
$currentVersion = getVersionFromPackage();
$latestVersion = self::getCurrentVersionFromAPI();
if ($latestVersion === null) {

View File

@ -7,6 +7,7 @@ use App\Models\Link;
use App\Models\Setting;
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
/**
* Shorthand for the current user settings
@ -196,3 +197,19 @@ function linkTarget(): string
{
return usersettings('links_new_tab') ? 'target="_blank" rel="noopener noreferrer"' : '';
}
/**
* Get the current version from the package.json file
*
* @return string|null
*/
function getVersionFromPackage(): ?string
{
try {
$package = json_decode(Storage::disk('root')->get('package.json'), false);
} catch (\Exception $e) {
return null;
}
return isset($package->version) ? 'v' . $package->version : null;
}

View File

@ -21,11 +21,8 @@ class SystemSettingsController extends Controller
*/
public function getSystemSettings(): View
{
$packageInfo = json_decode(File::get(base_path('package.json')));
$linkaceVersion = 'v' . $packageInfo->version;
return view('actions.settings.system', [
'linkaceVersion' => $linkaceVersion,
'linkaceVersion' => getVersionFromPackage(),
]);
}

View File

@ -113,6 +113,9 @@ class FetchController extends Controller
}
/**
* Returns the HTML for a given URL to prevent CORS issues in the frontend
* implementation.
*
* @param Request $request
* @return Response
*/

View File

@ -43,6 +43,11 @@ return [
'disks' => [
'root' => [
'driver' => 'local',
'root' => base_path(),
],
'local' => [
'driver' => 'local',
'root' => storage_path('app'),

View File

@ -29,11 +29,6 @@ export default class UpdateCheck {
this.$running.classList.add('d-none');
if (typeof this.result === 'string') {
if (this.currentVersion === this.result) {
this.$success.classList.remove('d-none');
return;
}
this.$versionFound.innerText = this.$versionFound.innerText.replace('#VERSION#', this.result);
this.$versionFound.classList.remove('d-none');
} else if (this.result === true) {

View File

@ -6,6 +6,7 @@ use App\Models\Link;
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class HelperFunctionsTest extends TestCase
@ -132,4 +133,31 @@ class HelperFunctionsTest extends TestCase
$this->assertNull($link);
}
public function testVersionFromPackage(): void
{
Storage::fake('root')->put('package.json', '{"version":"0.0.39"}');
$version = getVersionFromPackage();
$this->assertEquals('v0.0.39', $version);
}
public function testVersionFromPackageWithInvalidFile(): void
{
Storage::fake('root')->put('package.json', '{"foo":"bar"}');
$version = getVersionFromPackage(); // should now return null because there is no version field
$this->assertNull($version);
}
public function testVersionFromPackageWithMissingFile(): void
{
Storage::fake('root');
$version = getVersionFromPackage(); // should now return null because there is no package.json
$this->assertNull($version);
}
}