[mob][photos] upload files in web_view for public albums

This commit is contained in:
Aman Raj 2024-11-25 17:00:41 +05:30
parent c7d56c66a2
commit 799cb24c63
2 changed files with 29 additions and 1 deletions

View File

@ -71,6 +71,7 @@ class CollectionsService {
final _cachedPublicAlbumToken = <int, String>{};
final _cachedPublicAlbumJWTToken = <int, String>{};
final _cachedPublicCollectionID = <int>[];
final _cachedPublicAlbumKey = <String, String>{};
CollectionsService._privateConstructor() {
_db = CollectionsDB.instance;
@ -183,6 +184,7 @@ class CollectionsService {
_cachedPublicAlbumJWTToken.clear();
_cachedPublicCollectionID.clear();
_cachedKeys.clear();
_cachedPublicAlbumKey.clear();
}
Future<Map<int, int>> getCollectionIDsToBeSynced() async {
@ -1059,6 +1061,7 @@ class CollectionsService {
_cachedKeys[collection.id] = collectionKey;
_cachedPublicAlbumToken[collection.id] = authToken!;
_cachedPublicCollectionID.add(collection.id);
_cachedPublicAlbumKey[authToken] = albumKey;
collection.setName(_getDecryptedCollectionName(collection));
return collection;
} catch (e, s) {
@ -1114,6 +1117,13 @@ class CollectionsService {
}
}
Future<String> getPublicAlbumKey(String authToken) async {
if (_cachedPublicAlbumKey.containsKey(authToken)) {
return _cachedPublicAlbumKey[authToken]!;
}
return "";
}
Future<String?> getPublicAlbumToken(int collectionID) async {
if (_cachedPublicAlbumToken.containsKey(collectionID)) {
return _cachedPublicAlbumToken[collectionID];

View File

@ -33,6 +33,7 @@ import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
import "package:photos/ui/cast/auto.dart";
import "package:photos/ui/cast/choose.dart";
import "package:photos/ui/common/popup_item.dart";
import "package:photos/ui/common/web_page.dart";
import 'package:photos/ui/components/action_sheet_widget.dart';
import 'package:photos/ui/components/buttons/button_widget.dart';
import 'package:photos/ui/components/models/button_type.dart';
@ -844,7 +845,24 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
Future<void> _showAddPhotoDialog(BuildContext bContext) async {
final collection = widget.collection;
try {
await showAddPhotosSheet(bContext, collection!);
if (galleryType == GalleryType.sharedPublicCollection &&
collection!.isEnableCollect()) {
final authToken = await CollectionsService.instance
.getPublicAlbumToken(collection.id);
final albumKey =
await CollectionsService.instance.getPublicAlbumKey(authToken!);
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => WebPage(
widget.title ?? "",
"https://albums.ente.sh/?t=$authToken#$albumKey",
),
),
);
} else {
await showAddPhotosSheet(bContext, collection!);
}
} catch (e, s) {
_logger.severe(e, s);
await showGenericErrorDialog(context: bContext, error: e);