You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.8 KiB
112 lines
2.8 KiB
import 'package:get/get.dart';
|
|
import 'package:get_storage/get_storage.dart';
|
|
|
|
import '../../../core/utils/logger.dart';
|
|
import '../../../core/utils/upload_oss.dart';
|
|
import '../db/sqflite_api.dart';
|
|
import 'meeting_task_service.dart';
|
|
|
|
class MeetingUploadService extends GetxService {
|
|
final _taskService = Get.find<MeetingTaskService>();
|
|
|
|
final GetStorage _storage = GetStorage();
|
|
|
|
RxInt meetingId = 0.obs;
|
|
RxDouble uploadProgress = 0.0.obs;
|
|
RxList uploadList = [].obs;
|
|
|
|
bool _isUpload = false;
|
|
int _handled = 0;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
_getUploadList();
|
|
}
|
|
|
|
void _getUploadList() {
|
|
uploadList.value = _storage.read("meeting_upload_list") ?? [];
|
|
executeUpload();
|
|
}
|
|
|
|
void addUpload(
|
|
int id,
|
|
String filePath,
|
|
String rootDir, {
|
|
bool isUpload = true,
|
|
}) async {
|
|
uploadList.add({
|
|
'id': id,
|
|
'filepath': filePath,
|
|
'rootdir': rootDir,
|
|
'audiourl': '',
|
|
'isTask': false,
|
|
'language': '',
|
|
'prompt': '',
|
|
'outline': '',
|
|
});
|
|
_storage.write("meeting_upload_list", uploadList);
|
|
if (isUpload) {
|
|
executeUpload();
|
|
}
|
|
}
|
|
|
|
void executeUpload() async {
|
|
if (_isUpload) return;
|
|
_isUpload = true;
|
|
_handled = 0;
|
|
while (_handled < uploadList.length) {
|
|
Map element = uploadList[_handled];
|
|
_handled++;
|
|
if (element['audiourl'].isEmpty) {
|
|
meetingId.value = element['id'];
|
|
try {
|
|
final audiourl = await UploadOss.upload(
|
|
filepath: element['filepath'],
|
|
rootDir: element['rootdir'],
|
|
onSendProgress: (int count, int total) {
|
|
uploadProgress.value = count / total;
|
|
},
|
|
);
|
|
await SqfliteApi.editMeetingTitle(
|
|
element['id'],
|
|
{'audiourl': audiourl},
|
|
);
|
|
if (element['isTask']) {
|
|
await _taskService.addTaskList(
|
|
element['id'],
|
|
audiourl,
|
|
'',
|
|
element['language'],
|
|
element['prompt'],
|
|
element['outline'],
|
|
);
|
|
}
|
|
element['audiourl'] = audiourl;
|
|
uploadProgress.value = 0.0;
|
|
_storage.write("meeting_upload_list", uploadList);
|
|
} catch (e) {
|
|
Logger.error('Upload failed: $e');
|
|
}
|
|
}
|
|
}
|
|
meetingId.value = 0;
|
|
_isUpload = false;
|
|
}
|
|
|
|
void removeUpload(int id, {bool isDeleteTask = false}) {
|
|
Map uploadData = uploadList.firstWhere(
|
|
(element) => element['id'] == id,
|
|
orElse: () => {},
|
|
);
|
|
if (uploadData.isNotEmpty) {
|
|
if (isDeleteTask || uploadData['audiourl'].isNotEmpty) {
|
|
uploadList.remove(uploadData);
|
|
_storage.write("meeting_upload_list", uploadList);
|
|
if (uploadList.isEmpty) {
|
|
_handled = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|