Skip to content

Commit

Permalink
调整,加入新接口,为clone增加子目录
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyhhssyy committed Jun 3, 2024
1 parent 5ad0c04 commit e3c232f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 30 deletions.
26 changes: 0 additions & 26 deletions AmiyaBotPlayerRatingServer/Controllers/Game/GameHubController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,6 @@ public class GameHubController(
GameManager gameManager)
: ControllerBase
{
#pragma warning disable CS8618
// ReSharper disable UnusedAutoPropertyAccessor.Global
public class SendNotificationModel
{
public string Message { get; set; }
public DateTime ExpiredAt { get; set; }
}
// ReSharper restore UnusedAutoPropertyAccessor.Global
#pragma warning restore CS8618

[Authorize(Roles = "管理员账户")]
[HttpPost("sendNotificationToAll")]
public async Task<IActionResult> SendNotificationToAll([FromBody] SendNotificationModel model)
{
var not = new SystemNotification
{
Id = Guid.NewGuid(),
Message = model.Message,
ExpiredAt = model.ExpiredAt
};

dbContext.SystemNotifications.Add(not);
await dbContext.SaveChangesAsync();

return Ok();
}

private object GetGameReturnObj(GameLogic.Game game)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using AmiyaBotPlayerRatingServer.Data;
using AmiyaBotPlayerRatingServer.GameLogic;
using AmiyaBotPlayerRatingServer.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace AmiyaBotPlayerRatingServer.Controllers.Game
{
[ApiController]
[Route("api/gameHub")]
public class GameServerController(
PlayerRatingDatabaseContext dbContext,
IConfiguration configuration,

Check warning on line 14 in AmiyaBotPlayerRatingServer/Controllers/Game/GameServerController.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'configuration' is unread.
ArknightsMemoryCache memoryCache)
: ControllerBase
{
#pragma warning disable CS8618
// ReSharper disable UnusedAutoPropertyAccessor.Global
public class SendNotificationModel
{
public string Message { get; set; }
public DateTime ExpiredAt { get; set; }
}
// ReSharper restore UnusedAutoPropertyAccessor.Global
#pragma warning restore CS8618

[AllowAnonymous]
[HttpGet("serverStatistics")]
public async Task<IActionResult> GetServerStatistics()
{
var totalPlaying = await dbContext.GameInfos.Where(c => c.IsClosed != true).CountAsync();
var totalGames = await dbContext.GameInfos.CountAsync();
var validPlayers = await dbContext.ApplicationUserMinigameStatistics.CountAsync();

return Ok(new
{
GamesPlaying = totalPlaying,
GamesTotal = totalGames,
PlayersTotal = validPlayers
});
}

[Authorize(Roles = "管理员账户")]
[HttpPost("sendNotificationToAll")]
public async Task<IActionResult> SendNotificationToAll([FromBody] SendNotificationModel model)
{
var not = new SystemNotification
{
Id = Guid.NewGuid(),
Message = model.Message,
ExpiredAt = model.ExpiredAt
};

dbContext.SystemNotifications.Add(not);
await dbContext.SaveChangesAsync();

return Ok();
}

[Authorize(Roles = "管理员账户")]
[HttpPost("refreshArknightsData")]
public async Task<IActionResult> RefreshArknightsData()

Check warning on line 63 in AmiyaBotPlayerRatingServer/Controllers/Game/GameServerController.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{

try
{
memoryCache.UpdateAssets();
}
catch(Exception e)
{
return BadRequest(e.Message);
}

return Ok();
}
}
}
7 changes: 3 additions & 4 deletions AmiyaBotPlayerRatingServer/Data/ArknightsMemoryCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace AmiyaBotPlayerRatingServer.Data
public class ArknightsMemoryCache
{
// abs path is /app/Resources
private readonly string _directoryPath = "Resources/amiya-bot-assets";
private readonly string _directoryPath = "Resources/amiya-bot-assets/repo";
private readonly string _gitRepoUrl = "https://gitee.com/amiya-bot/amiya-bot-assets.git";
private readonly string _zipFilePath = "Resources/amiya-bot-assets/gamedata.zip";
private readonly string _extractPath = "Resources/amiya-bot-assets/gamedata";
private readonly string _zipFilePath = "Resources/amiya-bot-assets/repo/gamedata.zip";
private readonly string _extractPath = "Resources/amiya-bot-assets/repo/gamedata";


public class ArknightsOperator
Expand Down Expand Up @@ -112,7 +112,6 @@ private void InitializeAssets()

if (!Directory.Exists(_directoryPath))
{
//因为目标文件夹是NFSMount,因此不会有需要创建的情况,但是还是留着.
Directory.CreateDirectory(_directoryPath);
CloneRepo();
ExtractGameData();
Expand Down

0 comments on commit e3c232f

Please sign in to comment.