mirror of
https://github.com/feeddeck/feeddeck.git
synced 2026-03-11 17:47:47 -05:00
Improve the media handling within the app. We do not save the media files for items to the Supabase storage anymore. The source icons are now only saved in the Supabase storage, the usage of an url as source icon is not possible anymore. The media files for items are directly retrieved from the corresponding url or for the web version from the "image-proxy-v1" Supabase function. If the image is retireved from the Supabase function we cache the image in the browser via the cache control headers. If the image is directly retrieved from it's url it's cached by the "CachedNetworkImage" widget.
33 lines
1.1 KiB
Dart
33 lines
1.1 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
|
|
import 'package:feeddeck/repositories/settings_repository.dart';
|
|
|
|
/// [FDImageType] is a enum value which defines the image type. An image can be
|
|
/// related to an item or a source.
|
|
enum FDImageType {
|
|
item,
|
|
source,
|
|
}
|
|
|
|
/// [getImageUrl] returns the correct image url to use for the provided image
|
|
/// url:
|
|
/// - If the [imageType] is [FDImageType.source] the image is always requested
|
|
/// from the Supabase storage.
|
|
/// - If the [imageType] is [FDImageType.item] and the app runs on the web, the
|
|
/// image is proxied through the Supabase functions.
|
|
/// - If the [imageType] is [FDImageType.item] and the app runs on a mobile or
|
|
/// desktop device, the image is requested directly from the provided url.
|
|
String getImageUrl(FDImageType imageType, String imageUrl) {
|
|
if (imageType == FDImageType.source) {
|
|
return '${SettingsRepository().supabaseUrl}/storage/v1/object/public/sources/$imageUrl';
|
|
}
|
|
|
|
if (kIsWeb) {
|
|
return '${Supabase.instance.client.functionsUrl}/image-proxy-v1?media=${Uri.encodeQueryComponent(imageUrl)}';
|
|
}
|
|
|
|
return imageUrl;
|
|
}
|