performerMedia function

  1. @riverpod
FutureOr<List<PerformerMediaItem>> performerMedia(
  1. Ref ref,
  2. String performerId
)

Implementation

@riverpod
FutureOr<List<PerformerMediaItem>> performerMedia(
  Ref ref,
  String performerId,
) async {
  ref.keepAlive();
  final client = ref.read(graphqlClientProvider);

  final result = await client.query$FindScenes(
    Options$Query$FindScenes(
      variables: Variables$Query$FindScenes(
        filter: Input$FindFilterType(page: 1, per_page: 24),
        scene_filter: Input$SceneFilterType(
          performers: Input$MultiCriterionInput(
            value: <String>[performerId],
            modifier: Enum$CriterionModifier.INCLUDES,
          ),
        ),
      ),
    ),
  );

  if (result.hasException) throw result.exception!;

  final prefs = ref.read(sharedPreferencesProvider);
  final storedServerUrl = prefs.getString('server_base_url')?.trim() ?? '';
  final normalizedServerUrl = normalizeGraphqlServerUrl(storedServerUrl);
  final endpoint = Uri.parse(
    normalizedServerUrl.isEmpty
        ? 'http://localhost:9999/graphql'
        : normalizedServerUrl,
  );

  return result.parsedData!.findScenes.scenes
      .map(
        (scene) => PerformerMediaItem(
          sceneId: scene.id,
          title: buildSceneDisplayTitle(
            title: scene.title,
            filePath: scene.files.isNotEmpty ? scene.files.first.path : null,
            streamPath: scene.paths.stream,
          ),
          thumbnailUrl: resolveGraphqlMediaUrl(
            rawUrl: scene.paths.screenshot ?? scene.paths.preview,
            graphqlEndpoint: endpoint,
          ),
        ),
      )
      .where((item) => item.thumbnailUrl.isNotEmpty)
      .toList();
}