1
0
mirror of synced 2024-11-23 22:41:01 +01:00

Implemented qrCodeData related functions

This commit is contained in:
S-Sebb?? 2023-09-18 03:15:04 +08:00
parent 7dd43d2617
commit 46fe93d806
8 changed files with 58 additions and 3 deletions

View File

@ -0,0 +1,10 @@
using System.Text.Json.Serialization;
namespace SharedProject.Models;
public class QRCodeData
{
[JsonPropertyName("serial")] public string Serial { get; set; } = null!;
[JsonPropertyName("id")] public uint Id { get; set; }
}

View File

@ -46,6 +46,7 @@ public class GetDanOdaiController : BaseController<GetDanOdaiController>
Logger.LogWarning("Requested dan id {Id} does not exist!", danId);
continue;
}
Logger.LogInformation(odaiData.Stringify());
response.AryOdaiDatas.Add(odaiData);
}

View File

@ -4,16 +4,32 @@
[ApiController]
public class VerifyQrCodeController : BaseController<VerifyQrCodeController>
{
private readonly IGameDataService gameDataService;
public VerifyQrCodeController(IGameDataService gameDataService)
{
this.gameDataService = gameDataService;
}
[HttpPost]
[Produces("application/protobuf")]
public IActionResult VerifyQrCode([FromBody] VerifyQrcodeRequest request)
{
Logger.LogInformation("VerifyQrCode request : {Request}", request.Stringify());
var qrCodeDataDictionary = gameDataService.GetQRCodeDataDictionary();
qrCodeDataDictionary.TryGetValue(request.QrcodeSerial, out var qrCodeId);
if (qrCodeId == 0)
{
Logger.LogWarning("Requested QR code serial {Serial} does not exist!", request.QrcodeSerial);
}
var response = new VerifyQrcodeResponse
{
Result = 1,
QrcodeId = 999999001
QrcodeId = qrCodeId
};
return Ok(response);

View File

@ -36,6 +36,8 @@ public class GameDataService : IGameDataService
private ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData> shopFolderDictionary =
ImmutableDictionary<uint, GetShopFolderResponse.ShopFolderData>.Empty;
private ImmutableDictionary<string, uint> qrCodeDataDictionary = ImmutableDictionary<string, uint>.Empty;
private List<uint> musics = new();
private List<uint> musicsWithUra = new();
@ -111,6 +113,11 @@ public class GameDataService : IGameDataService
return lockedSongsList;
}
public ImmutableDictionary<string, uint> GetQRCodeDataDictionary()
{
return qrCodeDataDictionary;
}
public async Task InitializeAsync()
{
var dataPath = PathHelper.GetDataPath();
@ -126,6 +133,7 @@ public class GameDataService : IGameDataService
var shopFolderDataPath = Path.Combine(dataPath, settings.ShopFolderDataFileName);
var tokenDataPath = Path.Combine(dataPath, settings.TokenDataFileName);
var lockedSongsDataPath = Path.Combine(dataPath, settings.LockedSongsDataFileName);
var qrCodeDataPath = Path.Combine(dataPath, settings.QRCodeDataFileName);
if (File.Exists(compressedMusicInfoPath))
{
@ -145,6 +153,7 @@ public class GameDataService : IGameDataService
await using var shopFolderDataFile = File.OpenRead(shopFolderDataPath);
await using var tokenDataFile = File.OpenRead(tokenDataPath);
await using var lockedSongsDataFile = File.OpenRead(lockedSongsDataPath);
await using var qrCodeDataFile = File.OpenRead(qrCodeDataPath);
var infoesData = await JsonSerializer.DeserializeAsync<MusicInfoes>(musicInfoFile);
var attributesData = await JsonSerializer.DeserializeAsync<MusicAttributes>(musicAttributeFile);
@ -156,6 +165,7 @@ public class GameDataService : IGameDataService
var shopFolderData = await JsonSerializer.DeserializeAsync<List<ShopFolderData>>(shopFolderDataFile);
var tokenData = await JsonSerializer.DeserializeAsync<Dictionary<string, int>>(tokenDataFile);
var lockedSongsData = await JsonSerializer.DeserializeAsync<Dictionary<string, uint[]>>(lockedSongsDataFile);
var qrCodeData = await JsonSerializer.DeserializeAsync<List<QRCodeData>>(qrCodeDataFile);
InitializeMusicInfoes(infoesData);
@ -176,6 +186,8 @@ public class GameDataService : IGameDataService
InitializeTokenData(tokenData);
InitializeLockedSongsData(lockedSongsData);
InitializeQRCodeData(qrCodeData);
}
private static void TryDecompressMusicInfo()
@ -273,6 +285,12 @@ public class GameDataService : IGameDataService
lockedSongsList = lockedSongsData["songNo"].ToList();
}
private void InitializeQRCodeData(List<QRCodeData>? qrCodeData)
{
qrCodeData.ThrowIfNull("Shouldn't happen!");
qrCodeDataDictionary = qrCodeData.ToImmutableDictionary(data => data.Serial, data => data.Id);
}
private static GetDanOdaiResponse.OdaiData ToResponseOdaiData(DanData data)
{
var responseOdaiData = new GetDanOdaiResponse.OdaiData

View File

@ -29,5 +29,7 @@ public interface IGameDataService
public Dictionary<string, int> GetTokenDataDictionary();
public List<uint> GetLockedSongsList();
public ImmutableDictionary<string, uint> GetQRCodeDataDictionary();
}

View File

@ -17,4 +17,6 @@ public class DataSettings
public string TokenDataFileName { get; set; } = "token_data.json";
public string LockedSongsDataFileName { get; set; } = "locked_songs_data.json";
public string QRCodeDataFileName { get; set; } = "qrcode_data.json";
}

View File

@ -0,0 +1,6 @@
[
{
"serial": "",
"id": -1
}
]