2023-07-11 23:39:36 +08:00
|
|
|
import 'dart:io';
|
2023-08-15 10:53:30 +08:00
|
|
|
import 'dart:math';
|
2023-07-11 23:39:36 +08:00
|
|
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
2024-04-09 17:23:28 +08:00
|
|
|
import '/models/init_get_it.dart';
|
|
|
|
import '/models/user_model.dart';
|
2023-07-17 01:00:16 +08:00
|
|
|
|
2023-09-09 16:48:47 +08:00
|
|
|
Future<String> getAvatarPath(String type,String avatarName) async {
|
|
|
|
String avatarDir = await getAvatarDir(type);
|
2023-07-27 18:17:52 +08:00
|
|
|
return '$avatarDir/$avatarName';
|
|
|
|
}
|
|
|
|
|
2023-09-09 16:48:47 +08:00
|
|
|
Future<String> getAvatarDir(String type) async {
|
2023-07-11 23:39:36 +08:00
|
|
|
Directory appDirectory = await getApplicationDocumentsDirectory();
|
2023-09-09 16:48:47 +08:00
|
|
|
switch (type) {
|
|
|
|
case 'user':
|
|
|
|
return '${appDirectory.path}/${getIt.get<UserAccount>().id}/images/avatars/user';
|
|
|
|
case 'groupChat':
|
|
|
|
return '${appDirectory.path}/${getIt.get<UserAccount>().id}/images/avatars/group_chat';
|
|
|
|
case _:
|
|
|
|
return '${appDirectory.path}/${getIt.get<UserAccount>().id}/images/avatars/default';
|
|
|
|
}
|
2023-07-17 01:00:16 +08:00
|
|
|
}
|
|
|
|
|
2023-08-15 10:53:30 +08:00
|
|
|
Future<String> getBoxDir() async {
|
2023-07-17 01:00:16 +08:00
|
|
|
Directory appDirectory = await getApplicationDocumentsDirectory();
|
|
|
|
return '${appDirectory.path}/${getIt.get<UserAccount>().id}/ChatBox';
|
2023-07-11 23:39:36 +08:00
|
|
|
}
|
2023-08-15 10:53:30 +08:00
|
|
|
|
|
|
|
Future<String> getChatImageDir() async {
|
|
|
|
Directory appDirectory = await getApplicationDocumentsDirectory();
|
|
|
|
return '${appDirectory.path}/${getIt.get<UserAccount>().id}/images';
|
|
|
|
}
|
|
|
|
|
|
|
|
String getRandomFilename() {
|
|
|
|
final random = Random();
|
|
|
|
const availableChars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz';
|
|
|
|
String randomString = List.generate(
|
|
|
|
11, (index) => availableChars[random.nextInt(availableChars.length)])
|
|
|
|
.join();
|
|
|
|
|
|
|
|
return '$randomString.png';
|
|
|
|
}
|