Add download forcing
This commit is contained in:
parent
428645245b
commit
172131e1e6
1 changed files with 26 additions and 7 deletions
|
@ -36,15 +36,28 @@ class TrackerController extends Controller
|
||||||
$viewMode = $request->input('show', null);
|
$viewMode = $request->input('show', null);
|
||||||
$fromCheckin = $request->input('from', null);
|
$fromCheckin = $request->input('from', null);
|
||||||
$toCheckin = $request->input('to', null);
|
$toCheckin = $request->input('to', null);
|
||||||
|
$forceDownload = $request->input('force', false);
|
||||||
$tripData = $this->get_trip_data($tripId);
|
|
||||||
|
$tripData = $this->get_trip_data($tripId, $forceDownload);
|
||||||
|
|
||||||
if ($fromCheckin) {
|
if ($fromCheckin) {
|
||||||
$tripData->checkins = array_filter($tripData->checkins, function($key) use ($fromCheckin) { return $key >= $fromCheckin; }, ARRAY_FILTER_USE_KEY);
|
$tripData->checkins = array_filter(
|
||||||
|
$tripData->checkins,
|
||||||
|
function($key) use ($fromCheckin) {
|
||||||
|
return $key >= $fromCheckin;
|
||||||
|
},
|
||||||
|
ARRAY_FILTER_USE_KEY
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($toCheckin) {
|
if ($toCheckin) {
|
||||||
$tripData->checkins = array_filter($tripData->checkins, function($key) use ($toCheckin) { return $key <= $toCheckin; }, ARRAY_FILTER_USE_KEY);
|
$tripData->checkins = array_filter(
|
||||||
|
$tripData->checkins,
|
||||||
|
function($key) use ($toCheckin) {
|
||||||
|
return $key <= $toCheckin;
|
||||||
|
},
|
||||||
|
ARRAY_FILTER_USE_KEY
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
|
@ -75,15 +88,16 @@ class TrackerController extends Controller
|
||||||
* 3. If new trip data is downloaded, overwrite any cached data.
|
* 3. If new trip data is downloaded, overwrite any cached data.
|
||||||
*
|
*
|
||||||
* @param string $tripId
|
* @param string $tripId
|
||||||
|
* @param bool $forceDownload
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_trip_data(string $tripId) {
|
public function get_trip_data(string $tripId, bool $forceDownload = false) {
|
||||||
$tripFileName = ( $tripId ?? config('app.current_trip_id') ) . '.json';
|
$tripFileName = ( $tripId ?? config('app.current_trip_id') ) . '.json';
|
||||||
|
|
||||||
// Returns the cached trip data if the trip is inactive (i.e., finished)
|
// Returns the cached trip data if the trip is inactive (i.e., finished)
|
||||||
// or less than 1–3 hours old, depending on whether it was tracking
|
// or less than 1–3 hours old, depending on whether it was tracking
|
||||||
// at last check or not.
|
// at last check or not.
|
||||||
if (Storage::disk('local')->exists($tripFileName)) {
|
if (!$forceDownload && Storage::disk('local')->exists($tripFileName)) {
|
||||||
Log::debug("Cached trip file '{$tripFileName}' found...");
|
Log::debug("Cached trip file '{$tripFileName}' found...");
|
||||||
$cachedData = json_decode(Storage::disk('local')->get($tripFileName))->trip;
|
$cachedData = json_decode(Storage::disk('local')->get($tripFileName))->trip;
|
||||||
|
|
||||||
|
@ -106,7 +120,12 @@ class TrackerController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, download the trip data from the Wayward API.
|
// Otherwise, download the trip data from the Wayward API.
|
||||||
Log::debug("No cached trip file found for '{$tripFileName}'.");
|
if ($forceDownload) {
|
||||||
|
Log::debug("Forcing download for '{$tripFileName}'.");
|
||||||
|
} else {
|
||||||
|
Log::debug("No cached trip file found for '{$tripFileName}'.");
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client([
|
$client = new Client([
|
||||||
'base_uri' => 'https://app.wayward.travel/',
|
'base_uri' => 'https://app.wayward.travel/',
|
||||||
'timeout' => 3.0
|
'timeout' => 3.0
|
||||||
|
|
Loading…
Reference in a new issue