76 lines
2.2 KiB
C#
76 lines
2.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Server.Data;
|
|
using Server.Data.Entities;
|
|
|
|
namespace VoidScavengers.Admin.Pages.Assets;
|
|
|
|
public class IndexModel : AdminPageModel
|
|
{
|
|
private readonly GameDbContext _db;
|
|
|
|
public IndexModel(GameDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
public List<ClientAsset> Assets { get; set; } = new();
|
|
public string? Search { get; set; }
|
|
public string? TypeFilter { get; set; }
|
|
public int Page { get; set; } = 1;
|
|
public int PageSize { get; set; } = 24;
|
|
public int TotalCount { get; set; }
|
|
public int AssetCount { get; set; }
|
|
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
|
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
|
|
|
public async Task OnGetAsync(string? search, string? type, int page = 1)
|
|
{
|
|
Search = search;
|
|
TypeFilter = type;
|
|
Page = Math.Max(1, page);
|
|
|
|
// Get CDN URL from environment
|
|
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
|
if (!string.IsNullOrEmpty(cdnUrl))
|
|
{
|
|
CdnBaseUrl = cdnUrl;
|
|
}
|
|
|
|
AssetCount = await _db.ClientAssets.CountAsync();
|
|
|
|
var query = _db.ClientAssets.AsQueryable();
|
|
|
|
if (!string.IsNullOrWhiteSpace(search))
|
|
{
|
|
query = query.Where(a => a.FilePath.Contains(search));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(type))
|
|
{
|
|
switch (type.ToLower())
|
|
{
|
|
case "sprite":
|
|
query = query.Where(a => a.AssetType == ClientAssetType.Texture);
|
|
break;
|
|
case "scene":
|
|
query = query.Where(a => a.AssetType == ClientAssetType.Scene);
|
|
break;
|
|
case "script":
|
|
query = query.Where(a => a.AssetType == ClientAssetType.Script);
|
|
break;
|
|
case "audio":
|
|
query = query.Where(a => a.AssetType == ClientAssetType.Audio);
|
|
break;
|
|
}
|
|
}
|
|
|
|
TotalCount = await query.CountAsync();
|
|
|
|
Assets = await query
|
|
.OrderBy(a => a.FilePath)
|
|
.Skip((Page - 1) * PageSize)
|
|
.Take(PageSize)
|
|
.ToListAsync();
|
|
}
|
|
}
|