Browse Source

添加缓存RPC接口

Jimmy 2 years ago
parent
commit
e8d0cc7f90
2 changed files with 21 additions and 3 deletions
  1. 3 3
      lib/client_base.dart
  2. 18 0
      lib/services/platform.dart

+ 3 - 3
lib/client_base.dart

@@ -1,8 +1,6 @@
 import 'dart:convert';
 import 'package:dio/dio.dart' as dio;
-import 'package:fis_common/http/options.dart';
 import 'package:flutter/foundation.dart';
-
 import 'exception.dart';
 import 'http_pool.dart';
 import 'interceptor.dart';
@@ -56,7 +54,9 @@ class JsonRpcClientBase {
 
   Future<dynamic> _transmit(JsonRpcRequest request) async {
     final req = await jsonRpcInterceptHost.onRequestTransmit(request);
+
     String package = jsonEncode(req.toJson());
+
     var response = await _postRequest(package);
     if (response == null) throw JsonRpcException(message: "Response Empty");
 
@@ -68,9 +68,9 @@ class JsonRpcClientBase {
     try {
       final httpClient = jrpcHttpPool.getClient(this.host,
           timeout: this.timeout, headers: this.headers);
+
       var response =
           await httpClient.post('/${this.serviceName}', data: package);
-      // if (response.statusCode != HttpStatus.ok) {
       if (response.statusCode != 200) {
         throw JsonRpcException(
             message: "Http error.Status coder: ${response.statusCode}.");

+ 18 - 0
lib/services/platform.dart

@@ -84,4 +84,22 @@ class PlatformService extends JsonRpcClientBase {
     var result = GetVidFrameResult.fromJson(rpcRst as Map<String, dynamic>);
     return result;
   }
+
+  /// 导出文件
+  Future<bool> setBytesToExport(String data, String fileName) async {
+    var rpcRst = await call("SetBytesToExport", [data, fileName]);
+    return rpcRst;
+  }
+
+  ///缓存文件
+  Future<bool> setBinaryFileCache(String data, String fileName) async {
+    var rpcRst = await call("SetBinaryFileCache", [data, fileName]);
+    return rpcRst;
+  }
+
+  ///读取缓存文件
+  Future<String?> getBinaryFileCache(String fileName) async {
+    var rpcRst = await call("GetBinaryFileCache", [fileName]);
+    return rpcRst;
+  }
 }