Skip to content

Commit

Permalink
fix: 修复下载订阅时文件名解析异常
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleafgo committed May 13, 2023
1 parent a59518c commit 58eba04
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
40 changes: 27 additions & 13 deletions lib/app/source/request.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:clash_for_flutter/app/bean/config_bean.dart';
import 'package:clash_for_flutter/app/bean/connection_bean.dart';
Expand Down Expand Up @@ -48,19 +46,35 @@ class Request {
var file = "${time.millisecondsSinceEpoch}.yaml";
var savePath = "$profilesDir/$file";
return downFile(urlPath: profile.url, savePath: savePath).then((resp) {
String? filename;
// 解析文件名
if (profile.name.isEmpty) {
resp.headers["content-disposition"]?.forEach((v) {
var filename = HeaderValue.parse(v).parameters["filename"];
if (filename != null) {
profile.name = filename;
} else {
profile.name = file;
}
});
var headerDis = resp.headers.value("content-disposition");
if (headerDis != null) {
var disposition = HeaderValue.parse(headerDis);
disposition.parameters.forEach((key, value) {
if (key.startsWith("filename")) {
if (key == "filename*") {
filename = Uri.decodeComponent((value ?? "").split("'").last);
} else {
filename = value;
}
}
});
}
// 赋值文件名
if (filename?.isNotEmpty ?? false) {
profile.name = filename!;
} else {
profile.name = file;
}
}
resp.headers["subscription-userinfo"]?.forEach((v) {
profile.userinfo = SubUserinfo.formHString(v);
});
// 解析流量信息
var headerInfo = resp.headers.value("subscription-userinfo");
if (headerInfo != null) {
profile.userinfo = SubUserinfo.formHString(headerInfo);
}
// 解析更新间隔
var value = resp.headers.value("profile-update-interval");
if (value != null && profile.interval == 0) {
profile.interval = int.parse(value);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.2.2
version: 1.2.3

environment:
sdk: '>=2.18.4 <3.0.0'
Expand Down

0 comments on commit 58eba04

Please sign in to comment.