Pārlūkot izejas kodu

[fix]未登录则不能分享

zk 1 gadu atpakaļ
vecāks
revīzija
070c524936

+ 28 - 10
lib/data/repositories/talk_repository.dart

@@ -1,3 +1,4 @@
+import 'dart:convert';
 import 'dart:io';
 
 import 'package:dio/dio.dart';
@@ -11,6 +12,7 @@ import 'package:flutter_foreground_task/flutter_foreground_task.dart';
 import 'package:get/get.dart';
 import 'package:get/get_connect/http/src/request/request.dart';
 import 'package:path_provider/path_provider.dart';
+import '../../base/base_response.dart';
 import '../../dialog/talk_share_dialog.dart';
 import '../../utils/foreground_util.dart';
 import '../../utils/http_handler.dart';
@@ -54,18 +56,34 @@ class TalkRepository {
       String talkId, String fileName, ShareTalkType type) async {
     ResponseBody responseBody = await atmobStreamApi.talkExportFile(
         TalkExportRequest(talkId, type == ShareTalkType.summary ? 1 : 2));
+    List<String>? contentType = responseBody.headers['Content-Type'];
+
+    if (contentType != null) {
+      for (var value in contentType) {
+        if (value.contains('application/json')) {
+          BaseResponse<String> baseResponse = BaseResponse.fromJson(
+              jsonDecode(await responseBody.stream
+                  .map((bytes) => utf8.decoder.convert(bytes))
+                  .toList()
+                  .then((value) => value.join())),
+              (json) => json as String);
+          throw ServerErrorException(baseResponse.code, baseResponse.message);
+        } else {
+          final directory = await getTemporaryDirectory();
+          final filePath = '${directory.path}/export/$fileName';
+
+          final file = File(filePath);
+
+          if (!await file.exists()) {
+            await file.create(recursive: true);
+          }
 
-    final directory = await getTemporaryDirectory();
-    final filePath = '${directory.path}/export/$fileName';
-
-    final file = File(filePath);
-
-    if (!await file.exists()) {
-      await file.create(recursive: true);
+          await file.writeAsBytes(await responseBody.stream.toBytes());
+          return file;
+        }
+      }
     }
-
-    await file.writeAsBytes(await responseBody.stream.toBytes());
-    return file;
+    throw Exception('Invalid content type');
   }
 
   void setTalkList(List<TalkBean> list) {

+ 4 - 0
lib/module/talk/controller.dart

@@ -554,6 +554,10 @@ class TalkController extends BaseController {
   }
 
   void onShareClick() {
+    if (!accountRepository.isLogin.value) {
+      LoginPage.start(fromType: LoginFromType.talkDetail);
+      return;
+    }
     if (talkBean.value?.status.value != TalkStatus.analysisSuccess) {
       return;
     }