mirror of
https://github.com/immich-app/immich.git
synced 2025-06-04 22:24:26 -04:00
add session expiration checks
This commit is contained in:
parent
ef3d1f565d
commit
9e9b8fdb64
@ -98,6 +98,23 @@ class GCastService implements ICastDestinationService {
|
|||||||
return serverUrl?.startsWith("https://") ?? false;
|
return serverUrl?.startsWith("https://") ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isSessionValid() {
|
||||||
|
// check if we already have a session token
|
||||||
|
// we should always have a expiration date
|
||||||
|
if (sessionKey == null || sessionKey?.expiresAt == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final tokenExpiration = DateTime.parse(sessionKey!.expiresAt!);
|
||||||
|
|
||||||
|
// we want to make sure we have at least 10 seconds remaining in the session
|
||||||
|
// this is to account for network latency and other delays when sending the request
|
||||||
|
final bufferedExpiration =
|
||||||
|
tokenExpiration.subtract(const Duration(seconds: 10));
|
||||||
|
|
||||||
|
return bufferedExpiration.isAfter(DateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void loadMedia(Asset asset, bool reload) async {
|
void loadMedia(Asset asset, bool reload) async {
|
||||||
if (!isConnected) {
|
if (!isConnected) {
|
||||||
@ -109,11 +126,13 @@ class GCastService implements ICastDestinationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create a session key
|
// create a session key
|
||||||
sessionKey ??= await _sessionsApiService.createSession(
|
if (!isSessionValid()) {
|
||||||
|
sessionKey = await _sessionsApiService.createSession(
|
||||||
"Cast",
|
"Cast",
|
||||||
"Google Cast",
|
"Google Cast",
|
||||||
duration: const Duration(minutes: 15).inSeconds,
|
duration: const Duration(minutes: 15).inSeconds,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
final unauthenticatedUrl = asset.isVideo
|
final unauthenticatedUrl = asset.isVideo
|
||||||
? getPlaybackUrlForRemoteId(
|
? getPlaybackUrlForRemoteId(
|
||||||
@ -171,6 +190,6 @@ class GCastService implements ICastDestinationService {
|
|||||||
device
|
device
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(growable: false);
|
.toList(growable: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user