-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
262 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Flutter-Picgo Release</title> | ||
<script> | ||
// var u = navigator.userAgent; | ||
// var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //判断是否是 android终端 | ||
// var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //判断是否是 iOS终端 | ||
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { | ||
window.location.href = 'https://apps.apple.com/cn/app/flutter-picgo/id1519714305' | ||
} else if (/(Android)/i.test(navigator.userAgent)) { | ||
window.location.href = 'https://www.pgyer.com/flutter-picgo' | ||
} | ||
</script> | ||
</head> | ||
|
||
<body> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
{ | ||
"iOS": { | ||
"versionName": "1.6.0", | ||
"versionCode": "14" | ||
"versionName": "1.7.0", | ||
"versionCode": "15" | ||
}, | ||
"Android": { | ||
"versionName": "1.6.0", | ||
"versionCode": "14" | ||
"versionName": "1.7.0", | ||
"versionCode": "15" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:flutter_picgo/utils/net.dart'; | ||
import 'package:path/path.dart' as path; | ||
|
||
class LskyApi { | ||
static Future token(String email, String pwd, String host) async { | ||
String url = path.joinAll([host, 'api/token']); | ||
Response res = await NetUtils.getInstance().post(url, data: { | ||
'email': email, | ||
'password': pwd, | ||
}); | ||
return res.data; | ||
} | ||
|
||
static Future upload(String token, String host, FormData data) async { | ||
String url = path.joinAll([host, 'api/upload']); | ||
Response res = await NetUtils.getInstance() | ||
.post(url, data: data, options: buildCommonOptions(token)); | ||
return res.data; | ||
} | ||
|
||
static Options buildCommonOptions(String token) { | ||
return Options(headers: { | ||
'token': token, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class LskyConfig { | ||
String host; | ||
String email; | ||
String password; | ||
String token; | ||
|
||
LskyConfig({this.host, this.email, this.password, this.token}); | ||
|
||
LskyConfig.fromJson(Map<String, dynamic> json) { | ||
host = json['host']; | ||
email = json['email']; | ||
password = json['password']; | ||
token = json['token']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['host'] = this.host; | ||
data['email'] = this.email; | ||
data['password'] = this.password; | ||
data['token'] = this.token; | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,6 @@ class PBTypeKeys { | |
static const tcyun = 'tcyun'; | ||
|
||
static const niupic = 'niupic'; | ||
|
||
static const lsky = 'lsky'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:flutter_picgo/api/lsky_api.dart'; | ||
import 'package:flutter_picgo/model/lsky_config.dart'; | ||
import 'package:flutter_picgo/model/uploaded.dart'; | ||
import 'package:flutter_picgo/resources/pb_type_keys.dart'; | ||
import 'package:flutter_picgo/utils/image_upload.dart'; | ||
import 'dart:io'; | ||
|
||
import 'package:flutter_picgo/utils/strategy/image_upload_strategy.dart'; | ||
import 'package:flutter_picgo/utils/strings.dart'; | ||
|
||
class LskyImageUpload implements ImageUploadStrategy { | ||
@override | ||
Future<Uploaded> delete(Uploaded uploaded) async { | ||
return uploaded; | ||
} | ||
|
||
@override | ||
Future<Uploaded> upload(File file, String renameImage) async { | ||
String configStr = await ImageUploadUtils.getPBConfig(PBTypeKeys.lsky); | ||
if (isBlank(configStr)) { | ||
throw LskyError(error: '读取配置文件错误!请重试'); | ||
} | ||
LskyConfig config = LskyConfig.fromJson(json.decode(configStr)); | ||
FormData formData = FormData.fromMap({ | ||
"image": await MultipartFile.fromFile(file.path, filename: renameImage), | ||
}); | ||
var result = await LskyApi.upload(config.token, config.host, formData); | ||
if (result['code'] == 200) { | ||
var uploadedItem = | ||
Uploaded(-1, '${result['data']['url']}', PBTypeKeys.lsky, info: ''); | ||
await ImageUploadUtils.saveUploadedItem(uploadedItem); | ||
return uploadedItem; | ||
} else { | ||
throw new LskyError(error: '${result['msg']}'); | ||
} | ||
} | ||
} | ||
|
||
class LskyError implements Exception { | ||
LskyError({ | ||
this.error, | ||
}); | ||
|
||
dynamic error; | ||
|
||
String get message => (error?.toString() ?? ''); | ||
|
||
@override | ||
String toString() { | ||
var msg = 'LskyError $message'; | ||
if (error is Error) { | ||
msg += '\n${error.stackTrace}'; | ||
} | ||
return msg; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_picgo/api/lsky_api.dart'; | ||
import 'package:flutter_picgo/model/config.dart'; | ||
import 'package:flutter_picgo/model/lsky_config.dart'; | ||
import 'package:flutter_picgo/resources/pb_type_keys.dart'; | ||
import 'package:flutter_picgo/utils/strings.dart'; | ||
import 'package:flutter_picgo/views/pb_setting_page/base_pb_page_state.dart'; | ||
import 'package:toast/toast.dart'; | ||
|
||
class LskyPage extends StatefulWidget { | ||
_LskyPageState createState() => _LskyPageState(); | ||
} | ||
|
||
class _LskyPageState extends BasePBSettingPageState<LskyPage> { | ||
@override | ||
AppBar get appbar => AppBar( | ||
title: Text('兰空图床'), | ||
centerTitle: true, | ||
); | ||
|
||
@override | ||
onLoadConfig(String config) { | ||
List<Config> configs = []; | ||
Map<String, dynamic> map; | ||
if (isBlank(config)) { | ||
map = LskyConfig().toJson(); | ||
} else { | ||
map = LskyConfig.fromJson(json.decode(config)).toJson(); | ||
} | ||
map.forEach((key, value) { | ||
Config config; | ||
if (key == 'host') { | ||
config = Config( | ||
label: '设定Host', | ||
placeholder: '例如:https://lsky.si-yee.com', | ||
needValidate: true, | ||
value: value); | ||
} else if (key == 'token') { | ||
config = Config( | ||
label: '设定Token', | ||
placeholder: 'Token', | ||
needValidate: false, | ||
value: value); | ||
} else if (key == 'email') { | ||
config = Config( | ||
label: '设定邮箱', | ||
placeholder: 'Email', | ||
needValidate: true, | ||
value: value); | ||
} else if (key == 'password') { | ||
config = Config( | ||
label: '设定密码', | ||
placeholder: '设定密码', | ||
needValidate: true, | ||
value: value); | ||
} | ||
config.name = key; | ||
configs.add(config); | ||
}); | ||
setConfigs(configs); | ||
} | ||
|
||
@override | ||
String get tip => '点击保存会自动获取Token,如果已填写字段则不会自动生成'; | ||
|
||
@override | ||
String get pbType => PBTypeKeys.lsky; | ||
|
||
@override | ||
save() async { | ||
if (isBlank(controllers['token'].text.trim())) { | ||
// 如果Token为空,则自动获取 | ||
String email = controllers['email'].value.text.trim(); | ||
String pwd = controllers['password'].value.text.trim(); | ||
String host = controllers['host'].value.text.trim(); | ||
var result = await LskyApi.token(email, pwd, host); | ||
if (result["code"] == 200) { | ||
// controllers["token"].text = '${result["data"]["token"]}'; | ||
setState(() { | ||
configs[3].value = '${result["data"]["token"]}'; | ||
|
||
super.save(); | ||
}); | ||
} else { | ||
Toast.show('Token获取失败,请检查配置', context); | ||
} | ||
} else { | ||
return super.save(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters