@@ -45,48 +45,55 @@ Future<List<Map<String, dynamic>>> uploadPhotos(
4545}) async {
4646 List <Map <String , dynamic >> result = [];
4747 List <int > uploadCompletedList = [];
48+ List <UploadItem > items = [];
4849 FlutterSecureStorage storage = const FlutterSecureStorage ();
4950 String ? url = await storage.read (key: 'SERVER_URL' );
5051 if (url == null ) return [];
5152 String ? username = await storage.read (key: 'SERVER_USERNAME' );
5253 String ? password = await storage.read (key: 'SERVER_PASSWORD' );
5354 UploadNotifier uploadNotifier = App .appKey.currentContext! .read <UploadNotifier >();
5455
56+ /// Creates Upload Item list for the upload notifier
5557 for (var photo in photos) {
5658 File ? compressedFile;
57- UploadItem ? item;
59+ if (Preferences .getRemoveMetadata) {
60+ compressedFile = await compressFile (photo);
61+ } else {
62+ compressedFile = File (photo.path);
63+ }
64+ items.add (UploadItem (
65+ file: compressedFile,
66+ albumId: albumId,
67+ ));
68+ }
69+
70+ uploadNotifier.addItems (items);
71+
72+ /// Upload loop
73+ for (var item in items) {
5874 try {
59- if (Preferences .getRemoveMetadata) {
60- compressedFile = await compressFile (photo);
61- } else {
62- compressedFile = File (photo.path);
63- }
64- item = UploadItem (
65- file: compressedFile,
66- albumId: albumId,
67- );
68- uploadNotifier.addItem (item);
75+ /// Make Request
6976 Response ? response = await uploadChunk (
70- photo: compressedFile ,
77+ photo: item.file ,
7178 category: albumId,
7279 url: url,
7380 username: username,
7481 password: password,
7582 info: info,
7683 onProgress: (progress) {
7784 debugPrint ("$progress " );
78- item? .progress.sink.add (progress);
85+ item.progress.sink.add (progress);
7986 },
8087 );
8188 if (response != null ) {
8289 var data = json.decode (response.data);
8390 if (data['stat' ] != 'fail' ) {
8491 result.add ({
8592 'id' : data['result' ]['id' ],
86- 'name' : photo.name,
87- 'filename' : photo.path.split ('/' ).last,
8893 'url' : data['result' ]['element_url' ],
8994 });
95+
96+ /// Notify provider upload completed
9097 uploadNotifier.itemUploadCompleted (item);
9198 if (Preferences .getDeleteAfterUpload) {
9299 // todo: delete real file path, not the cached one.
@@ -98,17 +105,16 @@ Future<List<Map<String, dynamic>>> uploadPhotos(
98105 uploadNotifier.itemUploadCompleted (item, error: true );
99106 }
100107 } catch (e) {
101- if (item != null ) {
102- uploadNotifier.itemUploadCompleted (item, error: true );
103- }
104108 debugPrint ("$e " );
105109 }
106110 }
107- if (result.isEmpty) {
108- _showUploadNotification (success: false );
109- return [];
111+ if (Preferences .getUploadNotification) {
112+ if (result.isEmpty) {
113+ _showUploadNotification (success: false );
114+ }
115+ _showUploadNotification (success: true );
110116 }
111- _showUploadNotification (success : true ) ;
117+ if (result.isEmpty) return [] ;
112118 uploadCompletedList = result.map <int >((e) => e['id' ]).toList ();
113119 try {
114120 await uploadCompleted (uploadCompletedList, albumId);
@@ -131,7 +137,10 @@ Future<Response?> uploadChunk({
131137 String ? username,
132138 String ? password,
133139}) async {
134- Map <String , String > queries = {"format" : "json" , "method" : "pwg.images.uploadAsync" };
140+ Map <String , String > queries = {
141+ 'format' : 'json' ,
142+ 'method' : 'pwg.images.uploadAsync' ,
143+ };
135144 Map <String , dynamic > fields = {
136145 'username' : username,
137146 'password' : password,
@@ -151,7 +160,7 @@ Future<Response?> uploadChunk({
151160 ));
152161
153162 return await chunkedUploader.upload (
154- path: " /ws.php" ,
163+ path: ' /ws.php' ,
155164 filePath: photo.absolute.path,
156165 maxChunkSize: 100000 ,
157166 params: queries,
0 commit comments