Skip to content

Commit

Permalink
fix: Maybe fix problems with fetching file processing info
Browse files Browse the repository at this point in the history
  • Loading branch information
itssimple committed Jan 9, 2024
1 parent 66d91f1 commit 19a3bb2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
77 changes: 70 additions & 7 deletions CFLookup/Pages/FileProcessingInfo.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,75 @@
<tbody>
@foreach (var row in Model.ModFiles)
{
<tr>
<td scope="row"><a href="https://www.curseforge.com/@row.Game.Slug" target="_blank">@row.Game.Name</a></td>
<td><a href="@row.Mod.Links.WebsiteUrl" target="_blank">@row.Mod.Name</a></td>
<td><a href="@row.Mod.Links.WebsiteUrl/files/@row.File.Id" target="_blank">@row.File.FileName</a></td>
<td class="text-end" title="@row.LatestUpdatedUtc">@row.SinceLatestUpdate.ToHumanReadableFormat(true) ago</td>
</tr>
}
try
{
<tr>
<td scope="row"><a href="https://www.curseforge.com/@row.Game.Slug" target="_blank">@row.Game.Name</a></td>
<td>
@if (row.Mod != null)
{
<a href="@row.Mod.Links.WebsiteUrl" target="_blank">@row.Mod.Name</a>
}
else
{
<text>ProjectId:</text>
@row.FileProcessingInfo.ModId
}
</td>
<td>
@if (row.Mod != null)
{
<a href="@row.Mod.Links.WebsiteUrl/files/@row.File.Id" target="_blank">@row.File.FileName</a>
}
else if (row.File != null)
{
@row.File.FileName
}
else
{
<text>FileId:</text>
@row.FileProcessingInfo.FileId
}
</td>
<td class="text-end" title="@row.LatestUpdatedUtc">@row.SinceLatestUpdate.ToHumanReadableFormat(true) ago</td>
</tr>
} catch (Exception ex)
{
<tr>
<td scope="row"><a href="https://www.curseforge.com/@row.Game.Slug" target="_blank">@row.Game.Name</a></td>
<td>
@if (row.Mod != null)
{
<a href="@row.Mod.Links.WebsiteUrl" target="_blank">@row.Mod.Name</a>
}
else
{
<text>ProjectId:</text>
@row.FileProcessingInfo.ModId
}
</td>
<td>
@if (row.Mod != null)
{
<a href="@row.Mod.Links.WebsiteUrl/files/@row.File.Id" target="_blank">@row.File.FileName</a>
}
else if (row.File != null)
{
@row.File.FileName
}
else
{
<text>FileId:</text>
@row.FileProcessingInfo.FileId
}
</td>
<td class="text-end" title="@row.LatestUpdatedUtc">@row.SinceLatestUpdate.ToHumanReadableFormat(true) ago</td>
</tr>
<!-- Exception: @ex.ToString() -->
<!-- GameId: @row.FileProcessingInfo.GameId -->
<!-- ModId: @row.FileProcessingInfo.ModId -->
<!-- FileId: @row.FileProcessingInfo.FileId -->
}
}
</tbody>
</table>
13 changes: 8 additions & 5 deletions CFLookup/Pages/FileProcessingInfo.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public async Task<IActionResult> OnGetAsync()
await _redis.StringSetAsync($"cf-game-{info.GameId}", JsonSerializer.Serialize(game), TimeSpan.FromDays(1));
}

Mod mod;
Mod? mod;
var modCache = await _redis.StringGetAsync($"cf-mod-{info.ModId}");
if (!modCache.IsNullOrEmpty)
{
mod = JsonSerializer.Deserialize<Mod>(modCache)!;
mod = JsonSerializer.Deserialize<Mod?>(modCache)!;
}
else
{
mod = (await _cfApiClient.GetModAsync(info.ModId)).Data;
mod = (await _cfApiClient.GetModAsync(info.ModId))?.Data;
await _redis.StringSetAsync($"cf-mod-{info.ModId}", JsonSerializer.Serialize(mod), TimeSpan.FromDays(1));
}

Expand All @@ -71,7 +71,8 @@ public async Task<IActionResult> OnGetAsync()
Game = game,
Mod = mod,
File = file,
LatestUpdatedUtc = info.Last_Updated_UTC
LatestUpdatedUtc = info.Last_Updated_UTC,
FileProcessingInfo = info
};

ModFiles.Add(gameModFileProcessingInfo);
Expand All @@ -84,9 +85,11 @@ public async Task<IActionResult> OnGetAsync()
public class GameModFileProcessingInfo
{
public Game Game { get; set; }
public Mod Mod { get; set; }
public Mod? Mod { get; set; }
public CurseForge.APIClient.Models.Files.File File { get; set; }
public DateTimeOffset LatestUpdatedUtc { get; set; }
public TimeSpan SinceLatestUpdate => DateTimeOffset.UtcNow - LatestUpdatedUtc;

public FileProcessingStatus FileProcessingInfo { get; internal set; }
}
}

0 comments on commit 19a3bb2

Please sign in to comment.