Skip to content

Commit 7240465

Browse files
committed
Heic to jpg with auto upload
1 parent 8ecc0bd commit 7240465

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

lib/network/api_interceptor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ApiInterceptor extends Interceptor {
1818
debugPrint("[${options.method}] ${options.queryParameters['method']}");
1919
SharedPreferences prefs = await SharedPreferences.getInstance();
2020
options.baseUrl = (prefs.getString(Preferences.serverUrlKey))!;
21-
if (Preferences.getEnableBasicAuth) {
21+
if (prefs.getBool(Preferences.enableBasicAuthKey) ?? false) {
2222
String? username = prefs.getString(Preferences.basicUsernameKey) ?? '';
2323
String? password = prefs.getString(Preferences.basicPasswordKey) ?? '';
2424
String basicAuth =

lib/services/auto_upload_manager.dart

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:dio/dio.dart';
77
import 'package:dio_cookie_manager/dio_cookie_manager.dart';
88
import 'package:flutter/foundation.dart';
99
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
10+
import 'package:heic_to_jpg/heic_to_jpg.dart';
1011
import 'package:image_picker/image_picker.dart';
1112
import 'package:piwigo_ng/models/album_model.dart';
1213
import 'package:piwigo_ng/models/status_model.dart';
@@ -71,22 +72,44 @@ class AutoUploadManager {
7172

7273
Future<bool> autoUpload() async {
7374
SharedPreferences prefs = await SharedPreferences.getInstance();
75+
76+
// Check upload on WiFi only setting
7477
if (prefs.getBool(Preferences.wifiUploadKey) ?? false) {
75-
print('Check wifi only');
78+
debugPrint('Check wifi only');
7679
var connectivity = await Connectivity().checkConnectivity();
7780
if (connectivity != ConnectivityResult.wifi) {
78-
print('No wifi');
81+
debugPrint('No wifi');
7982
return false;
8083
}
81-
print('Has wifi');
84+
debugPrint('Has wifi');
8285
}
86+
8387
final Directory? appDocDir = await getUploadDirectory();
8488
if (appDocDir == null) return false;
85-
List<FileSystemEntity> dirFiles = appDocDir.listSync();
89+
90+
// Get source folder content
91+
List<FileSystemEntity> dirFiles = appDocDir.listSync(recursive: true);
92+
93+
// Remove folders and links
8694
List<File> files = dirFiles
8795
.where((file) => file is File)
8896
.map<File>((e) => e as File)
8997
.toList();
98+
99+
// Convert .heic files to .jpg
100+
for (File file in files) {
101+
if (file.path.endsWith('.heic')) {
102+
debugPrint("${file.path} is Heic !");
103+
String? jpgPath = await HeicToJpg.convert(
104+
file.path,
105+
);
106+
debugPrint("From ${file.path}...\nto $jpgPath");
107+
if (jpgPath != null) {
108+
files.remove(file);
109+
files.add(File(jpgPath));
110+
}
111+
}
112+
}
90113
debugPrint("List files: ${files.toString()}");
91114
await autoUploadPhotos(files);
92115
return true;
@@ -192,10 +215,8 @@ class AutoUploadManager {
192215
// If no changes, end task iteration
193216
if (result.isEmpty) return;
194217

195-
// Send notifications
196218
await showAutoUploadNotification(nbError, result.length);
197219

198-
// Empty lunge
199220
await _emptyLunge(result, destination.id);
200221
}
201222

0 commit comments

Comments
 (0)