Skip to content

Commit

Permalink
新增:ftp图床现在支持自定义域名
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuingsmile committed Jun 20, 2023
1 parent 7b2b57c commit 569f748
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 42 deletions.
Binary file modified android/.gradle/7.4/checksums/checksums.lock
Binary file not shown.
Binary file modified android/.gradle/7.4/checksums/sha1-checksums.bin
Binary file not shown.
Binary file modified android/.gradle/7.4/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified android/.gradle/7.4/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified android/.gradle/7.4/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified android/.gradle/7.4/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified android/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified android/.gradle/file-system.probe
Binary file not shown.
13 changes: 4 additions & 9 deletions lib/api/aliyun_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,12 @@ class AliyunImageUploadUtils {
String displayUrl = '';

if (customUrl != 'None') {
if (!customUrl.endsWith('/')) {
returnUrl = '$customUrl/$urlpath';
displayUrl = '$customUrl/$urlpath';
} else {
customUrl = customUrl.substring(0, customUrl.length - 1);
returnUrl = '$customUrl/$urlpath';
displayUrl = '$customUrl/$urlpath';
}
customUrl = customUrl.replaceAll(RegExp(r'/$'), '');
returnUrl = '$customUrl/$urlpath';
displayUrl = returnUrl;
} else {
returnUrl = 'https://$host/$urlpath';
displayUrl = 'https://$host/$urlpath';
displayUrl = returnUrl;
}

if (options == 'None') {
Expand Down
48 changes: 38 additions & 10 deletions lib/api/ftp_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class FTPImageUploadUtils {
String ftpType = configMap["ftpType"];
String isAnonymous = configMap["isAnonymous"];
String uploadPath = configMap["uploadPath"];
String? ftpCustomUrl = configMap["ftpCustomUrl"];
String? ftpWebPath = configMap["ftpWebPath"];
if (ftpType == 'SFTP') {
try {
final socket = await SSHSocket.connect(ftpHost, int.parse(ftpPort.toString()));
Expand Down Expand Up @@ -48,10 +50,23 @@ class FTPImageUploadUtils {
await Future.delayed(const Duration(milliseconds: 100));
}
client.close();
String returnUrl = 'ftp://$ftpUser:$ftpPassword@$ftpHost:$ftpPort$urlPath';
returnUrl = returnUrl;
String returnUrl = '';
String displayUrl = '';
if (ftpCustomUrl != null && ftpCustomUrl != 'None') {
ftpCustomUrl = ftpCustomUrl.replaceAll(RegExp(r'/$'), '');
if (ftpWebPath != null && ftpWebPath != 'None') {
ftpWebPath = ftpWebPath.replaceAll(RegExp(r'^/*'), '').replaceAll(RegExp(r'/*$'), '');
returnUrl = '$ftpCustomUrl/$ftpWebPath/$name';
} else {
urlPath = urlPath.replaceAll(RegExp(r'^/*'), '');
returnUrl = '$ftpCustomUrl/$urlPath';
}
displayUrl = returnUrl;
} else {
returnUrl = 'ftp://$ftpUser:$ftpPassword@$ftpHost:$ftpPort$urlPath';
displayUrl = returnUrl;
}
String pictureKey = jsonEncode(configMap);
String displayUrl = returnUrl;
if (Global.isCopyLink == true) {
formatedURL = linkGenerateDict[Global.defaultLKformat]!(displayUrl, name);
} else {
Expand Down Expand Up @@ -133,16 +148,29 @@ class FTPImageUploadUtils {
);
if (res == true) {
String returnUrl = '';
if (isAnonymous == 'true') {
returnUrl = 'ftp://$ftpHost:$ftpPort$urlPath';
} else if (ftpPassword == 'None') {
returnUrl = 'ftp://$ftpUser@$ftpHost:$ftpPort$urlPath';
String displayUrl = '';
if (ftpCustomUrl != null && ftpCustomUrl != 'None') {
ftpCustomUrl = ftpCustomUrl.replaceAll(RegExp(r'/$'), '');
if (ftpWebPath != null && ftpWebPath != 'None') {
ftpWebPath = ftpWebPath.replaceAll(RegExp(r'^/*'), '').replaceAll(RegExp(r'/*$'), '');
returnUrl = '$ftpCustomUrl/$ftpWebPath/$name';
} else {
urlPath = urlPath.replaceAll(RegExp(r'^/*'), '');
returnUrl = '$ftpCustomUrl/$urlPath';
}
displayUrl = returnUrl;
} else {
returnUrl = 'ftp://$ftpUser:$ftpPassword@$ftpHost:$ftpPort$urlPath';
if (isAnonymous == 'true') {
returnUrl = 'ftp://$ftpHost:$ftpPort$urlPath';
} else if (ftpPassword == 'None') {
returnUrl = 'ftp://$ftpUser@$ftpHost:$ftpPort$urlPath';
} else {
returnUrl = 'ftp://$ftpUser:$ftpPassword@$ftpHost:$ftpPort$urlPath';
}
displayUrl = returnUrl;
}
returnUrl = returnUrl;

String pictureKey = jsonEncode(configMap);
String displayUrl = returnUrl;
if (Global.isCopyLink == true) {
formatedURL = linkGenerateDict[Global.defaultLKformat]!(displayUrl, name);
} else {
Expand Down
47 changes: 37 additions & 10 deletions lib/pages/upload_pages/upload_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,8 @@ class UploadManager {
String ftpType = configMap["ftpType"];
String isAnonymous = configMap["isAnonymous"].toString();
String uploadPath = configMap["uploadPath"];
String? ftpCustomUrl = configMap["ftpCustomUrl"];
String? ftpWebPath = configMap["ftpWebPath"];

if (ftpType == 'SFTP') {
final socket = await SSHSocket.connect(ftpHost, int.parse(ftpPort.toString()));
Expand Down Expand Up @@ -836,10 +838,23 @@ class UploadManager {
await Future.delayed(const Duration(milliseconds: 100));
}
client.close();
String returnUrl = 'ftp://$ftpUser:$ftpPassword@$ftpHost:$ftpPort$urlPath';
returnUrl = returnUrl;
String returnUrl = '';
String displayUrl = '';
if (ftpCustomUrl != null && ftpCustomUrl != 'None') {
ftpCustomUrl = ftpCustomUrl.replaceAll(RegExp(r'/$'), '');
if (ftpWebPath != null && ftpWebPath != 'None') {
ftpWebPath = ftpWebPath.replaceAll(RegExp(r'^/*'), '').replaceAll(RegExp(r'/*$'), '');
returnUrl = '$ftpCustomUrl/$ftpWebPath/$fileName';
} else {
urlPath = urlPath.replaceAll(RegExp(r'^/*'), '');
returnUrl = '$ftpCustomUrl/$urlPath';
}
displayUrl = returnUrl;
} else {
returnUrl = 'ftp://$ftpUser:$ftpPassword@$ftpHost:$ftpPort$urlPath';
displayUrl = returnUrl;
}
String pictureKey = jsonEncode(configMap);
String displayUrl = returnUrl;

eventBus.fire(AlbumRefreshEvent(albumKeepAlive: false));
Map<String, dynamic> maps = {};
Expand Down Expand Up @@ -920,16 +935,28 @@ class UploadManager {
);
if (res == true) {
String returnUrl = '';
if (isAnonymous == 'true') {
returnUrl = 'ftp://$ftpHost:$ftpPort$urlPath';
} else if (ftpPassword == 'None') {
returnUrl = 'ftp://$ftpUser@$ftpHost:$ftpPort$urlPath';
String displayUrl = '';
if (ftpCustomUrl != null && ftpCustomUrl != 'None') {
ftpCustomUrl = ftpCustomUrl.replaceAll(RegExp(r'/$'), '');
if (ftpWebPath != null && ftpWebPath != 'None') {
ftpWebPath = ftpWebPath.replaceAll(RegExp(r'^/*'), '').replaceAll(RegExp(r'/*$'), '');
returnUrl = '$ftpCustomUrl/$ftpWebPath/$fileName';
} else {
urlPath = urlPath.replaceAll(RegExp(r'^/*'), '');
returnUrl = '$ftpCustomUrl/$urlPath';
}
displayUrl = returnUrl;
} else {
returnUrl = 'ftp://$ftpUser:$ftpPassword@$ftpHost:$ftpPort$urlPath';
if (isAnonymous == 'true') {
returnUrl = 'ftp://$ftpHost:$ftpPort$urlPath';
} else if (ftpPassword == 'None') {
returnUrl = 'ftp://$ftpUser@$ftpHost:$ftpPort$urlPath';
} else {
returnUrl = 'ftp://$ftpUser:$ftpPassword@$ftpHost:$ftpPort$urlPath';
}
displayUrl = returnUrl;
}
returnUrl = returnUrl;
String pictureKey = jsonEncode(configMap);
String displayUrl = returnUrl;
eventBus.fire(AlbumRefreshEvent(albumKeepAlive: false));
Map<String, dynamic> maps = {};
String formatedURL = '';
Expand Down
67 changes: 60 additions & 7 deletions lib/picture_host_configure/configure_page/ftp_configure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class FTPConfigState extends State<FTPConfig> {
final _ftpPasswordController = TextEditingController(); //匿名登录时不需要
final _ftpHomeDirController = TextEditingController();
final _ftpUploadPathController = TextEditingController(); //可选
final _ftpCustomUrlController = TextEditingController(); //可选
final _ftpWebPathController = TextEditingController(); //可选

Map _ftpConfigMap = {
'ftpType': 'SFTP',
Expand Down Expand Up @@ -82,6 +84,16 @@ class FTPConfigState extends State<FTPConfig> {
} else {
_ftpHomeDirController.clear();
}
if (configMap['ftpCustomUrl'] != null && configMap['ftpCustomUrl'] != 'None') {
_ftpCustomUrlController.text = configMap['ftpCustomUrl'];
} else {
_ftpCustomUrlController.clear();
}
if (configMap['ftpWebPath'] != null && configMap['ftpWebPath'] != 'None') {
_ftpWebPathController.text = configMap['ftpWebPath'];
} else {
_ftpWebPathController.clear();
}
setState(() {});
} catch (e) {
FLog.error(
Expand All @@ -100,6 +112,8 @@ class FTPConfigState extends State<FTPConfig> {
_ftpPasswordController.dispose();
_ftpUploadPathController.dispose();
_ftpHomeDirController.dispose();
_ftpCustomUrlController.dispose();
_ftpWebPathController.dispose();
super.dispose();
}

Expand Down Expand Up @@ -210,6 +224,24 @@ class FTPConfigState extends State<FTPConfig> {
),
textAlign: TextAlign.center,
),
TextFormField(
controller: _ftpCustomUrlController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.zero,
label: Center(child: Text('可选:自定义域名')),
hintText: '例如https://test.com',
),
textAlign: TextAlign.center,
),
TextFormField(
controller: _ftpWebPathController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.zero,
label: Center(child: Text('可选:拼接用web路径')),
hintText: '例如:/test/',
),
textAlign: TextAlign.center,
),
ListTile(
title: const Text('FTP类型'),
trailing: DropdownButton<String>(
Expand Down Expand Up @@ -359,6 +391,21 @@ class FTPConfigState extends State<FTPConfig> {
ftpHomeDir = '$ftpHomeDir/';
}
}
String ftpCustomUrl = '';
if (_ftpCustomUrlController.text.isEmpty || _ftpCustomUrlController.text == '') {
ftpCustomUrl = 'None';
} else {
ftpCustomUrl = _ftpCustomUrlController.text;
}
String ftpWebPath = '';
if (_ftpWebPathController.text.isEmpty || _ftpWebPathController.text == '') {
ftpWebPath = 'None';
} else {
ftpWebPath = _ftpWebPathController.text;
if (!ftpWebPath.endsWith('/')) {
ftpWebPath = '$ftpWebPath/';
}
}
final String isAnonymous = _ftpConfigMap['isAnonymous'].toString();
final String ftpType = _ftpConfigMap['ftpType'];

Expand All @@ -375,8 +422,8 @@ class FTPConfigState extends State<FTPConfig> {
bool connectResult = await ftpConnect.connect();
await ftpConnect.disconnect();
if (connectResult == true) {
final ftpConfig =
FTPConfigModel(ftpHost, ftpPort, ftpUser, ftpPassword, ftpType, isAnonymous, ftpUploadPath, ftpHomeDir);
final ftpConfig = FTPConfigModel(ftpHost, ftpPort, ftpUser, ftpPassword, ftpType, isAnonymous,
ftpUploadPath, ftpHomeDir, ftpCustomUrl, ftpWebPath);
final ftpConfigJson = jsonEncode(ftpConfig);
final ftpConfigFile = await localFile;
await ftpConfigFile.writeAsString(ftpConfigJson);
Expand All @@ -393,8 +440,8 @@ class FTPConfigState extends State<FTPConfig> {
);
client.close();

final ftpConfig =
FTPConfigModel(ftpHost, ftpPort, ftpUser, ftpPassword, ftpType, isAnonymous, ftpUploadPath, ftpHomeDir);
final ftpConfig = FTPConfigModel(ftpHost, ftpPort, ftpUser, ftpPassword, ftpType, isAnonymous, ftpUploadPath,
ftpHomeDir, ftpCustomUrl, ftpWebPath);
final ftpConfigJson = jsonEncode(ftpConfig);
final ftpConfigFile = await localFile;
await ftpConfigFile.writeAsString(ftpConfigJson);
Expand Down Expand Up @@ -450,7 +497,7 @@ class FTPConfigState extends State<FTPConfig> {
context: context,
title: '通知',
content:
'检测通过,您的配置信息为:\n用户名:\n${configMap["ftpHost"]}\n端口:\n${configMap["ftpPort"]}\n用户名:\n${configMap["ftpUser"]}\n密码:\n${configMap["ftpPassword"]}\n上传路径:\n${configMap["uploadPath"]}\n管理功能起始路径:\n${configMap["ftpHomeDir"]}',
'检测通过,您的配置信息为:\n用户名:\n${configMap["ftpHost"]}\n端口:\n${configMap["ftpPort"]}\n用户名:\n${configMap["ftpUser"]}\n密码:\n${configMap["ftpPassword"]}\n上传路径:\n${configMap["uploadPath"]}\n管理功能起始路径:\n${configMap["ftpHomeDir"]}\n自定义URL:\n${configMap["ftpCustomUrl"]}',
);
} else {
return showCupertinoAlertDialog(context: context, title: '错误', content: '检查失败,请检查配置信息');
Expand All @@ -469,7 +516,7 @@ class FTPConfigState extends State<FTPConfig> {
context: context,
title: '通知',
content:
'检测通过,您的配置信息为:\n用户名:\n${configMap["ftpHost"]}\n端口:\n${configMap["ftpPort"]}\n用户名:\n${configMap["ftpUser"]}\n密码:\n${configMap["ftpPassword"]}\n上传路径:\n${configMap["uploadPath"]}\n管理功能起始路径:\n${configMap["ftpHomeDir"]}',
'检测通过,您的配置信息为:\n用户名:\n${configMap["ftpHost"]}\n端口:\n${configMap["ftpPort"]}\n用户名:\n${configMap["ftpUser"]}\n密码:\n${configMap["ftpPassword"]}\n上传路径:\n${configMap["uploadPath"]}\n管理功能起始路径:\n${configMap["ftpHomeDir"]}\n自定义URL:\n${configMap["ftpCustomUrl"]}',
);
}
} catch (e) {
Expand Down Expand Up @@ -535,9 +582,11 @@ class FTPConfigModel {
final String isAnonymous;
final String uploadPath;
final String ftpHomeDir;
final String ftpCustomUrl;
final String ftpWebPath;

FTPConfigModel(this.ftpHost, this.ftpPort, this.ftpUser, this.ftpPassword, this.ftpType, this.isAnonymous,
this.uploadPath, this.ftpHomeDir);
this.uploadPath, this.ftpHomeDir, this.ftpCustomUrl, this.ftpWebPath);

Map<String, dynamic> toJson() => {
'ftpHost': ftpHost,
Expand All @@ -548,6 +597,8 @@ class FTPConfigModel {
'isAnonymous': isAnonymous,
'uploadPath': uploadPath,
'ftpHomeDir': ftpHomeDir,
'ftpCustomUrl': ftpCustomUrl,
'ftpWebPath': ftpWebPath
};

static List keysList = [
Expand All @@ -560,5 +611,7 @@ class FTPConfigModel {
'isAnonymous',
'uploadPath',
'ftpHomeDir',
'ftpCustomUrl',
'ftpWebPath'
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class FtpConfigureStoreEditState extends State<FtpConfigureStoreEdit> {
final _ftpPasswordController = TextEditingController(); //匿名登录时不需要
final _ftpHomeDirController = TextEditingController();
final _ftpUploadPathController = TextEditingController(); //可选
final _ftpCustomUrlController = TextEditingController(); //可选
final _ftpWebPathController = TextEditingController(); //可选

Map _ftpConfigMap = {
'ftpType': 'SFTP',
Expand Down Expand Up @@ -200,6 +202,24 @@ class FtpConfigureStoreEditState extends State<FtpConfigureStoreEdit> {
),
textAlign: TextAlign.center,
),
TextFormField(
controller: _ftpCustomUrlController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.zero,
label: Center(child: Text('可选: 自定义URL')),
hintText: '例如:https://www.test.com',
),
textAlign: TextAlign.center,
),
TextFormField(
controller: _ftpWebPathController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.zero,
label: Center(child: Text('可选: 拼接用web路径')),
hintText: '例如:/test/',
),
textAlign: TextAlign.center,
),
ListTile(
title: const Text('FTP类型'),
trailing: DropdownButton<String>(
Expand Down Expand Up @@ -269,6 +289,12 @@ class FtpConfigureStoreEditState extends State<FtpConfigureStoreEdit> {
if (configMap['ftpHomeDir'] != 'None') {
_ftpHomeDirController.text = configMap['ftpHomeDir'];
}
if (configMap['ftpCustomUrl'] != 'None' && configMap['ftpCustomUrl'] != null) {
_ftpCustomUrlController.text = configMap['ftpCustomUrl'];
}
if (configMap['ftpWebPath'] != 'None' && configMap['ftpWebPath'] != null) {
_ftpWebPathController.text = configMap['ftpWebPath'];
}
_ftpConfigMap['ftpType'] = configMap['ftpType'];
_ftpConfigMap['isAnonymous'] = configMap['isAnonymous'].toString();

Expand All @@ -289,6 +315,8 @@ class FtpConfigureStoreEditState extends State<FtpConfigureStoreEdit> {
String ftpHomeDir = _ftpHomeDirController.text;
String ftpType = _ftpConfigMap['ftpType'];
String isAnonymous = _ftpConfigMap['isAnonymous'].toString();
String ftpCustomUrl = _ftpCustomUrlController.text;
String ftpWebPath = _ftpWebPathController.text;

if (remarkName.isEmpty || remarkName.trim().isEmpty) {
remarkName = ConfigureTemplate.placeholder;
Expand Down Expand Up @@ -318,6 +346,14 @@ class FtpConfigureStoreEditState extends State<FtpConfigureStoreEdit> {
}
}

if (ftpCustomUrl.isEmpty || ftpCustomUrl.trim().isEmpty) {
ftpCustomUrl = ConfigureTemplate.placeholder;
}

if (ftpWebPath.isEmpty || ftpWebPath.trim().isEmpty) {
ftpWebPath = ConfigureTemplate.placeholder;
}

Map psInfo = {
'remarkName': remarkName,
'ftpHost': ftpHost,
Expand All @@ -328,6 +364,8 @@ class FtpConfigureStoreEditState extends State<FtpConfigureStoreEdit> {
'isAnonymous': isAnonymous,
'uploadPath': ftpUploadPath,
'ftpHomeDir': ftpHomeDir,
'ftpCustomUrl': ftpCustomUrl,
'ftpWebPath': ftpWebPath,
};

try {
Expand Down

0 comments on commit 569f748

Please sign in to comment.