diff --git a/app/Helper/UpdateHelper.php b/app/Helper/UpdateHelper.php index cb80dab0..70f57659 100644 --- a/app/Helper/UpdateHelper.php +++ b/app/Helper/UpdateHelper.php @@ -24,7 +24,7 @@ class UpdateHelper */ public static function checkForUpdates() { - $currentVersion = config('linkace.version'); + $currentVersion = getVersionFromPackage(); $latestVersion = self::getCurrentVersionFromAPI(); if ($latestVersion === null) { diff --git a/app/Helper/functions.php b/app/Helper/functions.php index f1d3579e..4be825f9 100644 --- a/app/Helper/functions.php +++ b/app/Helper/functions.php @@ -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; +} diff --git a/app/Http/Controllers/App/SystemSettingsController.php b/app/Http/Controllers/App/SystemSettingsController.php index 7a491f8f..3dfe4d34 100644 --- a/app/Http/Controllers/App/SystemSettingsController.php +++ b/app/Http/Controllers/App/SystemSettingsController.php @@ -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(), ]); } diff --git a/app/Http/Controllers/FetchController.php b/app/Http/Controllers/FetchController.php index 738bdeb2..c09b8934 100644 --- a/app/Http/Controllers/FetchController.php +++ b/app/Http/Controllers/FetchController.php @@ -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 */ diff --git a/config/filesystems.php b/config/filesystems.php index f839aad7..2b6ef55b 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -43,6 +43,11 @@ return [ 'disks' => [ + 'root' => [ + 'driver' => 'local', + 'root' => base_path(), + ], + 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), diff --git a/resources/assets/js/components/UpdateCheck.js b/resources/assets/js/components/UpdateCheck.js index be8c27be..2ddfa2e6 100644 --- a/resources/assets/js/components/UpdateCheck.js +++ b/resources/assets/js/components/UpdateCheck.js @@ -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) { diff --git a/tests/Helper/HelperFunctionsTest.php b/tests/Helper/HelperFunctionsTest.php index 81e0639a..ae4342c8 100644 --- a/tests/Helper/HelperFunctionsTest.php +++ b/tests/Helper/HelperFunctionsTest.php @@ -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); + } }