diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Entries/EntryService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Entries/EntryService.cs index d25cb00dc7..6ea215d448 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Entries/EntryService.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Entries/EntryService.cs @@ -25,6 +25,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; using System.Linq.Dynamic.Core; @@ -37,7 +38,7 @@ namespace CnGalWebSite.APIServer.Application.Entries { - public class EntryService : IEntryService + public partial class EntryService : IEntryService { private readonly IRepository _entryRepository; private readonly IRepository _articleRepository; @@ -1212,14 +1213,21 @@ public async Task GetEntryIndexViewModelAsync(Entry entry, var info = informationTypes.FirstOrDefault(s => s.Name == item.DisplayName); if (info != null) { - model.Information.Add(new EntryInformationModel + var temp = new EntryInformationModel { Icon = info.Icon, Name = item.DisplayName, Value = item.DisplayValue - }); + }; + if(temp.Name== "QQ群") + { + temp.Value = QQGroupRegex().Replace(temp.Value, "$1"); + } + model.Information.Add(temp); } } + + // 添加Staff var relstionsAndStaffs = new List(); relstionsAndStaffs.AddRange(entry.EntryRelationFromEntryNavigation.Select(s => s.ToEntryNavigation)); relstionsAndStaffs.AddRange(entry.EntryStaffFromEntryNavigation.Where(s => s.ToEntryNavigation != null).Select(s => s.ToEntryNavigation)); @@ -1231,14 +1239,19 @@ public async Task GetEntryIndexViewModelAsync(Entry entry, var publisherIds = entry.EntryStaffFromEntryNavigation.Where(s => s.PositionGeneral == PositionGeneralType.Publisher || s.PositionGeneral == PositionGeneralType.ProductionGroup).Select(s => s.ToEntry); foreach (var item in relstionsAndStaffs.Where(s => publisherIds.Contains(s.Id) && s.Information.Any(s => s.DisplayName == "QQ群" && string.IsNullOrWhiteSpace(s.DisplayValue) == false))) { - model.Information.Add(new EntryInformationModel + var temp = new EntryInformationModel { Name = model.Information.Any(s => s.Name == "QQ群") ? item.DisplayName : "QQ群", Icon = model.Information.Any(s => s.Name == "QQ群") ? "mdi-vector-point" : qqIcon, Value = model.Information.Any(s => s.Name == "QQ群") ? item.Information.FirstOrDefault(s => s.DisplayName == "QQ群").DisplayValue : $"{item.Information.FirstOrDefault(s => s.DisplayName == "QQ群").DisplayValue} ({item.DisplayName})" - }); + }; + + + temp.Value = QQGroupRegex().Replace(temp.Value, "$1"); + model.Information.Add(temp); } } + //添加发行列表 foreach (var item in entry.Releases) { @@ -3118,5 +3131,8 @@ public async Task PostAllBookingNotice(int max) await _bookingUserRepository.GetAll().Where(s => userIds.Contains(s.ApplicationUserId) && s.BookingId != null && entries.Select(s => s.BookingId).Contains(s.BookingId.Value)).ExecuteUpdateAsync(s => s.SetProperty(a => a.IsNotified, b => true)); } + + [GeneratedRegex("(\\d{8})")] + private static partial Regex QQGroupRegex(); } } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Files/FileService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Files/FileService.cs index d7a9673008..20f53fc568 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Files/FileService.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Files/FileService.cs @@ -28,7 +28,7 @@ public class FileService : IFileService private readonly IConfiguration _configuration; private readonly ILogger _logger; - public FileService(IAppHelper appHelper,IConfiguration configuration, IHttpService httpService, + public FileService(IAppHelper appHelper, IConfiguration configuration, IHttpService httpService, IRepository articleRepository, IRepository entryRepository, ILogger logger, IRepository videoRepository, IFileUploadService fileUploadService) { _appHelper = appHelper; @@ -50,15 +50,15 @@ public async Task TransferDepositFile(string url) { try { - var result = await _httpService.GetAsync(_configuration["ImageApiPath"]+ "api/files/TransferDepositToTucangCC?url=" + url); - + var result = await _httpService.GetAsync(_configuration["ImageApiPath"] + "api/files/TransferDepositToTucangCC?url=" + url); + if (result.Uploaded) { return $"{result.Url}?{url}"; } else { - _logger.LogError("转存图片({img})失败,{msg}",url,result.Error); + _logger.LogError("转存图片({img})失败,{msg}", url, result.Error); return null; } @@ -203,6 +203,43 @@ public async Task TransferMainImagesToPublic(int maxCount) _logger.LogError(ex, "转存 词条 - {name}({id}) 相册失败", item.Name, item.Id); } } + + var websitePictures = await _entryRepository.GetAll() + .Include(s => s.WebsiteAddInfor).ThenInclude(s => s.Images) + .Where(s => s.IsHidden == false && string.IsNullOrWhiteSpace(s.Name) == false) + .Where(s => s.WebsiteAddInfor != null) + .Where(s => s.WebsiteAddInfor.Images.Any(s => s.Url.Contains("?") == false && s.Url.Contains("default") == false)) + .OrderBy(s => s.Id) + .Take(maxCount) + .ToListAsync(); + + foreach (var item in websitePictures) + { + try + { + var count = item.WebsiteAddInfor.Images.Count(s => s.Url.Contains('?') == false && s.Url.Contains("default") == false); + foreach (var infor in item.WebsiteAddInfor.Images.Where(s => s.Url.Contains('?') == false && s.Url.Contains("default") == false)) + { + var temp = await TransferDepositFile(infor.Url); + if (string.IsNullOrWhiteSpace(temp) == false) + { + infor.Url = temp; + } + else + { + throw new Exception("转存图片失败"); + } + } + + await _entryRepository.UpdateAsync(item); + _logger.LogInformation("转存 词条 - {name}({id}) 专题页图片到 tucang.cc 图床,总计 {count} 张图片", item.Name, item.Id, count); + + } + catch (Exception ex) + { + _logger.LogError(ex, "转存 词条 - {name}({id}) 专题页图片失败", item.Name, item.Id); + } + } } } } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AdminAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AdminAPIController.cs index f4fa1b8a27..25412d63a8 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AdminAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AdminAPIController.cs @@ -15,6 +15,7 @@ using CnGalWebSite.APIServer.Application.Ranks; using CnGalWebSite.APIServer.Application.Search; using CnGalWebSite.APIServer.Application.SteamInfors; +using CnGalWebSite.APIServer.Application.Stores; using CnGalWebSite.APIServer.Application.Tasks; using CnGalWebSite.APIServer.Application.TimedTasks; using CnGalWebSite.APIServer.Application.Users; @@ -132,6 +133,7 @@ public class AdminAPIController : ControllerBase private readonly IEditRecordService _editRecordService; private readonly IVideoService _videoService; private readonly ITimedTaskService _timedTaskService; + private readonly IStoreInfoService _storeInfoService; private readonly IBackgroundTaskService _backgroundTaskService; private readonly IRepository _perfectionOverviewRepository; private readonly IRepository _almanacRepository; @@ -147,7 +149,7 @@ public AdminAPIController(IRepository userOnlineInforRepo IArticleService articleService, IUserService userService, IExamineService examineService, IRepository rankRepository, INewsService newsService, ISteamInforService steamInforService, IRepository articleRepository, IAppHelper appHelper, IRepository entryRepository, IFavoriteFolderService favoriteFolderService, IRepository peripheryRepository, IRepository examineRepository, IRepository tagRepository, IPeripheryService peripheryService, IRepository gameNewsRepository, IRepository steamInforTableModelRepository, - IVoteService voteService, IRepository voteRepository, IRepository steamInforRepository, ILotteryService lotteryService, IRepository robotReplyRepository, + IVoteService voteService, IRepository voteRepository, IRepository steamInforRepository, ILotteryService lotteryService, IRepository robotReplyRepository, IStoreInfoService storeInfoService, IRepository weeklyNewsRepository, IConfiguration configuration, IRepository lotteryRepository, IRepository lotteryUserRepository, ILogger logger, IRepository lotteryAwardRepository, ISearchHelper searchHelper, IChartService chartService, IOperationRecordService operationRecordService, IRepository playedGameRepository, ITimedTaskService timedTaskService, IRepository lotteryPrizeRepository, IRepository operationRecordRepository, IRepository rankUsersRepository, IRepository videoRepository, IRepository almanacRepository, @@ -223,6 +225,7 @@ public AdminAPIController(IRepository userOnlineInforRepo _almanacEntryRepository = almanacEntryRepository; _timedTaskService = timedTaskService; _backgroundTaskService = backgroundTaskService; + _storeInfoService= storeInfoService; } /// @@ -325,11 +328,7 @@ public async Task> TempFunction() { try { - var lottery= await _lotteryRepository.FirstOrDefaultAsync(s => s.Id == 10); - lottery.MainPicture = null; - lottery.Thumbnail = "https://tucang.cngal.top/api/image/show/eff79eeb2860dc7b117b96c90d4daf81?https://image.cngal.org/images/upload/20240330/3fe68efcc0de2071ee489163609c6a1a616cae66.jpg"; - lottery.BriefIntroduction = "CnGal八周年啦!"; - await _lotteryRepository.UpdateAsync(lottery); + await _fileService.TransferMainImagesToPublic(1); return new Result { Successful = true }; } diff --git a/CnGalWebSite/CnGalWebSite.Shared.Component/Entries/NewVersion/BasicInforAloneTip.razor b/CnGalWebSite/CnGalWebSite.Shared.Component/Entries/NewVersion/BasicInforAloneTip.razor index e345351402..73749c2435 100644 --- a/CnGalWebSite/CnGalWebSite.Shared.Component/Entries/NewVersion/BasicInforAloneTip.razor +++ b/CnGalWebSite/CnGalWebSite.Shared.Component/Entries/NewVersion/BasicInforAloneTip.razor @@ -5,7 +5,7 @@ {
- @($"{Title}{(string.IsNullOrWhiteSpace(Title)?"":":")}{Text}") + @((MarkupString)$"{Title}{(string.IsNullOrWhiteSpace(Title) ? "" : ":")}{Text}")
} else