styles:同步PicGo配置的命名

This commit is contained in:
hackycy
2020-06-28 23:37:28 +08:00
parent 3f3e0fac37
commit 39dd08702b
4 changed files with 31 additions and 36 deletions

View File

@@ -1,32 +1,27 @@
class GithubConfig {
String repositoryName;
String branchName;
String branch;
String customUrl;
String path;
String repo;
String token;
String storagePath;
String customDomain;
GithubConfig(
{this.repositoryName,
this.branchName,
this.token,
this.storagePath,
this.customDomain});
GithubConfig({this.branch, this.customUrl, this.path, this.repo, this.token});
GithubConfig.fromJson(Map<String, dynamic> json) {
repositoryName = json['repositoryName'];
branchName = json['branchName'];
branch = json['branch'];
customUrl = json['customUrl'];
path = json['path'];
repo = json['repo'];
token = json['token'];
storagePath = json['storagePath'];
customDomain = json['customDomain'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['repositoryName'] = this.repositoryName;
data['branchName'] = this.branchName;
data['branch'] = this.branch;
data['customUrl'] = this.customUrl;
data['path'] = this.path;
data['repo'] = this.repo;
data['token'] = this.token;
data['storagePath'] = this.storagePath;
data['customDomain'] = this.customDomain;
return data;
}
}

View File

@@ -47,26 +47,26 @@ class GithubImageUpload implements ImageUploadStrategy {
GithubConfig.fromJson(json.decode(configStr));
String realUrl = path.joinAll([
'repos',
config.repositoryName,
config.repo,
'contents',
config.storagePath,
config.path,
renameImage
]);
var result = await GithubApi.putContent(realUrl, {
"message": UPLOAD_COMMIT_MESSAGE,
"content": await EncryptUtils.image2Base64(file.path),
"branch": config.branchName
"branch": config.branch
});
String imagePath = result["content"]["path"];
String downloadUrl = result["content"]["download_url"];
String sha = result["content"]["sha"];
String imageUrl =
config.customDomain == null || config.customDomain == ''
isBlank(config.customUrl)
? downloadUrl
: '${path.joinAll([config.customDomain, imagePath])}';
: '${path.joinAll([config.customUrl, imagePath])}';
var uploadedItem = Uploaded(-1, imageUrl, PBTypeKeys.github,
info: json.encode(GithubUploadedInfo(
path: imagePath, sha: sha, branch: config.branchName, ownerrepo: config.repositoryName)));
path: imagePath, sha: sha, branch: config.branch, ownerrepo: config.repo)));
await ImageUploadUtils.saveUploadedItem(uploadedItem);
return uploadedItem;
} else {

View File

@@ -41,14 +41,14 @@ class _GithubPageState extends State<GithubPage> implements GithubPageContract {
@override
Widget build(BuildContext context) {
_repositoryNameController =
TextEditingController(text: _config?.repositoryName ?? '');
TextEditingController(text: _config?.repo ?? '');
_branchNameController =
TextEditingController(text: _config?.branchName ?? '');
TextEditingController(text: _config?.branch ?? '');
_tokenController = TextEditingController(text: _config?.token ?? '');
_storagePathController =
TextEditingController(text: _config?.storagePath ?? '');
TextEditingController(text: _config?.path ?? '');
_customDomainController =
TextEditingController(text: _config?.customDomain ?? '');
TextEditingController(text: _config?.customUrl ?? '');
return Scaffold(
appBar: AppBar(
title: Text('Github图床'),
@@ -205,11 +205,11 @@ class _GithubPageState extends State<GithubPage> implements GithubPageContract {
void _saveConfig() {
if (_formKey.currentState.validate()) {
var config = GithubConfig(
repositoryName: _repositoryNameController.text.trim(),
branchName: _branchNameController.text.trim(),
repo: _repositoryNameController.text.trim(),
branch: _branchNameController.text.trim(),
token: _tokenController.text.trim(),
storagePath: _storagePathController.text.trim(),
customDomain: _customDomainController.text.trim());
path: _storagePathController.text.trim(),
customUrl: _customDomainController.text.trim());
_presenter.doSaveConfig(config);
}
}

View File

@@ -22,21 +22,21 @@ class GithubRepoPagePresenter {
try {
String configStr = await ImageUploadUtils.getPBConfig(PBTypeKeys.github);
GithubConfig config = GithubConfig.fromJson(json.decode(configStr));
if (isBlank(config.branchName) ||
isBlank(config.repositoryName) ||
if (isBlank(config.branch) ||
isBlank(config.repo) ||
isBlank(config.token)) {
_view.loadError('读取配置错误!');
return;
}
String realUrl = pathutil.joinAll([
'repos',
config.repositoryName,
config.repo,
'contents',
prePath ?? '',
path == '/' ? '' : path
]);
List result =
await GithubApi.getContents(realUrl, {"ref": config.branchName});
await GithubApi.getContents(realUrl, {"ref": config.branch});
var data = result.map((e) {
return GithubContent.fromJson(e);
}).toList();