Escape slashes in package name
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
namespace sh.actions.package_cleanup.Service;
|
namespace sh.actions.package_cleanup.Service;
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using sh.actions.package_cleanup.Models;
|
using sh.actions.package_cleanup.Models;
|
||||||
@@ -10,8 +11,10 @@ public class GiteaPackageService(
|
|||||||
HttpClient httpClient)
|
HttpClient httpClient)
|
||||||
: IGiteaPackageService
|
: IGiteaPackageService
|
||||||
{
|
{
|
||||||
|
private static string EncodePathSegment(string? s) => Uri.EscapeDataString((s ?? string.Empty));
|
||||||
|
|
||||||
private string GetBaseUrl() =>
|
private string GetBaseUrl() =>
|
||||||
$"{configuration["URL"]?.TrimEnd('/')}/packages/{configuration["OWNER"]}";
|
$"{configuration["URL"]?.TrimEnd('/')}/packages/{EncodePathSegment(configuration["OWNER"]) }";
|
||||||
|
|
||||||
private void AddAuthorizationHeader(HttpRequestMessage request)
|
private void AddAuthorizationHeader(HttpRequestMessage request)
|
||||||
{
|
{
|
||||||
@@ -45,7 +48,10 @@ public class GiteaPackageService(
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var url = $"{baseUrl}/{type}/{name}?page={page}";
|
var encodedType = EncodePathSegment(type);
|
||||||
|
var encodedName = EncodePathSegment(name);
|
||||||
|
|
||||||
|
var url = $"{baseUrl}/{encodedType}/{encodedName}?page={page}";
|
||||||
logger.LogInformation("Fetching packages from Gitea: {Url}", url);
|
logger.LogInformation("Fetching packages from Gitea: {Url}", url);
|
||||||
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
var request = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
@@ -126,7 +132,11 @@ public class GiteaPackageService(
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var baseUrl = GetBaseUrl();
|
var baseUrl = GetBaseUrl();
|
||||||
var url = $"{baseUrl}/{package.Type}/{package.Name}/{package.Version}";
|
var encodedType = EncodePathSegment(package.Type);
|
||||||
|
var encodedName = EncodePathSegment(package.Name);
|
||||||
|
var encodedVersion = EncodePathSegment(package.Version);
|
||||||
|
|
||||||
|
var url = $"{baseUrl}/{encodedType}/{encodedName}/{encodedVersion}";
|
||||||
logger.LogInformation("Deleting package {PackageName} (ID: {PackageId}) from Gitea",
|
logger.LogInformation("Deleting package {PackageName} (ID: {PackageId}) from Gitea",
|
||||||
package.Name, package.Id);
|
package.Name, package.Id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user