mirror of
https://github.com/koel/koel
synced 2024-11-10 06:34:14 +00:00
Add a version check
This commit is contained in:
parent
a8d620b83d
commit
b3a93e4038
6 changed files with 65 additions and 2 deletions
|
@ -2,14 +2,19 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use Cache;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Foundation\Application as IlluminateApplication;
|
||||
use InvalidArgumentException;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Extends \Illuminate\Foundation\Application to override some defaults.
|
||||
*/
|
||||
class Application extends IlluminateApplication
|
||||
{
|
||||
const VERSION = '1.1';
|
||||
|
||||
/**
|
||||
* We have merged public path and base path.
|
||||
*
|
||||
|
@ -42,4 +47,30 @@ class Application extends IlluminateApplication
|
|||
|
||||
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version number of Koel from Github.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLatestVersion(Client $client = null)
|
||||
{
|
||||
$client = $client ?: new Client();
|
||||
|
||||
if ($v = Cache::get('latestKoelVersion')) {
|
||||
return $v;
|
||||
}
|
||||
|
||||
try {
|
||||
$v = json_decode($client->get('https://api.github.com/repos/phanan/koel/tags')->getBody())[0]->name;
|
||||
// Cache for a week
|
||||
Cache::put('latestKoelVersion', $v, 7 * 24 * 60);
|
||||
|
||||
return $v;
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
|
||||
return self::VERSION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Application;
|
||||
use App\Models\Artist;
|
||||
use App\Models\Interaction;
|
||||
use App\Models\Playlist;
|
||||
|
@ -32,6 +33,8 @@ class DataController extends Controller
|
|||
'users' => auth()->user()->is_admin ? User::all() : [],
|
||||
'currentUser' => auth()->user(),
|
||||
'useLastfm' => env('LASTFM_API_KEY') && env('LASTFM_API_SECRET'),
|
||||
'currentVersion' => Application::VERSION,
|
||||
'latestVersion' => auth()->user()->is_admin ? app()->getLatestVersion() : Application::VERSION,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class SongController extends Controller
|
|||
/**
|
||||
* Scrobble a song.
|
||||
*
|
||||
* @param Song $song
|
||||
* @param Song $song
|
||||
* @param string $timestamp The UNIX timestamp when the song started playing.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
|
|
|
@ -37,13 +37,15 @@
|
|||
"post-install-cmd": [
|
||||
"php artisan clear-compiled",
|
||||
"php artisan optimize",
|
||||
"php artisan cache:clear",
|
||||
"php -r \"if (!file_exists('.env')) copy('.env.example', '.env');\""
|
||||
],
|
||||
"pre-update-cmd": [
|
||||
"php artisan clear-compiled"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"php artisan optimize"
|
||||
"php artisan optimize",
|
||||
"php artisan cache:clear"
|
||||
],
|
||||
"post-root-package-install": [
|
||||
"php -r \"copy('.env.example', '.env');\""
|
||||
|
|
|
@ -43,6 +43,14 @@
|
|||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<a
|
||||
href="https://github.com/phanan/koel/releases"
|
||||
target="_blank"
|
||||
v-show="user.current.is_admin && sharedState.currentVersion < sharedState.latestVersion"
|
||||
class="new-ver">
|
||||
Koel version {{ sharedState.latestVersion }} is available!
|
||||
</a>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
|
@ -54,6 +62,7 @@
|
|||
import userStore from '../../../stores/user';
|
||||
import songStore from '../../../stores/song';
|
||||
import queueStore from '../../../stores/queue';
|
||||
import sharedStore from '../../../stores/shared';
|
||||
|
||||
export default {
|
||||
components: { playlists },
|
||||
|
@ -63,6 +72,7 @@
|
|||
currentView: 'queue',
|
||||
user: userStore.state,
|
||||
showing: !isMobile.phone,
|
||||
sharedState: sharedStore.state,
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -218,6 +228,21 @@
|
|||
}
|
||||
}
|
||||
|
||||
.new-ver {
|
||||
margin: 16px;
|
||||
padding: 16px;
|
||||
border: 1px solid $color2ndText;
|
||||
color: $colorMainText;
|
||||
opacity: .3;
|
||||
font-size: 90%;
|
||||
display: block;
|
||||
transition: .3s;
|
||||
|
||||
&:hover {
|
||||
opacity: .7;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@media only screen
|
||||
|
|
|
@ -22,6 +22,8 @@ export default {
|
|||
currentUser: null,
|
||||
playlists: [],
|
||||
useLastfm: false,
|
||||
currentVersion: '',
|
||||
latestVersion: '',
|
||||
},
|
||||
|
||||
init(cb = null) {
|
||||
|
|
Loading…
Reference in a new issue