单个rom 信息查询 webapi

This commit is contained in:
sin365 2024-09-18 12:54:13 +08:00
parent 68f19925d6
commit 68f121df60
3 changed files with 109 additions and 30 deletions

View File

@ -34,6 +34,27 @@ namespace AxibugEmuOnline.Client
callback.Invoke(resp);
}
private IEnumerator GetNesRomInfo(int RomID, Action<Resp_RomInfo> callback)
{
UnityWebRequest request = UnityWebRequest.Get($"{WebSiteApi}/RomInfo?PType={PlatformType.Nes}&RomID={RomID}");
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
callback.Invoke(null);
yield break;
}
var resp = JsonUtility.FromJson<Resp_RomInfo>(request.downloadHandler.text);
callback.Invoke(resp);
}
enum PlatformType : byte
{
All = 0,
Nes = 1,
}
enum GameType : byte
{
NONE = 0,

View File

@ -28,7 +28,7 @@ namespace AxibugEmuOnline.Web.Controllers
}
[HttpGet]
public JsonResult NesRomList(string SearchKey,int Ptype,int GType,int Page, int PageSize)
public JsonResult NesRomList(string SearchKey, int Ptype, int GType, int Page, int PageSize)
{
string searchPattern = $"%{SearchKey}%";
Resp_GameList resp = new Resp_GameList();
@ -103,6 +103,40 @@ namespace AxibugEmuOnline.Web.Controllers
return new JsonResult(resp);
}
[HttpGet]
public JsonResult RomInfo(int Ptype, int RomID)
{
string searchPattern = $"%{RomInfo}%";
Resp_RomInfo resp = new Resp_RomInfo();
MySqlConnection conn = Haoyue_SQLPoolManager.DequeueSQLConn("NesRomList");
{
string query = $"SELECT id,`Name`,GameType,Note,RomUrl,ImgUrl,`Hash` FROM romlist_nes where id = ?romid;";
using (var command = new MySqlCommand(query, conn))
{
// 设置参数值
command.Parameters.AddWithValue("?romid", RomID);
// 执行查询并处理结果
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
resp.id = reader.GetInt32(0);
resp.romName = !reader.IsDBNull(1) ? reader.GetString(1) : string.Empty;
resp.gType = !reader.IsDBNull(2) ? reader.GetString(2) : string.Empty;
resp.desc = !reader.IsDBNull(3) ? reader.GetString(3) : string.Empty;
resp.url = !reader.IsDBNull(4) ? reader.GetString(4) : string.Empty;
resp.imgUrl = !reader.IsDBNull(5) ? reader.GetString(5) : string.Empty;
resp.hash = !reader.IsDBNull(6) ? reader.GetString(6) : string.Empty;
resp.stars = 0;
}
}
}
Haoyue_SQLPoolManager.EnqueueSQLConn(conn);
}
return new JsonResult(resp);
}
enum PlatformType : byte
{
All = 0,
@ -153,7 +187,7 @@ namespace AxibugEmuOnline.Web.Controllers
{
public int orderid { get; set; }
public int id { get; set; }
public string romName { get; set;}
public string romName { get; set; }
public string gType { get; set; }
public string desc { get; set; }
public string url { get; set; }

View File

@ -2,6 +2,24 @@
这里说明WebApi类的接口
### 基本通用参数
```
platform 模拟器所在平台
[0] 通用
[1] PC
PType Rom所属平台
enum PlatformType : byte
{
All = 0,
Nes = 1,
}
```
### 基本信息检查
```
@ -120,33 +138,7 @@ Response:
序列化C#实体类示例
```
enum PlatformType : byte
{
All = 0,
Nes,
}
enum GameType : byte
{
NONE = 0,
ACT,
ARPG,
AVG,
ETC,
FTG,
PUZ,
RAC,
RPG,
SLG,
SPG,
SRPG,
STG,
TAB,
/// <summary>
/// 合卡
/// </summary>
ALLINONE,
}
class Resp_GameList
{
@ -168,4 +160,36 @@ Response:
public string hash { get; set; }
public int stars { get; set; }
}
```
```
### 单个Rom游戏详情
```
{WebHost}/api/RomInfo?PType=<平台枚举int>&RomID=<RomID>
```
Request:
```
http://emu.axibug.com/api/RomInfo?PType=1&RomID=5
```
Response:
```
{
"orderid": 0,//单个查询就没有排序id了
"id": 5,
"romName": "1999强手棋",
"gType": "TAB",
"desc": "以世纪末地球危机为题材的桌棋冒险节目。游戏者要存储宇宙能量帮助地球摆脱各方面危机最多可4人同时进行",
"url": "roms/fcrom/1999%20-%20Hore,%20Mitakotoka!%20Seikimatsu%20(J).zip",
"imgUrl": "images/fcrom/1999%20-%20Hore,%20Mitakotoka!%20Seikimatsu%20(J).JPG",
"hash": "",
"stars": 0
}
```
序列化Class 参照如上 Resp_RomInfo