remove old file get api use

This commit is contained in:
yaso 2026-07-10 11:09:56 +02:00
parent 8912e77b03
commit d7e4ac134d
19 changed files with 80 additions and 109 deletions

View file

@ -11,7 +11,6 @@ import 'package:mzansi_innovation_hub/mih_packages/mzansi_profile/business_profi
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_directory_services.dart';
import 'package:provider/provider.dart';
import 'package:redacted/redacted.dart';
@ -531,12 +530,6 @@ class _MihBusinessCardState extends State<MihBusinessCard> {
businessSearchResults = await MihBusinessDetailsServices()
.searchBusinesses(directoryProvider.searchTerm,
directoryProvider.businessTypeFilter, context);
Map<String, Future<String>> busImagesUrl = {};
Future<String> businessLogoUrl;
for (var bus in businessSearchResults) {
businessLogoUrl = MihFileApi.getMinioFileUrl(bus.logo_path);
busImagesUrl[bus.business_id] = businessLogoUrl;
}
directoryProvider.setSearchedBusinesses(
searchedBusinesses: businessSearchResults,
);

View file

@ -57,8 +57,6 @@ class _MihLinuxInstallInstructionsState
MihSnackBar(
child: Text('Command copied to clipboard!'),
),
// const SnackBar(
// content: Text('Command copied to clipboard!')),
);
},
tooltip: 'Copy command',

View file

@ -6,7 +6,6 @@ import 'package:mzansi_innovation_hub/mih_providers/mzansi_directory_provider.da
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_business_details_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_file_services.dart';
import 'package:mzansi_innovation_hub/mih_services/mih_mzansi_directory_services.dart';
import 'package:provider/provider.dart';
@ -34,15 +33,11 @@ class _MihAddBookmarkAlertState extends State<MihAddBookmarkAlert> {
directoryProvider,
);
List<Business> favBus = [];
Map<String, Future<String>> favBusImages = {};
Future<String> businessLogoUrl;
for (var bus in directoryProvider.bookmarkedBusinesses) {
await MihBusinessDetailsServices()
.getBusinessDetailsByBusinessId(bus.business_id)
.then((business) async {
favBus.add(business!);
businessLogoUrl = MihFileApi.getMinioFileUrl(business.logo_path);
favBusImages[business.business_id] = businessLogoUrl;
});
}
directoryProvider.setFavouriteBusinesses(

View file

@ -39,15 +39,11 @@ class _MihDeleteBookmarkAlertState extends State<MihDeleteBookmarkAlert> {
directoryProvider,
);
List<Business> favBus = [];
Map<String, Future<String>> favBusImages = {};
Future<String> businessLogoUrl;
for (var bus in directoryProvider.bookmarkedBusinesses) {
await MihBusinessDetailsServices()
.getBusinessDetailsByBusinessId(bus.business_id)
.then((business) async {
favBus.add(business!);
businessLogoUrl = MihFileApi.getMinioFileUrl(business.logo_path);
favBusImages[business.business_id] = businessLogoUrl;
});
}
directoryProvider.setFavouriteBusinesses(

View file

@ -85,7 +85,7 @@ class _MihBusinessDetailsSetUpState extends State<MihBusinessDetailsSetUp> {
bool successUpload =
await uploadFile(mzansiProfileProvider, newSelectedLogoPic);
if (successUpload) {
String logoUrl = await MihFileApi.getMinioFileUrl(
String logoUrl = MihFileApi.getMinioFileUrlV2(
mzansiProfileProvider.business!.logo_path);
mzansiProfileProvider.setBusinessProfilePicUrl(logoUrl);
}
@ -110,7 +110,7 @@ class _MihBusinessDetailsSetUpState extends State<MihBusinessDetailsSetUp> {
bool successUpload =
await uploadFile(mzansiProfileProvider, newSelectedSignaturePic);
if (successUpload) {
String sigUrl = await MihFileApi.getMinioFileUrl(
String sigUrl = MihFileApi.getMinioFileUrlV2(
mzansiProfileProvider.businessUser!.sig_path);
mzansiProfileProvider.setBusinessUserSignatureUrl(sigUrl);
String message =

View file

@ -24,7 +24,6 @@ class MihBusinessDetailsView extends StatefulWidget {
}
class _MihBusinessDetailsViewState extends State<MihBusinessDetailsView> {
late Future<String> futureImageUrl;
PlatformFile? file;
@override
@ -35,10 +34,6 @@ class _MihBusinessDetailsViewState extends State<MihBusinessDetailsView> {
@override
void initState() {
super.initState();
MzansiDirectoryProvider directoryProvider =
context.read<MzansiDirectoryProvider>();
futureImageUrl = MihFileApi.getMinioFileUrl(
directoryProvider.selectedBusiness!.logo_path);
}
@override

View file

@ -31,7 +31,6 @@ class MihBusinessQrCode extends StatefulWidget {
}
class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
late Future<String> futureImageUrl;
late Business business;
PlatformFile? file;
late String qrCodedata;
@ -313,7 +312,6 @@ class _MihBusinessQrCodeState extends State<MihBusinessQrCode> {
business = profileProvider.business!;
}
_checkUserSession();
futureImageUrl = MihFileApi.getMinioFileUrl(business.logo_path);
qrCodedata = "${AppEnviroment.baseAppUrl}/business-profile/view/";
}

View file

@ -26,7 +26,6 @@ class MihPersonalProfileView extends StatefulWidget {
}
class _MihPersonalProfileViewState extends State<MihPersonalProfileView> {
late Future<String> futureImageUrl;
late Future<List<ProfileLink>> futureLinks;
PlatformFile? file;
@ -40,8 +39,6 @@ class _MihPersonalProfileViewState extends State<MihPersonalProfileView> {
super.initState();
MzansiDirectoryProvider directoryProvider =
context.read<MzansiDirectoryProvider>();
futureImageUrl = MihFileApi.getMinioFileUrl(
directoryProvider.selectedUser!.pro_pic_path);
futureLinks = MihProfileLinksServices.getUserProfileLinksMD(
directoryProvider, directoryProvider.selectedUser!.app_id);
}

View file

@ -33,7 +33,6 @@ class MihPersonalQrCode extends StatefulWidget {
class _MihPersonalQrCodeState extends State<MihPersonalQrCode> {
late AppUser user;
late Future<String> futureImageUrl;
PlatformFile? file;
int qrSize = 500;
ScreenshotController screenshotController = ScreenshotController();
@ -310,7 +309,6 @@ class _MihPersonalQrCodeState extends State<MihPersonalQrCode> {
user = profileProvider.user!;
}
_checkUserSession();
futureImageUrl = MihFileApi.getMinioFileUrl(user.pro_pic_path);
}
@override

View file

@ -444,7 +444,7 @@ class _BuildPatientsListState extends State<BuildMyPatientListList> {
patientManagerProvider.myPaitentList![index].app_id, context)
.then((user) async {
user;
String url = await MihFileApi.getMinioFileUrl(user!.pro_pic_path);
String url = MihFileApi.getMinioFileUrlV2(user!.pro_pic_path);
patientManagerProvider.setSelectedPatientProfilePicUrl(url);
});
patientProfileChoicePopUp(

View file

@ -38,16 +38,16 @@ class _BuildClaimStatementFileListState
int progress = 0;
late StreamSubscription progressStream;
Future<String> getFileUrlApiCall(String filePath) async {
String teporaryFileUrl = "";
await MihFileApi.getMinioFileUrl(
filePath,
).then((value) {
teporaryFileUrl = value;
});
return teporaryFileUrl;
}
// Future<String> getFileUrlApiCall(String filePath) async {
// String teporaryFileUrl = "";
// await MihFileApi.getMinioFileUrl(
// filePath,
// ).then((value) {
// teporaryFileUrl = value;
// });
// return teporaryFileUrl;
// }
//
String getFileName(String path) {
//print(pdfLink.split(".")[1]);
return path.split("/").last;
@ -282,14 +282,13 @@ class _BuildClaimStatementFileListState
onTap: () async {
MihFileViewerProvider fileViewerProvider =
context.read<MihFileViewerProvider>();
await getFileUrlApiCall(patientManagerProvider
.patientClaimsDocuments![index].file_path)
.then((urlHere) {
//print(url);
fileViewerProvider.setFilePath(patientManagerProvider
.patientClaimsDocuments![index].file_path);
fileViewerProvider.setFileLink(urlHere);
});
String fileUrl = MihFileApi.getMinioFileUrlV2(
patientManagerProvider
.patientClaimsDocuments![index].file_path);
//print(url);
fileViewerProvider.setFilePath(patientManagerProvider
.patientClaimsDocuments![index].file_path);
fileViewerProvider.setFileLink(fileUrl);
viewFilePopUp(
patientManagerProvider,

View file

@ -38,16 +38,16 @@ class _BuildFilesListState extends State<BuildFilesList> {
int progress = 0;
late StreamSubscription progressStream;
Future<String> getFileUrlApiCall(String filePath) async {
String teporaryFileUrl = "";
await MihFileApi.getMinioFileUrl(
filePath,
).then((value) {
teporaryFileUrl = value;
});
return teporaryFileUrl;
}
// Future<String> getFileUrlApiCall(String filePath) async {
// String teporaryFileUrl = "";
// await MihFileApi.getMinioFileUrl(
// filePath,
// ).then((value) {
// teporaryFileUrl = value;
// });
// return teporaryFileUrl;
// }
//
String getFileName(String path) {
//print(pdfLink.split(".")[1]);
return path.split("/").last;
@ -309,14 +309,13 @@ class _BuildFilesListState extends State<BuildFilesList> {
onTap: () async {
MihFileViewerProvider fileViewerProvider =
context.read<MihFileViewerProvider>();
await getFileUrlApiCall(patientManagerProvider
.patientDocuments![index].file_path)
.then((urlHere) {
//print(url);
fileViewerProvider.setFilePath(patientManagerProvider
.patientDocuments![index].file_path);
fileViewerProvider.setFileLink(urlHere);
});
String fileUrl = MihFileApi.getMinioFileUrlV2(
patientManagerProvider
.patientDocuments![index].file_path);
//print(url);
fileViewerProvider.setFilePath(patientManagerProvider
.patientDocuments![index].file_path);
fileViewerProvider.setFileLink(fileUrl);
viewFilePopUp(
patientManagerProvider,
patientManagerProvider.patientDocuments![index].file_name,

View file

@ -1,5 +1,6 @@
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_providers/mzansi_profile_provider.dart';
@ -61,12 +62,9 @@ class _PatientDocumentsState extends State<PatientDocuments> {
int statusCode =
await MihPatientServices().addPatientFile(file, patientManagerProvider);
if (statusCode == 201) {
setState(() {
selectedFileController.clear();
});
var fname = file!.name.replaceAll(RegExp(r' '), '-');
// end loading circle
Navigator.of(context).pop();
context.pop();
String message =
"The file $fname has been successfully generated and added to ${patientManagerProvider.selectedPatient!.first_name} ${patientManagerProvider.selectedPatient!.last_name}'s record. You can now access and download it for their use.";
successPopUp("Successfully Uplouded File", message);
@ -77,6 +75,8 @@ class _PatientDocumentsState extends State<PatientDocuments> {
Future<void> uploadSelectedFile(
PatientManagerProvider patientManagerProvider, PlatformFile? file) async {
KenLogger.success(
"Patient app id: ${patientManagerProvider.selectedPatient!.app_id}");
var response = await MihFileApi.uploadFile(
patientManagerProvider.selectedPatient!.app_id,
env,
@ -84,6 +84,7 @@ class _PatientDocumentsState extends State<PatientDocuments> {
file,
context,
);
KenLogger.success("Response code: $response");
if (response == 200) {
await addPatientFileLocationToDB(patientManagerProvider, file);
} else {
@ -462,6 +463,9 @@ class _PatientDocumentsState extends State<PatientDocuments> {
onPressed: () {
context.pop();
context.pop();
setState(() {
selectedFileController.clear();
});
},
buttonColor: MihColors.primary(),
elevation: 10,

View file

@ -65,7 +65,7 @@ class _PatientProfileState extends State<PatientProfile> {
AppUser? patientUserDetails = await MihUserServices().getMIHUserDetails(
patientManagerProvider.selectedPatient!.app_id, context);
String patientProPicUrl =
await MihFileApi.getMinioFileUrl(patientUserDetails!.pro_pic_path);
MihFileApi.getMinioFileUrlV2(patientUserDetails!.pro_pic_path);
patientManagerProvider.setSelectedPatientProfilePicUrl(patientProPicUrl);
}
patientManagerProvider.setPersonalMode(mzansiProfileProvider.personalHome);

View file

@ -293,7 +293,7 @@ class MihBusinessDetailsServices {
businessMissionVision,
),
);
String newProPicUrl = await MihFileApi.getMinioFileUrl(filePath);
String newProPicUrl = MihFileApi.getMinioFileUrlV2(filePath);
provider.setBusinessProfilePicUrl(newProPicUrl);
return 200;
} else {

View file

@ -1,9 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:go_router/go_router.dart';
import 'package:ken_logger/ken_logger.dart';
import 'package:mih_package_toolkit/mih_package_toolkit.dart';
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
import 'package:flutter/material.dart';
@ -14,30 +11,30 @@ import 'package:supertokens_flutter/supertokens.dart';
class MihFileApi {
final baseAPI = AppEnviroment.baseApiUrl;
static Future<String> getMinioFileUrl(
String filePath,
) async {
String fileUrl = "";
try {
var url =
"${AppEnviroment.baseApiUrl}/minio/pull/file/${AppEnviroment.getEnv()}/$filePath";
var response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
var decodedData = jsonDecode(response.body);
fileUrl = decodedData['minioURL'];
} else {}
} catch (e) {
KenLogger.error("Error getting url");
} finally {}
if (AppEnviroment.getEnv() == "Dev" && kIsWeb) {
fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
} else if (AppEnviroment.getEnv() == "Dev" && Platform.isIOS) {
fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
} else if (AppEnviroment.getEnv() == "Dev" && Platform.isLinux) {
fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
}
return fileUrl;
}
// static Future<String> getMinioFileUrl(
// String filePath,
// ) async {network
// String fileUrl = "";
// try {
// var url =
// "${AppEnviroment.baseApiUrl}/minio/pull/file/${AppEnviroment.getEnv()}/$filePath";
// var response = await http.get(Uri.parse(url));
// if (response.statusCode == 200) {
// var decodedData = jsonDecode(response.body);
// fileUrl = decodedData['minioURL'];
// } else {}
// } catch (e) {
// KenLogger.error("Error getting url");
// } finally {}
// if (AppEnviroment.getEnv() == "Dev" && kIsWeb) {
// fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
// } else if (AppEnviroment.getEnv() == "Dev" && Platform.isIOS) {
// fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
// } else if (AppEnviroment.getEnv() == "Dev" && Platform.isLinux) {
// fileUrl = fileUrl.replaceAll("10.0.2.2", "127.0.0.1");
// }
// return fileUrl;
// }
static String getMinioFileUrlV2(
String filePath,
@ -63,8 +60,13 @@ class MihFileApi {
request.fields['app_id'] = app_id;
request.fields['env'] = env;
request.fields['folder'] = folderName;
request.files.add(await http2.MultipartFile.fromBytes('file', file!.bytes!,
filename: file.name.replaceAll(RegExp(r' '), '-')));
request.files.add(
http2.MultipartFile.fromBytes(
'file',
await file!.readAsBytes(),
filename: file.name.replaceAll(RegExp(r' '), '-'),
),
);
var response = await request.send();
context.pop(); // Pop loading dialog
return response.statusCode;

View file

@ -1,5 +1,4 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
@ -22,9 +21,7 @@ class MIHLocationAPI {
MihAlertServices().locationPermissionAlert(context);
return null;
}
print("Before checkPermission"); // Debug
LocationPermission permission = await Geolocator.checkPermission();
print("After checkPermission: $permission"); // Debug
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {

View file

@ -140,7 +140,7 @@ class MihMyBusinessUserServices {
bUserAccess,
),
);
String newProPicUrl = await MihFileApi.getMinioFileUrl(filePath);
String newProPicUrl = MihFileApi.getMinioFileUrlV2(filePath);
provider.setBusinessUserSignatureUrl(newProPicUrl);
return 200;
} else {

View file

@ -221,7 +221,7 @@ class MihUserServices {
purpose,
),
);
String newProPicUrl = await MihFileApi.getMinioFileUrl(filePath);
String newProPicUrl = MihFileApi.getMinioFileUrlV2(filePath);
context.read<MzansiProfileProvider>().setUserProfilePicUrl(newProPicUrl);
return response.statusCode;
} else {