Skip to content

Commit

Permalink
Pass client parent id to jellyfin
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Nov 7, 2024
1 parent 71ba594 commit f0fef39
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/src/modules/jellyfin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import 'package:dio/dio.dart'
show DioException, ErrorInterceptorHandler, Interceptor, RequestInterceptorHandler, RequestOptions;
import 'package:built_collection/built_collection.dart';

final _mediaInfoAuthHeader =
'MediaBrowser Client="$botName", Device="DiscordBot ($botName)", DeviceId="$botName", Version="$version"';
String _getMediaInfoAuthHeader(String parentId) =>
'MediaBrowser Client="$botName", Device="DiscordBot ($botName, $parentId)", DeviceId="${botName}_$parentId", Version="$version"';

MessageBuilder getWizarrRedeemInvitationMessageBuilder(
WizarrClient client, String code, Snowflake userId, Snowflake parentId, String configName) {
Expand Down Expand Up @@ -297,21 +297,26 @@ class AnonymousJellyfinClient {

class TokenAuthInterceptor extends AuthInterceptor {
final String token;
final Snowflake parentId;

TokenAuthInterceptor(this.token);
TokenAuthInterceptor(this.token, this.parentId);

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
options.headers['Authorization'] = '$_mediaInfoAuthHeader, Token="$token"';
options.headers['Authorization'] = '${_getMediaInfoAuthHeader(parentId.toString())}, Token="$token"';

super.onRequest(options, handler);
}
}

class AnonAuthInterceptor extends AuthInterceptor {
final Snowflake parentId;

AnonAuthInterceptor(this.parentId);

@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
options.headers['Authorization'] = _mediaInfoAuthHeader;
options.headers['Authorization'] = _getMediaInfoAuthHeader(parentId.toString());

super.onRequest(options, handler);
}
Expand Down Expand Up @@ -614,15 +619,17 @@ class JellyfinModuleV2 implements RequiresInitialization {

AnonymousJellyfinClient createJellyfinClientAnonymous(JellyfinConfig config) {
return AnonymousJellyfinClient(
jellyfinClient: Tentacle(basePathOverride: config.basePath, interceptors: [AnonAuthInterceptor()]),
jellyfinClient:
Tentacle(basePathOverride: config.basePath, interceptors: [AnonAuthInterceptor(config.parentId)]),
config: config);
}

AuthenticatedJellyfinClient createJellyfinClientAuthenticated(JellyfinConfigUser configUser) {
return AuthenticatedJellyfinClient(
Tentacle(
basePathOverride: configUser.config!.basePath,
interceptors: [TokenAuthInterceptor(configUser.token), AuthResponseErrorInterceptor()]),
Tentacle(basePathOverride: configUser.config!.basePath, interceptors: [
TokenAuthInterceptor(configUser.token, configUser.config?.parentId ?? configUser.userId),
AuthResponseErrorInterceptor()
]),
configUser);
}

Expand Down

0 comments on commit f0fef39

Please sign in to comment.