Fix: Wrong manifest downloaded when installing plugin on old btcpay (Fix #6344) (#6354)

This commit is contained in:
Nicolas Dorier 2024-11-04 13:05:10 +09:00 committed by GitHub
parent 693eceb80f
commit 7aa87d397e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 2 deletions

View File

@ -65,5 +65,17 @@ namespace BTCPayServer.Plugins
var result = await httpClient.GetStringAsync($"api/v1/plugins{queryString}");
return JsonConvert.DeserializeObject<PublishedVersion[]>(result, serializerSettings) ?? throw new InvalidOperationException();
}
public async Task<PublishedVersion> GetPlugin(string pluginSlug, string version)
{
try
{
var result = await httpClient.GetStringAsync($"api/v1/plugins/{pluginSlug}/versions/{version}");
return JsonConvert.DeserializeObject<PublishedVersion>(result, serializerSettings);
}
catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
{
return null;
}
}
}
}

View File

@ -72,9 +72,11 @@ namespace BTCPayServer.Plugins
var dest = _dataDirectories.Value.PluginDir;
var filedest = Path.Join(dest, pluginIdentifier + ".btcpay");
var filemanifestdest = Path.Join(dest, pluginIdentifier + ".json");
var pluginSelector = $"[{Uri.EscapeDataString(pluginIdentifier)}]";
version = Uri.EscapeDataString(version);
Directory.CreateDirectory(Path.GetDirectoryName(filedest));
var url = $"api/v1/plugins/[{Uri.EscapeDataString(pluginIdentifier)}]/versions/{Uri.EscapeDataString(version)}/download";
var manifest = (await _pluginBuilderClient.GetPublishedVersions(null, true)).Select(v => v.ManifestInfo.ToObject<AvailablePlugin>()).FirstOrDefault(p => p.Identifier == pluginIdentifier);
var url = $"api/v1/plugins/{pluginSelector}/versions/{version}/download";
var manifest = (await _pluginBuilderClient.GetPlugin(pluginSelector, version))?.ManifestInfo?.ToObject<AvailablePlugin>();
await File.WriteAllTextAsync(filemanifestdest, JsonConvert.SerializeObject(manifest, Formatting.Indented));
using var resp2 = await _pluginBuilderClient.HttpClient.GetAsync(url);
await using var fs = new FileStream(filedest, FileMode.Create, FileAccess.ReadWrite);