Skip to content

Commit 86ea22e

Browse files
committed
修正gitee basd address 问题
1 parent 037fd75 commit 86ea22e

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Extensions.Configuration.GitRepository.GiteeProvider/GiteeRepositoryClient.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ private void check_config()
2626
var rp = _options.RepositoryPath.Split('/');
2727
owner = rp[0];
2828
repoName = rp[1];
29-
_client.BaseAddress = new Uri($"https://gitee.com/api/v5/repos/{owner}/{repoName}/contents/");
29+
_client.BaseAddress = new Uri($"https://gitee.com/api/v5/repos/{owner}/{repoName}/");
3030
}
3131
}
3232

3333
public bool FileExists(string _filePath)
3434
{
3535
check_config();
36-
var reps = _client.GetAsync($"/{_filePath}?access_token={_options.AuthenticationToken}").GetAwaiter().GetResult();
36+
var reps = _client.GetAsync($"contents/{_filePath}?access_token={_options.AuthenticationToken}").GetAwaiter().GetResult();
3737
if (reps.StatusCode == System.Net.HttpStatusCode.OK)
3838
{
39-
var rep = JsonSerializer.Deserialize<List<GitContent>>(reps.Content.ReadAsStream());
40-
return rep?.Any(gc => gc.path == _filePath) == true;
39+
var rep = JsonSerializer.Deserialize<GitContent>(reps.Content.ReadAsStream());
40+
return rep.path== _filePath;
4141
}
4242
else
4343
{
@@ -58,7 +58,7 @@ public void PutFile(string _fileName, string _content, string _msg)
5858
check_config();
5959
//curl -X POST --header 'Content-Type: ' 'https://gitee.com/api/v5/repos/maikebing/gitcfg/contents/Gitee.json' -d '{"access_token":"d675106450be61985dd39ec076cc05c0","content":"sdfsd","message":"sdfsd"}'
6060
var body = JsonContent.Create(new { access_token = _options.AuthenticationToken, content = Convert.ToBase64String(Encoding.UTF8.GetBytes(_content)), message = _msg });
61-
var reps = _client.PostAsync($"{_fileName}", body).GetAwaiter().GetResult();
61+
var reps = _client.PostAsync($"contents/{_fileName}", body).GetAwaiter().GetResult();
6262
}
6363
}
6464
}

Extensions.Configuration.GitRepository/GitRepositoryConfigurationProvider.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ private bool ReadGitRepo( ref JsonDocument _jsonData)
105105
var _diff = JsonDiff<JsonNode>.Diff(_jsonData, JsonDocument.Parse(fileContent)).ToArray();
106106
if (_diff.Any())
107107
{
108+
108109
var jp = new JsonPatch(_diff.ToArray());
109110
var _jn = jp.Apply(_jsonData.RootElement);
110111
string _json = _jn.ToJsonString(new JsonSerializerOptions() { WriteIndented = true });
@@ -149,7 +150,11 @@ private void SaveCache(string fileContent)
149150
{
150151
try
151152
{
152-
System.IO.File.WriteAllText(_options.CacheToFile, fileContent);
153+
if(!string.IsNullOrEmpty(_options.CacheToFile))
154+
{
155+
System.IO.File.WriteAllText(_options.CacheToFile, fileContent);
156+
}
157+
153158
}
154159
catch (Exception ex)
155160
{

0 commit comments

Comments
 (0)