1+ import 'dart:io' ;
2+
13import 'package:flutter/material.dart' ;
24import 'package:flutter/services.dart' ;
5+ import 'package:flutter_secure_storage/flutter_secure_storage.dart' ;
6+ import 'package:mime_type/mime_type.dart' ;
37import 'package:photo_view/photo_view.dart' ;
48import 'package:photo_view/photo_view_gallery.dart' ;
9+ import 'package:piwigo_ng/api/api_client.dart' ;
510import 'package:piwigo_ng/api/api_error.dart' ;
611import 'package:piwigo_ng/api/images.dart' ;
712import 'package:piwigo_ng/components/popup_list_item.dart' ;
@@ -11,6 +16,7 @@ import 'package:piwigo_ng/services/preferences_service.dart';
1116import 'package:piwigo_ng/utils/image_actions.dart' ;
1217import 'package:piwigo_ng/utils/localizations.dart' ;
1318import 'package:piwigo_ng/views/image/video_view.dart' ;
19+ import 'package:html_unescape/html_unescape.dart' ;
1420
1521/// Media Full Screen page
1622/// * Video player
@@ -60,6 +66,9 @@ class _ImageViewPageState extends State<ImageViewPage> {
6066 /// API Image Pagination
6167 int _imagePage = 0 ;
6268
69+ /// Server Cookie String
70+ String _serverCookie = '' ;
71+
6372 /// Initialize [PageView]
6473 @override
6574 void initState () {
@@ -73,6 +82,9 @@ class _ImageViewPageState extends State<ImageViewPage> {
7382 }
7483 }
7584 _pageController = PageController (initialPage: _page);
85+
86+ _loadCookies ();
87+
7688 super .initState ();
7789 }
7890
@@ -95,6 +107,17 @@ class _ImageViewPageState extends State<ImageViewPage> {
95107 });
96108 }
97109
110+ Future <void > _loadCookies () async {
111+ FlutterSecureStorage secureStorage = const FlutterSecureStorage ();
112+ String ? serverUrl = await secureStorage.read (key: 'SERVER_URL' );
113+ List <Cookie > cookies = await ApiClient .cookieJar.loadForRequest (Uri .parse (serverUrl! ));
114+
115+ String cookiesStr = cookies.map ((cookie) => '${cookie .name }=${cookie .value }' ).join ('; ' );
116+ setState (() {
117+ _serverCookie = cookiesStr;
118+ });
119+ }
120+
98121 /// Get image that is shown in the [PhotoViewGallery] at [_page]
99122 ImageModel get _currentImage => _imageList[_page];
100123
@@ -330,7 +353,7 @@ class _ImageViewPageState extends State<ImageViewPage> {
330353 child: GestureDetector (
331354 behavior: HitTestBehavior .opaque,
332355 onTap: () => _onToggleOverlay (MediaQuery .of (context).orientation),
333- child: PhotoViewGallery .builder (
356+ child: _serverCookie == '' ? null : PhotoViewGallery .builder (
334357 /// Compatibility with PageView and PhotoView
335358 pageController: _pageController,
336359 onPageChanged: (page) => setState (() {
@@ -358,13 +381,24 @@ class _ImageViewPageState extends State<ImageViewPage> {
358381 );
359382 }
360383
384+ String imageUrl = '' ;
385+ if (Preferences .getImageFullScreenSize == 'full' ) {
386+ imageUrl = image.elementUrl ?? '' ;
387+ imageUrl = HtmlUnescape ().convert (imageUrl);
388+ } else {
389+ imageUrl = image.getDerivativeFromString (Preferences .getImageFullScreenSize)? .url ?? '' ;
390+ }
391+
392+ ApiClient .cookieJar.loadForRequest (Uri .parse (imageUrl));
393+
361394 // Default behavior: Zoomable image
395+
362396 return PhotoViewGalleryPageOptions (
363397 heroAttributes: PhotoViewHeroAttributes (
364398 tag: "<hero image ${image .id }>" ,
365399 ),
366400 imageProvider: NetworkImage (
367- image. getDerivativeFromString ( Preferences .getImageFullScreenSize) ? .url ?? '' ,
401+ imageUrl, headers : { HttpHeaders .cookieHeader : _serverCookie} ,
368402 ),
369403 maxScale: 2.0 ,
370404 minScale: PhotoViewComputedScale .contained,
0 commit comments