mirror of
https://github.com/SabreTools/SabreTools.RedumpLib.git
synced 2026-11-15 17:01:37 +00:00
Add a couple more
This commit is contained in:
20
SabreTools.RedumpLib.Test/Endpoints/AboutTests.cs
Normal file
20
SabreTools.RedumpLib.Test/Endpoints/AboutTests.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.RedumpLib.Test.Endpoints
|
||||
{
|
||||
public class AboutTests
|
||||
{
|
||||
#region BuildUrl
|
||||
|
||||
[Fact]
|
||||
public void BuildAboutUrl_Constant()
|
||||
{
|
||||
var endpoint = new RedumpLib.Endpoints.About();
|
||||
|
||||
string actual = endpoint.BuildUrl();
|
||||
Assert.Equal("https://redump.info/about", actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
38
SabreTools.RedumpLib.Test/Endpoints/DiscTests.cs
Normal file
38
SabreTools.RedumpLib.Test/Endpoints/DiscTests.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using SabreTools.RedumpLib.Data;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.RedumpLib.Test.Endpoints
|
||||
{
|
||||
public class DiscTests
|
||||
{
|
||||
#region BuildUrl
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1)]
|
||||
[InlineData(-1, 1)]
|
||||
public void BuildDiscUrl_AlwaysPositive(int id, int expected)
|
||||
{
|
||||
var endpoint = new RedumpLib.Endpoints.Disc { Id = id };
|
||||
string actual = endpoint.BuildUrl();
|
||||
Assert.Equal($"https://redump.info/disc/{expected}", actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, "https://redump.info/disc/1")]
|
||||
[InlineData(DiscSubpath.Cuesheet, "https://redump.info/disc/1/cue")]
|
||||
[InlineData(DiscSubpath.Edit, "https://redump.info/disc/1/edit")]
|
||||
[InlineData(DiscSubpath.SBI, "https://redump.info/disc/1/sbi")]
|
||||
public void BuildDiscUrl_Subpath_Builds(DiscSubpath? subpath, string expected)
|
||||
{
|
||||
var endpoint = new RedumpLib.Endpoints.Disc
|
||||
{
|
||||
Id = 1,
|
||||
Subpath = subpath,
|
||||
};
|
||||
string actual = endpoint.BuildUrl();
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -7,41 +7,6 @@ namespace SabreTools.RedumpLib.Test.Web
|
||||
{
|
||||
public class UrlBuilderTests
|
||||
{
|
||||
#region BuildAboutUrl
|
||||
|
||||
[Fact]
|
||||
public void BuildAboutUrl_Constant()
|
||||
{
|
||||
string actual = UrlBuilder.BuildAboutUrl();
|
||||
Assert.Equal("https://redump.info/about", actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BuildDiscUrl
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 1)]
|
||||
[InlineData(-1, 1)]
|
||||
public void BuildDiscUrl_AlwaysPositive(int id, int expected)
|
||||
{
|
||||
string actual = UrlBuilder.BuildDiscUrl(id);
|
||||
Assert.Equal($"https://redump.info/disc/{expected}", actual);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, "https://redump.info/disc/1")]
|
||||
[InlineData(DiscSubpath.Cuesheet, "https://redump.info/disc/1/cue")]
|
||||
[InlineData(DiscSubpath.Edit, "https://redump.info/disc/1/edit")]
|
||||
[InlineData(DiscSubpath.SBI, "https://redump.info/disc/1/sbi")]
|
||||
public void BuildDiscUrl_Subpath_Builds(DiscSubpath? subpath, string expected)
|
||||
{
|
||||
string actual = UrlBuilder.BuildDiscUrl(1, subpath);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BuildDownloadsUrl
|
||||
|
||||
[Theory]
|
||||
|
||||
24
SabreTools.RedumpLib/Endpoints/About.cs
Normal file
24
SabreTools.RedumpLib/Endpoints/About.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace SabreTools.RedumpLib.Endpoints
|
||||
{
|
||||
[JsonObject("about")]
|
||||
public class About
|
||||
{
|
||||
/// <summary>
|
||||
/// Build a /discs/ path URL
|
||||
/// </summary>
|
||||
public string BuildUrl()
|
||||
{
|
||||
var ub = new UriBuilder
|
||||
{
|
||||
Scheme = "https",
|
||||
Host = "redump.info",
|
||||
Path = "about",
|
||||
};
|
||||
|
||||
return ub.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
47
SabreTools.RedumpLib/Endpoints/Disc.cs
Normal file
47
SabreTools.RedumpLib/Endpoints/Disc.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.RedumpLib.Data;
|
||||
|
||||
namespace SabreTools.RedumpLib.Endpoints
|
||||
{
|
||||
/// TODO: Handle submit path?
|
||||
[JsonObject("disc")]
|
||||
public class Disc
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonProperty("subpath")]
|
||||
public DiscSubpath? Subpath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Build a /discs/ path URL
|
||||
/// </summary>
|
||||
public string BuildUrl()
|
||||
{
|
||||
var ub = new UriBuilder
|
||||
{
|
||||
Scheme = "https",
|
||||
Host = "redump.info",
|
||||
Path = $"disc/{Math.Abs(Id)}",
|
||||
};
|
||||
|
||||
switch (Subpath)
|
||||
{
|
||||
case DiscSubpath.Cuesheet:
|
||||
case DiscSubpath.Edit:
|
||||
case DiscSubpath.SBI:
|
||||
ub.Path += $"/{Subpath.ShortName()}";
|
||||
break;
|
||||
|
||||
// History and null are invalid for a disc page
|
||||
case DiscSubpath.History:
|
||||
case null:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ub.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1149,7 +1149,8 @@ namespace SabreTools.RedumpLib.Web
|
||||
try
|
||||
{
|
||||
// Try to retrieve the data
|
||||
string discPageUri = UrlBuilder.BuildDiscUrl(id);
|
||||
var endpoint = new Endpoints.Disc { Id = id };
|
||||
string discPageUri = endpoint.BuildUrl();
|
||||
string? discPage = await DownloadString(discPageUri);
|
||||
|
||||
if (discPage is null)
|
||||
@@ -1197,7 +1198,8 @@ namespace SabreTools.RedumpLib.Web
|
||||
try
|
||||
{
|
||||
// Try to retrieve the data
|
||||
string discPageUri = UrlBuilder.BuildDiscUrl(id);
|
||||
var endpoint = new Endpoints.Disc { Id = id };
|
||||
string discPageUri = endpoint.BuildUrl();
|
||||
string? discPage = await DownloadString(discPageUri);
|
||||
|
||||
if (discPage is null)
|
||||
@@ -1265,7 +1267,12 @@ namespace SabreTools.RedumpLib.Web
|
||||
// View Edit History
|
||||
if ((discSubpaths is null || Array.Exists(discSubpaths, s => s is DiscSubpath.History)) && discPage.Contains($"<a href=\"/queue/?disc_id=/{id}"))
|
||||
{
|
||||
string uri = UrlBuilder.BuildDiscUrl(id, DiscSubpath.History);
|
||||
var subEndpoint = new Endpoints.Disc
|
||||
{
|
||||
Id = id,
|
||||
Subpath = DiscSubpath.History,
|
||||
};
|
||||
string uri = endpoint.BuildUrl();
|
||||
string? changesPage = await DownloadString(uri);
|
||||
if (!IgnoreErrors && changesPage is null)
|
||||
{
|
||||
@@ -1281,7 +1288,12 @@ namespace SabreTools.RedumpLib.Web
|
||||
// Edit disc
|
||||
if ((discSubpaths is null || Array.Exists(discSubpaths, s => s is DiscSubpath.Edit)) && discPage.Contains($"<a href=\"/disc/{id}/edit/\""))
|
||||
{
|
||||
string uri = UrlBuilder.BuildDiscUrl(id, DiscSubpath.Edit);
|
||||
var subEndpoint = new Endpoints.Disc
|
||||
{
|
||||
Id = id,
|
||||
Subpath = DiscSubpath.Edit,
|
||||
};
|
||||
string uri = endpoint.BuildUrl();
|
||||
string? editPage = await DownloadString(uri);
|
||||
if (!IgnoreErrors && editPage is null)
|
||||
{
|
||||
@@ -1301,7 +1313,12 @@ namespace SabreTools.RedumpLib.Web
|
||||
// CUE
|
||||
if ((discSubpaths is null || Array.Exists(discSubpaths, s => s is DiscSubpath.Cuesheet)) && discPage.Contains($"<a href=\"/disc/{id}/cue\""))
|
||||
{
|
||||
string uri = UrlBuilder.BuildDiscUrl(id, DiscSubpath.Cuesheet);
|
||||
var subEndpoint = new Endpoints.Disc
|
||||
{
|
||||
Id = id,
|
||||
Subpath = DiscSubpath.Cuesheet,
|
||||
};
|
||||
string uri = endpoint.BuildUrl();
|
||||
string? remoteName = await DownloadFile(uri, Path.Combine(paddedIdDir, $"{paddedId}.cue"));
|
||||
if (!IgnoreErrors && remoteName is null)
|
||||
{
|
||||
@@ -1313,7 +1330,12 @@ namespace SabreTools.RedumpLib.Web
|
||||
// SBI
|
||||
if ((discSubpaths is null || Array.Exists(discSubpaths, s => s is DiscSubpath.SBI)) && discPage.Contains($"<a href=\"/disc/{id}/sbi\""))
|
||||
{
|
||||
string uri = UrlBuilder.BuildDiscUrl(id, DiscSubpath.SBI);
|
||||
var subEndpoint = new Endpoints.Disc
|
||||
{
|
||||
Id = id,
|
||||
Subpath = DiscSubpath.SBI,
|
||||
};
|
||||
string uri = endpoint.BuildUrl();
|
||||
string? remoteName = await DownloadFile(uri, Path.Combine(paddedIdDir, $"{paddedId}.sbi"));
|
||||
if (!IgnoreErrors && remoteName is null)
|
||||
{
|
||||
|
||||
@@ -33,54 +33,6 @@ namespace SabreTools.RedumpLib.Web
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Build a /about/ path URL
|
||||
/// </summary>
|
||||
public static string BuildAboutUrl()
|
||||
{
|
||||
var ub = new UriBuilder
|
||||
{
|
||||
Scheme = "https",
|
||||
Host = "redump.info",
|
||||
Path = "about",
|
||||
};
|
||||
|
||||
return ub.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build a /disc/ path URL
|
||||
/// </summary>
|
||||
/// <param name="id">Disc ID, required</param>
|
||||
/// <param name="subpath">Disc page subpath, null to omit</param>
|
||||
/// TODO: Handle submit path?
|
||||
public static string BuildDiscUrl(int id, DiscSubpath? subpath = null)
|
||||
{
|
||||
var ub = new UriBuilder
|
||||
{
|
||||
Scheme = "https",
|
||||
Host = "redump.info",
|
||||
Path = $"disc/{Math.Abs(id)}",
|
||||
};
|
||||
|
||||
switch (subpath)
|
||||
{
|
||||
case DiscSubpath.Cuesheet:
|
||||
case DiscSubpath.Edit:
|
||||
case DiscSubpath.SBI:
|
||||
ub.Path += $"/{subpath.ShortName()}";
|
||||
break;
|
||||
|
||||
// History and null are invalid for a disc page
|
||||
case DiscSubpath.History:
|
||||
case null:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ub.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build a /downloads/ path URL
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user