mirror of
https://github.com/cxfksword/jellyfin-plugin-danmu.git
synced 2026-02-03 02:04:47 +08:00
fix: fix dandan unit test. #69
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,7 +1,9 @@
|
||||
bin/
|
||||
obj/
|
||||
.vs/
|
||||
.vscode/
|
||||
.idea/
|
||||
artifacts
|
||||
**/.DS_Store
|
||||
*.json
|
||||
**/.env
|
||||
@@ -18,5 +18,18 @@ namespace Jellyfin.Plugin.Danmu.Test
|
||||
options.SingleLine = true;
|
||||
options.TimestampFormat = "hh:mm:ss ";
|
||||
}));
|
||||
|
||||
[TestInitialize]
|
||||
public void SetUp()
|
||||
{
|
||||
DotNetEnv.Env.TraversePath().Load();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TearDown()
|
||||
{
|
||||
// 清理代码
|
||||
// 例如,释放资源或重置状态
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,16 +11,8 @@ namespace Jellyfin.Plugin.Danmu.Test
|
||||
{
|
||||
|
||||
[TestClass]
|
||||
public class DandanApiTest
|
||||
public class DandanApiTest : BaseTest
|
||||
{
|
||||
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
|
||||
builder.AddSimpleConsole(options =>
|
||||
{
|
||||
options.IncludeScopes = true;
|
||||
options.SingleLine = true;
|
||||
options.TimestampFormat = "hh:mm:ss ";
|
||||
}));
|
||||
|
||||
[TestMethod]
|
||||
public void TestSearch()
|
||||
{
|
||||
|
||||
@@ -17,18 +17,8 @@ namespace Jellyfin.Plugin.Danmu.Test
|
||||
{
|
||||
|
||||
[TestClass]
|
||||
public class DandanTest
|
||||
public class DandanTest : BaseTest
|
||||
{
|
||||
ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
|
||||
builder.AddSimpleConsole(options =>
|
||||
{
|
||||
options.IncludeScopes = true;
|
||||
options.SingleLine = true;
|
||||
options.TimestampFormat = "hh:mm:ss ";
|
||||
}));
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestAddMovie()
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNetEnv" Version="3.1.1" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.22.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="Moq" Version="4.18.2" />
|
||||
|
||||
@@ -31,6 +31,32 @@ public class DandanApi : AbstractApi
|
||||
}
|
||||
}
|
||||
|
||||
protected string ApiID {
|
||||
get
|
||||
{
|
||||
var apiId = Environment.GetEnvironmentVariable("DANDAN_API_ID");
|
||||
if (!string.IsNullOrEmpty(apiId))
|
||||
{
|
||||
return apiId;
|
||||
}
|
||||
|
||||
return API_ID;
|
||||
}
|
||||
}
|
||||
|
||||
protected string ApiSecret {
|
||||
get
|
||||
{
|
||||
var apiSecret = Environment.GetEnvironmentVariable("DANDAN_API_SECRET");
|
||||
if (!string.IsNullOrEmpty(apiSecret))
|
||||
{
|
||||
return apiSecret;
|
||||
}
|
||||
|
||||
return API_SECRET;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DandanApi"/> class.
|
||||
/// </summary>
|
||||
@@ -148,7 +174,7 @@ public class DandanApi : AbstractApi
|
||||
var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
|
||||
var signature = GenerateSignature(url, timestamp);
|
||||
|
||||
httpClient.DefaultRequestHeaders.Add("X-AppId", API_ID);
|
||||
httpClient.DefaultRequestHeaders.Add("X-AppId", ApiID);
|
||||
httpClient.DefaultRequestHeaders.Add("X-Signature", signature);
|
||||
httpClient.DefaultRequestHeaders.Add("X-Timestamp", timestamp.ToString());
|
||||
var response = await httpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
|
||||
@@ -158,13 +184,13 @@ public class DandanApi : AbstractApi
|
||||
|
||||
protected string GenerateSignature(string url, long timestamp)
|
||||
{
|
||||
if (string.IsNullOrEmpty(API_ID) || string.IsNullOrEmpty(API_SECRET))
|
||||
if (string.IsNullOrEmpty(ApiID) || string.IsNullOrEmpty(ApiSecret))
|
||||
{
|
||||
throw new Exception("弹弹接口缺少API_ID和API_SECRET");
|
||||
}
|
||||
var uri = new Uri(url);
|
||||
var path = uri.AbsolutePath;
|
||||
var str = $"{API_ID}{timestamp}{path}{API_SECRET}";
|
||||
var str = $"{ApiID}{timestamp}{path}{ApiSecret}";
|
||||
using (var sha256 = SHA256.Create())
|
||||
{
|
||||
var hashBytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
|
||||
Reference in New Issue
Block a user