Fix 'is' middleware
Diff
storage/stats.json | 1 +
app/Http/routes.php | 1 +
app/Http/Controllers/StatsController.php | 34 ++++++++++++++++++++++++++--------
app/Http/Middleware/IsGroup.php | 6 +++---
4 files changed, 29 insertions(+), 13 deletions(-)
@@ -1,0 +1,1 @@
{"dj":"Unset","listeners":2,"artist":"Sigma & Rita Ora","song":"Coming Home"}
@@ -119,5 +119,6 @@
Route::get('timetable', ['as' => 'timetable', 'uses' => 'DJ\TimetableController@getJSONTimetable']);
Route::get('event/all', ['as' => 'events', 'uses' => 'Event\TimetableController@getJSONTimetable']);
Route::get('event/current', ['as' => 'event.current', 'uses' => 'Event\TimetableController@getCurrentEvent']);
Route::get('stats', ['as' => 'stats', 'uses' => 'StatsController@s']);
Route::post('request', ['as' => 'request', 'uses' => 'DJ\RequestController@request']);
});
@@ -1,10 +1,13 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Models\ConnectionInfo;
use App\Models\Timetable;
use Carbon\Carbon;
use LastFmApi\Api\AuthApi;
use LastFmApi\Api\TrackApi;
use stdClass;
class StatsController extends Controller
{
@@ -29,17 +32,28 @@
if (empty($stats->songtitle)) {
$ret = ['status' => false];
} else {
$old = json_decode(file_get_contents(storage_path('stats.json')));
$ret['dj'] = empty($json->dj) ? $old->dj : $stats->dj;
$ret['listeners'] = $stats->listeners;
if (count(explode(' - ', $json->songtitle, 2)) == 2) {
list($artist, $song) = explode(' - ', $json->songtitle, 2);
$old = file_exists(storage_path('stats.json')) ?
json_decode(file_get_contents(storage_path('stats.json'))) : false;
$ret['dj'] = empty($stats->dj) ? ($old ? $old->dj : 'Unset') : $stats->dj;
$ret['listeners'] = $stats->currentlisteners;
if (!$ret['dj']) {
$timetable = Timetable::where('week', Carbon::now()->weekOfYear)
->where('year', Carbon::now()->year)
->where('day', Carbon::now()->format('N') - 1)
->where('hour', Carbon::now()->hour)
->first();
$ret['dj'] = $timetable ? $timetable->user->getDisplayName()->toHtml() : 'Offline';
}
if (count(explode(' - ', $stats->songtitle, 2)) == 2) {
list($artist, $song) = explode(' - ', $stats->songtitle, 2);
$ret['artist'] = $artist;
$ret['song'] = $song;
if ($stats->songtitle !== "{$old->artist} - {$old->song}") {
/*if ($stats->songtitle !== "{$old->artist} - {$old->song}") {
$lastfm = new AuthApi('getsession', [
'apiKey' => env('LASTFM_API_KEY'),
'secret' => env('LASTFM_SECRET'),
@@ -47,9 +61,9 @@
]);
$trackApi = new TrackApi($lastfm);
$trackApi->scrobble(['artist' => $artist, 'track' => $song, 'timestamp' => 400]);
}
}*/
} else {
$ret['song'] = $json->songtitle;
$ret['song'] = $stats->songtitle;
}
file_put_contents(storage_path('stats.json'), json_encode($ret));
@@ -13,10 +13,10 @@
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string $group
* @param array $group
* @return mixed
*/
public function handle($request, Closure $next, $group)
public function handle($request, Closure $next, ...$group)
{
if ($group === 'admin') {
if (!Auth::user()->isAdmin()) {
@@ -42,7 +42,7 @@
return redirect()->route('dashboard::home');
}
} elseif (!Auth::user()->is(...explode(',', $group))) {
} elseif (!Auth::user()->is(...$group)) {
Session::flash('msg', [
'type' => 'danger',
'msg' => sprintf('%s %s',