From 39dd08702bb3795900a9e32b2051dd3601cfd05e Mon Sep 17 00:00:00 2001 From: hackycy Date: Sun, 28 Jun 2020 23:37:28 +0800 Subject: [PATCH] =?UTF-8?q?styles=EF=BC=9A=E5=90=8C=E6=AD=A5PicGo=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/model/github_config.dart | 31 ++++++++----------- .../strategy/impl/github_image_upload.dart | 12 +++---- .../github_page/github_page.dart | 16 +++++----- .../github_repo_page_presenter.dart | 8 ++--- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/lib/model/github_config.dart b/lib/model/github_config.dart index f673642..899cf47 100644 --- a/lib/model/github_config.dart +++ b/lib/model/github_config.dart @@ -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 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 toJson() { final Map data = new Map(); - 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; } } \ No newline at end of file diff --git a/lib/utils/strategy/impl/github_image_upload.dart b/lib/utils/strategy/impl/github_image_upload.dart index c61b9d4..c1cb964 100644 --- a/lib/utils/strategy/impl/github_image_upload.dart +++ b/lib/utils/strategy/impl/github_image_upload.dart @@ -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 { diff --git a/lib/views/pb_setting_page/github_page/github_page.dart b/lib/views/pb_setting_page/github_page/github_page.dart index e3431f3..27115a0 100644 --- a/lib/views/pb_setting_page/github_page/github_page.dart +++ b/lib/views/pb_setting_page/github_page/github_page.dart @@ -41,14 +41,14 @@ class _GithubPageState extends State 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 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); } } diff --git a/lib/views/pb_setting_page/github_page/github_repo_page_presenter.dart b/lib/views/pb_setting_page/github_page/github_repo_page_presenter.dart index 468c182..4e1eb67 100644 --- a/lib/views/pb_setting_page/github_page/github_repo_page_presenter.dart +++ b/lib/views/pb_setting_page/github_page/github_repo_page_presenter.dart @@ -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();