Skip to content

Commit

Permalink
Merge pull request #796 from LittleFish-233/master
Browse files Browse the repository at this point in the history
修改周年庆页面样式,抽奖奖品主图默认转存图仓
  • Loading branch information
LittleFish-233 authored Jul 26, 2024
2 parents 91e9b32 + cde9b7b commit 48f37a1
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 69 deletions.
42 changes: 21 additions & 21 deletions CnGalWebSite/CnGalWebSite.DrawingBed/Services/FileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class FileService : IFileService
private readonly IUploadService _uploadService;
private readonly IRecordService _recordService;

public FileService(IHttpClientFactory httpClientFactory, IWebHostEnvironment webHostEnvironment, IConfiguration configuration, ILogger<FileService> logger ,IUploadService uploadService, IRecordService recordService)
public FileService(IHttpClientFactory httpClientFactory, IWebHostEnvironment webHostEnvironment, IConfiguration configuration, ILogger<FileService> logger, IUploadService uploadService, IRecordService recordService)
{
_httpClientFactory = httpClientFactory;
_webHostEnvironment = webHostEnvironment;
Expand All @@ -44,7 +44,7 @@ public FileService(IHttpClientFactory httpClientFactory, IWebHostEnvironment web
Directory.CreateDirectory(_audioTempPath);
}

public async Task<UploadResult> TransferDepositFile(string url,bool gallery , double x = 0, double y = 0, UploadFileType type = UploadFileType.Image )
public async Task<UploadResult> TransferDepositFile(string url, bool gallery, double x = 0, double y = 0, UploadFileType type = UploadFileType.Image)
{
string pathSaveFile = null;
string pathCutFile = null;
Expand Down Expand Up @@ -109,7 +109,7 @@ public async Task<UploadResult> TransferDepositFile(string url,bool gallery , do
}
}

public async Task<UploadResult> UploadFormFile(IFormFile file,bool gallery, double x = 0, double y = 0,UploadFileType type = UploadFileType.Image )
public async Task<UploadResult> UploadFormFile(IFormFile file, bool gallery, double x = 0, double y = 0, UploadFileType type = UploadFileType.Image)
{
string pathSaveFile = null;
string pathCompressFile = null;
Expand All @@ -118,7 +118,7 @@ public async Task<UploadResult> UploadFormFile(IFormFile file,bool gallery, dou
try
{

pathSaveFile =await SaveFormFile(file, type);
pathSaveFile = await SaveFormFile(file, type);

if (type == UploadFileType.Image)
{
Expand Down Expand Up @@ -146,7 +146,7 @@ public async Task<UploadResult> UploadFormFile(IFormFile file,bool gallery, dou

if (string.IsNullOrWhiteSpace(model.Url))
{
model.Url = await UploadLocalFileToServer(pathCompressFile, sha1, type,gallery);
model.Url = await UploadLocalFileToServer(pathCompressFile, sha1, type, gallery);
//添加文件上传记录
await _recordService.Add(model);
}
Expand All @@ -169,18 +169,18 @@ public async Task<UploadResult> UploadFormFile(IFormFile file,bool gallery, dou


#region 上传文件
private async Task<string> UploadLocalFileToServer(string filePath,string shar1, UploadFileType type, bool gallery)
private async Task<string> UploadLocalFileToServer(string filePath, string shar1, UploadFileType type, bool gallery)
{
var url= type switch
var url = type switch
{
UploadFileType.Audio => await _uploadService.UploadToAliyunOSS(filePath, shar1),
UploadFileType.Image =>await _uploadService.UploadToTencentOSS(filePath, shar1),
UploadFileType.Image => await _uploadService.UploadToTencentOSS(filePath, shar1),
_ => null
};

if(gallery&&type== UploadFileType.Image)
if (gallery && type == UploadFileType.Image)
{
url = await _uploadService.UploadToTucangCC(filePath)+"?"+ url;
url = await _uploadService.UploadToTucangCC(filePath) + "?" + url;
}

return url;
Expand All @@ -207,7 +207,7 @@ private async Task<string> SaveFormFile(IFormFile file, UploadFileType type)
using var steam = file.OpenReadStream();
await SaveFile(steam, newPath);

_logger.LogInformation("保存客户端传输的文件:{file}" ,file.FileName);
_logger.LogInformation("保存客户端传输的文件:{file}", file.FileName);

return newPath;
}
Expand All @@ -220,14 +220,14 @@ public async Task<string> SaveFileFromUrl(string url, UploadFileType type)
}

var response = await _httpClientFactory.CreateClient().GetAsync(url);
using var stream =await response.Content.ReadAsStreamAsync();
var tempName =new Random().Next() + "." + GetFileSuffixName(url,type);
using var stream = await response.Content.ReadAsStreamAsync();
var tempName = new Random().Next() + "." + GetFileSuffixName(url, type);

//保存图片到本地
var newPath = Path.Combine(type switch { UploadFileType.Image => _imageTempPath, UploadFileType.Audio => _audioTempPath, _ => _fileTempPath }, tempName);
await SaveFile(stream, newPath);

_logger.LogInformation( "下载远程链接里的文件:{file}" ,url);
_logger.LogInformation("下载远程链接里的文件:{file}", url);

return newPath;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ private string GetSHA1(string path)

private static async Task SaveFile(Stream file, string destinationPath)
{
using var fs = File.Create(destinationPath);
using var fs = File.Create(destinationPath);
await file.CopyToAsync(fs);
file.Close();
fs.Close();
Expand All @@ -276,7 +276,7 @@ private static async Task SaveFile(Stream file, string destinationPath)
/// <param name="y"></param>
private async Task<CutFileResult> CutAudioAsync(string path)
{
if( File.Exists(path)==false)
if (File.Exists(path) == false)
{
throw new Exception($"裁剪音频失败,文件不存在:{path}");
}
Expand All @@ -292,14 +292,14 @@ private async Task<CutFileResult> CutAudioAsync(string path)

var output = await ffmpeg.ConvertAsync(inputFile, outputFile, options, default);

var mediaFile = new MediaInfoWrapper(outputFile.FileInfo.FullName,_logger);
var mediaFile = new MediaInfoWrapper(outputFile.FileInfo.FullName, _logger);

_logger.LogInformation("成功裁剪音频:{url}", output.FileInfo.FullName);

return new CutFileResult
{
FileURL = output.FileInfo.FullName,
Duration = new TimeSpan(0,0,0,0,mediaFile.Duration)
Duration = new TimeSpan(0, 0, 0, 0, mediaFile.Duration)
};

}
Expand All @@ -326,7 +326,7 @@ public string CompressImage(string path)
/// <param name="proportion"></param>
private string GetPicThumbnail(string path, double proportion)
{
var newPath = Path.Combine(_imageTempPath, Guid.NewGuid().ToString() + "." + GetFileSuffixName(path, UploadFileType.Image));
var newPath = Path.Combine(_imageTempPath, Guid.NewGuid().ToString() + "." + GetFileSuffixName(path, UploadFileType.Image));
using (var image = Image.Load(path))
{
image.Mutate(x => x
Expand Down Expand Up @@ -362,7 +362,7 @@ private string CutImage(string path, double x = 0, double y = 0)

image.Mutate(x => x
//.Resize(linshi_x, linshi_y)
.Crop(new Rectangle((image.Width- linshi_x)/2, (image.Height - linshi_y) / 2, linshi_x, linshi_y)));
.Crop(new Rectangle((image.Width - linshi_x) / 2, (image.Height - linshi_y) / 2, linshi_x, linshi_y)));
image.Save(newPath);
return newPath;

Expand Down Expand Up @@ -423,7 +423,7 @@ public void DeleteFile(string path)
{
File.Delete(path);
}
catch(Exception ex)
catch (Exception ex)
{
_logger.LogError(ex, "删除文件失败:{url}", path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@
}
else
{
@if (string.IsNullOrWhiteSpace(GameName) == false)
{
<div class="label-large mt-4">
@($"《{GameName}》")
<div>
@if (string.IsNullOrWhiteSpace(GameName) == false)
{
<div class="label-large mt-2" style="color:gray">
@($"《{GameName}》")
</div>
}
<div class="label-large mt-2" style="color:gray">
@Model.LastEditTime.ToString("yyyy-MM-dd HH:mm:ss")
</div>
}
<div class="label-large mt-4">
@Model.LastEditTime.ToString("yyyy-MM-dd HH:mm:ss")
</div>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@

@if (string.IsNullOrWhiteSpace(gameName) == false)
{
<MCardText Class="pb-2">
<MCardText Class="pb-2 pt-0" Style="color:gray">
@($"《{gameName}》")
</MCardText>
}
<MCardText Class="@(gameId!=0?"pb-0":"")">
<MCardText Class="@(gameId!=0?"pb-0 pt-0":"pt-0")" Style="color:gray">
@Model.LastEditTime.ToString("yyyy-MM-dd HH:mm:ss")
</MCardText>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,53 @@


<CnGalWebSite.Components.Containers.MiniModeContainer>
@if (Anniversaries)
{
<CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert Icon="@IconType.GameRecord.ToIconString()" Type="AlertTypes.Success" Class="mb-4" Color="tertiary">
绑定游戏库后,选择一款游戏留下你的游玩记录吧
</CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert>
}

@if (OverviewModel != null)
{
<div class="row">
<div class="col-12 col-md-6">
<HasMostGamesUsersCard Model="OverviewModel.HasMostGamesUsers" />
</div>
<div class="col-12 col-md-6">
<PossessionRateHighestGamesCard Model="OverviewModel.PossessionRateHighestGames" />
@if (!Anniversaries)
{
<div class="row">
<div class="col-12 col-md-6">
<HasMostGamesUsersCard Model="OverviewModel.HasMostGamesUsers" />
</div>
<div class="col-12 col-md-6">
<PossessionRateHighestGamesCard Model="OverviewModel.PossessionRateHighestGames" />
</div>
</div>
</div>
}
<AuthorizeView>
<Authorized>
@if (Model != null)
{
<div id="game-library-card">
<CnGalWebSite.Shared.MasaComponent.PC.Users.UserPlayedGameListView IsCurrentUser="true" SteamId="@Model.SteamId" UserId="@Model.Id" IsAnniversary TotalCount="OverviewModel.Count" UserInfoModel="Model" />
</div>
</div>
}
</Authorized>
<NotAuthorized>
<MDCard Style="display: flex; justify-content: center;align-items: center;" Class="pa-3 mb-4">
<CnGalWebSite.Components.Buttons.MasaButton Rounded Text="登入后分享游戏库" OnClick="_userService.Login" Icon="@IconType.Login.ToIconString()" />
</MDCard>
</NotAuthorized>
</AuthorizeView>
</MDCard>
</NotAuthorized>
</AuthorizeView>
}
else
{
<CnGalWebSite.Components.Progressings.ProgressingCard Page Fill Class="mb-4" />
}

@if (Anniversaries)
{
<CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.Ratings.RandomUserScoreGroup />
}

@if (isReady)
@if (isReady && !Anniversaries)
{
<CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert Type="AlertTypes.Success" Class="mb-4" Color="tertiary">
晒出的你的游戏库吧
Expand All @@ -48,6 +62,8 @@


@code {
[Parameter]
public bool Anniversaries { get; set; }

public PersonalSpaceViewModel Model { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
@inject NavigationManager NavigationManager
@inject IDataCacheService _dataCacheService

<CnGalWebSite.Components.Containers.MasaTitleContainer Title="随机评价" Icon="fa fa-fw fa-random" Class="mb-4" Outline>
<CnGalWebSite.Components.Containers.MasaTitleContainer Title="随机评价" Icon="@IconType.GameRecord.ToIconString()" Class="mb-4" Outline>

<ButtonContent>
<MButton Text Block Color="primary" OnClick="OnClickMore">
<MButton Rounded OnClick="OnClickMore" Color="primary">
<MIcon Left>mdi-refresh </MIcon>
换一批
</MButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
}

<MCardText>
<CnGalWebSite.Components.Containers.MasaTitleContainer Icon="fa fa-fw fa fa-fw fa-home" Title="主要信息" Class="mb-4" Collapable Outline OutlineHead>
<CnGalWebSite.Components.Containers.MasaTitleContainer Icon="@IconType.Home.ToIconString()" Title="主要信息" Class="mb-4" Collapable Outline OutlineHead>
<MRow>
<MCol Cols="12" Md="6">
<CnGalWebSite.Components.Images.UploadButton @bind-ImagePath="@Model.Image" Type="ImageAspectType.None" ShowCropper Text="上传预览图" Class="mb-4"/>
<CnGalWebSite.Components.Images.UploadButton @bind-ImagePath="@Model.Image" Type="ImageAspectType.None" ShowCropper Text="上传预览图" Class="mb-4" Gallery/>
</MCol>
<MCol Cols="12"></MCol>
<MCol Cols="12" Md="6">
Expand All @@ -45,7 +45,7 @@
</MCol>
</MRow>
</CnGalWebSite.Components.Containers.MasaTitleContainer>
<CnGalWebSite.Components.Containers.MasaTitleContainer Icon="fa fa-fw fa-info-circle" Title="基本信息" Class="mb-4" Collapable Outline OutlineHead>
<CnGalWebSite.Components.Containers.MasaTitleContainer Icon="@IconType.Infor.ToIconString()" Title="基本信息" Class="mb-4" Collapable Outline OutlineHead>
<MRow>

<MCol Cols="12" Md="6">
Expand All @@ -72,9 +72,9 @@



<MCardActions Class="pb-6 pe-6 ps-6 pt-6">
<MCardActions Class="pb-6 pe-6 ps-6 pt-0">
<MSpacer />
<CnGalWebSite.Components.Buttons.MasaButton Text="保存" IsAsync="true" OnClick="OnSave" Icon="mdi-check" Color="success" Rounded />
<CnGalWebSite.Components.Buttons.MasaButton Text="保存" IsAsync="true" OnClick="OnSave" Icon="@IconType.Save.ToIconString()" Rounded />
</MCardActions>
</MDCard>
</MDialog>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@inject IDataCacheService _dataCacheService
@inject NavigationManager NavigationManager
@inject IEventService _eventService

<CnGalWebSite.Components.Containers.MasaTitleContainer Title="基本信息" Icon="@IconType.Infor.ToIconString()" Collapable Class="@Class">
<MRow>
Expand All @@ -13,11 +12,6 @@
<MCol Cols="12">
<MTextField @bind-Value="Model.PersonalSignature" Label="个性签名" />
</MCol>
<MCol Cols="12">
<CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert Type="AlertTypes.Info" Class="mt-2 mb-2" Color="primary">
点击查看<a @onclick="OnClickQuestion" class="primary--text fw-bold">如何获取SteamId</a> ,Steam个人资料隐私设置<strong>【游戏详情】</strong>需要选择<strong>【公开】</strong>哦
</CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaAlert>
</MCol>
<MCol Cols="12" Md="6">
<MCheckbox @bind-Value="Model.CanComment" Label="允许游客留言" />
</MCol>
Expand All @@ -43,9 +37,5 @@
[Parameter]
public string Class { get; set; }

public void OnClickQuestion()
{
_eventService.OpenNewPage(NavigationManager.BaseUri + "articles/index/5");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<CnGalWebSite.Shared.Pages.Webs.Lotteries.Index Id="22" />
</MTabItem>
<MTabItem Value="3">
<CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.PlayedGames.MainCard />
<CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.PlayedGames.MainCard Anniversaries/>
</MTabItem>
<MTabItem Value="4">
<CnGalWebSite.Shared.MasaComponent.PC.Home.Anniversaries.Home.IntroductionCard />
Expand Down Expand Up @@ -80,10 +80,10 @@
index = Type switch
{
"Home" => 1,
"Rating" => 2,
"Rating" => 5,
"PlayedGames" => 3,
"Lottery" => 4,
"Introduction" => 5,
"Lottery" => 2,
"Introduction" => 4,
_=>1
};
StateHasChanged();
Expand Down Expand Up @@ -111,10 +111,10 @@
NavigationManager.NavigateTo($"/{baseStr}/" + (index.ToInt32() switch
{
1 => "Home",
2 => "Rating",
5 => "Rating",
3 => "PlayedGames",
4 => "Lottery",
5 => "Introduction",
2 => "Lottery",
4 => "Introduction",
_ => ""
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,4 @@
StateHasChanged();

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


/*分享库存*/
.anniversary-page .user-steam-card {
gap: .5rem;
Expand Down
Loading

0 comments on commit 48f37a1

Please sign in to comment.