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:
parent
c11e0e8411
commit
113a865019
@ -24,7 +24,7 @@ class UpdateHelper
|
|||||||
*/
|
*/
|
||||||
public static function checkForUpdates()
|
public static function checkForUpdates()
|
||||||
{
|
{
|
||||||
$currentVersion = config('linkace.version');
|
$currentVersion = getVersionFromPackage();
|
||||||
$latestVersion = self::getCurrentVersionFromAPI();
|
$latestVersion = self::getCurrentVersionFromAPI();
|
||||||
|
|
||||||
if ($latestVersion === null) {
|
if ($latestVersion === null) {
|
||||||
|
@ -7,6 +7,7 @@ use App\Models\Link;
|
|||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shorthand for the current user settings
|
* Shorthand for the current user settings
|
||||||
@ -196,3 +197,19 @@ function linkTarget(): string
|
|||||||
{
|
{
|
||||||
return usersettings('links_new_tab') ? 'target="_blank" rel="noopener noreferrer"' : '';
|
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;
|
||||||
|
}
|
||||||
|
@ -21,11 +21,8 @@ class SystemSettingsController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function getSystemSettings(): View
|
public function getSystemSettings(): View
|
||||||
{
|
{
|
||||||
$packageInfo = json_decode(File::get(base_path('package.json')));
|
|
||||||
$linkaceVersion = 'v' . $packageInfo->version;
|
|
||||||
|
|
||||||
return view('actions.settings.system', [
|
return view('actions.settings.system', [
|
||||||
'linkaceVersion' => $linkaceVersion,
|
'linkaceVersion' => getVersionFromPackage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
* @param Request $request
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
|
@ -43,6 +43,11 @@ return [
|
|||||||
|
|
||||||
'disks' => [
|
'disks' => [
|
||||||
|
|
||||||
|
'root' => [
|
||||||
|
'driver' => 'local',
|
||||||
|
'root' => base_path(),
|
||||||
|
],
|
||||||
|
|
||||||
'local' => [
|
'local' => [
|
||||||
'driver' => 'local',
|
'driver' => 'local',
|
||||||
'root' => storage_path('app'),
|
'root' => storage_path('app'),
|
||||||
|
@ -29,11 +29,6 @@ export default class UpdateCheck {
|
|||||||
this.$running.classList.add('d-none');
|
this.$running.classList.add('d-none');
|
||||||
|
|
||||||
if (typeof this.result === 'string') {
|
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.innerText = this.$versionFound.innerText.replace('#VERSION#', this.result);
|
||||||
this.$versionFound.classList.remove('d-none');
|
this.$versionFound.classList.remove('d-none');
|
||||||
} else if (this.result === true) {
|
} else if (this.result === true) {
|
||||||
|
@ -6,6 +6,7 @@ use App\Models\Link;
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class HelperFunctionsTest extends TestCase
|
class HelperFunctionsTest extends TestCase
|
||||||
@ -132,4 +133,31 @@ class HelperFunctionsTest extends TestCase
|
|||||||
|
|
||||||
$this->assertNull($link);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user