mirror of
https://github.com/SabreTools/SabreTools.RedumpLib.git
synced 2026-11-15 17:01:37 +00:00
Move query normalization
This commit is contained in:
@@ -279,7 +279,7 @@ namespace SabreTools.RedumpLib.Endpoints
|
||||
|
||||
// General Query
|
||||
if (Query is not null)
|
||||
sb.Append($"q={Query}&");
|
||||
sb.Append($"q={NormalizeQuery(Query)}&");
|
||||
|
||||
// Sorting
|
||||
if (Sort is not null && Enum.IsDefined(typeof(SortCategory), Sort))
|
||||
@@ -299,5 +299,25 @@ namespace SabreTools.RedumpLib.Endpoints
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a URL query string
|
||||
/// </summary>
|
||||
/// <param name="query">Query string to normalize</param>
|
||||
/// <returns>Normalized query</returns>
|
||||
private static string NormalizeQuery(string query)
|
||||
{
|
||||
// Strip quotes
|
||||
query = query!.Trim('"', '\'');
|
||||
|
||||
// Special characters become dashes
|
||||
query = query.Replace(' ', '-');
|
||||
query = query.Replace('\\', '-');
|
||||
query = query.Replace('/', '-');
|
||||
|
||||
// Lowercase is defined per language
|
||||
query = query.ToLowerInvariant();
|
||||
return query;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,10 +573,6 @@ namespace SabreTools.RedumpLib.Web
|
||||
long? tracksMin = null,
|
||||
string? universalHash = null)
|
||||
{
|
||||
// Normalize the search query, if needed
|
||||
if (query is not null)
|
||||
query = NormalizeQuery(query);
|
||||
|
||||
var endpoint = new Endpoints.Discs
|
||||
{
|
||||
System = system,
|
||||
@@ -978,26 +974,6 @@ namespace SabreTools.RedumpLib.Web
|
||||
return processed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalize a URL query string
|
||||
/// </summary>
|
||||
/// <param name="query">Query string to normalize</param>
|
||||
/// <returns>Normalized query</returns>
|
||||
private static string NormalizeQuery(string query)
|
||||
{
|
||||
// Strip quotes
|
||||
query = query!.Trim('"', '\'');
|
||||
|
||||
// Special characters become dashes
|
||||
query = query.Replace(' ', '-');
|
||||
query = query.Replace('\\', '-');
|
||||
query = query.Replace('/', '-');
|
||||
|
||||
// Lowercase is defined per language
|
||||
query = query.ToLowerInvariant();
|
||||
return query;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Download Helpers
|
||||
|
||||
Reference in New Issue
Block a user