提交 4ae8e1af authored 作者: 张国庆's avatar 张国庆

feat :oss 调整

上级 deaba6f0
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "apk_update",
"request": "launch",
"type": "dart"
},
{
"name": "apk_update (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "apk_update (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
},
{
"name": "example (profile mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "example (release mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
\ No newline at end of file
......@@ -61,7 +61,8 @@ class ApkUpdatePlugin : FlutterPlugin, MethodCallHandler, EventChannel.StreamHan
val bucketName = data?.get("bucketName")
val objectKey = data?.get("objectKey")
val localPath = data?.get("localPath")
if (ak == null || sk == null || token == null || endpoint == null || bucketName == null || objectKey == null || localPath == null) {
val localFileName = data?.get("localFileName")
if (ak == null || sk == null || token == null || endpoint == null || bucketName == null || objectKey == null || localPath == null || localFileName == null) {
result.error("error", "data is null", null)
return
}
......@@ -78,6 +79,7 @@ class ApkUpdatePlugin : FlutterPlugin, MethodCallHandler, EventChannel.StreamHan
bucketName,
objectKey,
localPath,
localFileName,
this
)
......
......@@ -27,6 +27,7 @@ object DownloadAppUtil {
bucketName: String,
objectKey: String,
localPath: String,
localFileName: String,
progressCallback: ProgressCallback
) {
......@@ -35,7 +36,7 @@ object DownloadAppUtil {
// 填写下载到本地文件所在的完整路径。
val localFile = "$localPath/$objectKey"
val localFile = "$localPath/$localFileName"
Log.d(TAG, "aliDownload: localFile = $localFile")
val request = ResumableDownloadRequest(bucketName, objectKey, localFile)
......
......@@ -64,15 +64,11 @@ class _MyAppState extends State<MyApp> {
TextButton(
onPressed: () {
var map = {
'token': "20502a804a784bc1a21681e26aa14cb8",
'objectKey': 'msl.apk',
'bucketName': 'mslapp-download',
'endpoint': 'oss-cn-beijing.aliyuncs.com',
"baseUrl": "https://gateway.testclx.cn"
'token': "a0b6655571e0412787c9e0dd113ded74",
};
ApkUpdate().updateAppByPM(
baseUrl: "https://gateway.91msl.com",
productCode: "msl-report-app",
productCode: "carrier-driver-app",
versionNumber: 1,
onceDay: false,
paramsOSS: map,
......
......@@ -130,7 +130,7 @@ class ApkUpdate {
return;
}
ApkUpdatePlatform.instance.downloadApk(
ak, sk, token, objectKey, endpoint, bucketName, localPath);
ak, sk, token, objectKey, endpoint, bucketName, localPath,"fileName");
}).catchError((e) {
debugPrint('获取OSS授权失败');
downloadApkError?.call();
......@@ -177,11 +177,14 @@ class ApkUpdate {
ApkUpdatePlatform.instance.installApk(path);
},
downloadApk: (String? path, String? apkPath) async {
var objectKey = apkPath ?? "";
objectKey = getObjectKey(objectKey);
DioUpdateUtil.getDio()
.get("${paramsOSS?['baseUrl']}$generateByExt",
.get("$baseUrl$generateByExt",
queryParameters: {
"extension": "apk",
"bucketName": paramsOSS?["bucketName"]
"bucketName": paramsOSS?["bucketName"] ?? bucketName
},
options: Options(headers: {
"token": paramsOSS?['token'],
......@@ -198,19 +201,22 @@ class ApkUpdate {
var ak = map?['onceAccessKeyId'];
var sk = map?["onceAccessKeySecret"];
var token = map?["onceSecurityToken"];
var objectKey = apkPath ?? "";
// apkPath https://mslapp-download.oss-cn-beijing.aliyuncs.com/msl-chengyun.apk 截取后:msl-chengyun.apk
objectKey = objectKey.substring(objectKey.lastIndexOf("/") + 1);
var endpoint = paramsOSS?["endpoint"];
var bucketName = paramsOSS?["bucketName"];
var localPath = path;
if (localPath == null) {
ToastUtil.showToast("下载路径错误,请稍后重新");
return;
}
var localPathFileName = getFileName(objectKey);
ApkUpdatePlatform.instance.downloadApk(
ak, sk, token, objectKey, endpoint, bucketName, localPath);
ak,
sk,
token,
objectKey,
paramsOSS?["endpoint"] ?? endpoint,
paramsOSS?["bucketName"] ?? bucketName,
localPath,
localPathFileName);
}).catchError((e) {
debugPrint('获取OSS授权失败');
ToastUtil.showToast("获取OSS授权失败,请稍后重新");
......
......@@ -24,7 +24,7 @@ class MethodChannelApkUpdate extends ApkUpdatePlatform {
@override
void downloadApk(String ak, String sk, String token, String objectKey,
String endpoint, String bucketName, String localPath) {
String endpoint, String bucketName, String localPath,localFileName) {
methodChannel.invokeMethod<String>('downloadInstall', {
"ak": ak,
"sk": sk,
......@@ -32,7 +32,8 @@ class MethodChannelApkUpdate extends ApkUpdatePlatform {
"objectKey": objectKey,
"endpoint": endpoint,
"bucketName": bucketName,
"localPath": localPath
"localPath": localPath,
"localFileName":localFileName,
});
}
......
......@@ -33,7 +33,7 @@ abstract class ApkUpdatePlatform extends PlatformInterface {
//支持断点下载并安装
void downloadApk(String ak, String sk, String token, String objectKey,
String endpoint, String bucketName, String localPath) {
String endpoint, String bucketName, String localPath,String localFileName) {
throw UnimplementedError('downloadApk() has not been implemented.');
}
......
......@@ -7,6 +7,7 @@ import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:get/route_manager.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:path/path.dart' as p;
import 'dio_update_util.dart';
......@@ -22,6 +23,8 @@ const getDetailPM = "/pm-process/external/web/onlineConfig/getDetail";
const String generateByExt = "/msl-document/common/oss/generateByExt";
const currentDay = "current_day";
const dateFormat = "yyyy-MM-dd";
const endpoint = 'oss-cn-beijing.aliyuncs.com';
const bucketName = 'clx-prod';
/// 获取更新版本信息
/// url 请求地址
......@@ -270,6 +273,33 @@ Future<void> openBrowser(String stringUrl) async {
}
}
/// 处理apk下载url 获取 objectKey
String getObjectKey(String url) {
int startIndex = url.indexOf("aliyuncs.com/") + "aliyuncs.com/".length;
return url.substring(startIndex);
}
/// 获取下载url文件名
String getFileName(String url) {
return p.basename(url);
}
/// 获取objectKey中的文件夹字符 “msl/common/prod/video/2025-06-20/app-release11.apk” 中获取 “msl/common/prod/video/2025-06-20”
String getPathByObjectKey(String url) {
return p.dirname(url);
}
//创建下载目录
Future<String?> createDir() async {
setInitDir(initStorageDir: true);
await DirectoryUtil.getInstance();
DirectoryUtil.createStorageDirSync(category: 'Download');
String? path = DirectoryUtil.getStoragePath(category: 'Download');
return path;
}
enum Method {
get,
post,
......
......@@ -220,13 +220,18 @@ class _UpdateDialogState extends State<UpdateDialog> {
try {
// 2024-11-21 使用OSSSDK下载
if (widget.isOssDownload == 1) {
setInitDir(initStorageDir: true);
await DirectoryUtil.getInstance();
DirectoryUtil.createStorageDirSync(category: 'Download');
String? path = DirectoryUtil.getStoragePath(category: 'Download');
//创建本地下载目录
String? path = await createDir();
File apkFile = File("$path/${widget.versionPath}");
File apkFileTmp = File("$path/${widget.versionPath}.tmp");
if (widget.versionPath == null) {
widget.downloadApkError?.call();
_isDownload = false;
setState(() {});
return;
}
File apkFile = File("$path/${getFileName(widget.versionPath!)}");
File apkFileTmp = File("$path/${getFileName(widget.versionPath!)}.tmp");
// 判断localPath 下有没有下载完成的文件
if (apkFile.existsSync() && !apkFileTmp.existsSync()) {
ApkUpdatePlatform.instance.installApk(apkFile.path);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论