Skip to content

Commit

Permalink
Merge pull request #770 from LittleFish-233/master
Browse files Browse the repository at this point in the history
添加转存词条专题页图片到图床的任务,词条附加信息中QQ群号加粗显示
  • Loading branch information
LittleFish-233 authored May 4, 2024
2 parents 9e86043 + 245d468 commit 38894fd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +38,7 @@

namespace CnGalWebSite.APIServer.Application.Entries
{
public class EntryService : IEntryService
public partial class EntryService : IEntryService
{
private readonly IRepository<Entry, int> _entryRepository;
private readonly IRepository<Article, int> _articleRepository;
Expand Down Expand Up @@ -1212,14 +1213,21 @@ public async Task<EntryIndexViewModel> 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, "<b>$1</b>");
}
model.Information.Add(temp);
}
}

// 添加Staff
var relstionsAndStaffs = new List<Entry>();
relstionsAndStaffs.AddRange(entry.EntryRelationFromEntryNavigation.Select(s => s.ToEntryNavigation));
relstionsAndStaffs.AddRange(entry.EntryStaffFromEntryNavigation.Where(s => s.ToEntryNavigation != null).Select(s => s.ToEntryNavigation));
Expand All @@ -1231,14 +1239,19 @@ public async Task<EntryIndexViewModel> 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, "<b>$1</b>");
model.Information.Add(temp);
}
}

//添加发行列表
foreach (var item in entry.Releases)
{
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class FileService : IFileService
private readonly IConfiguration _configuration;
private readonly ILogger<FileService> _logger;

public FileService(IAppHelper appHelper,IConfiguration configuration, IHttpService httpService,
public FileService(IAppHelper appHelper, IConfiguration configuration, IHttpService httpService,
IRepository<Article, long> articleRepository, IRepository<Entry, int> entryRepository, ILogger<FileService> logger, IRepository<Video, long> videoRepository, IFileUploadService fileUploadService)
{
_appHelper = appHelper;
Expand All @@ -50,15 +50,15 @@ public async Task<string> TransferDepositFile(string url)
{
try
{
var result = await _httpService.GetAsync<UploadResult>(_configuration["ImageApiPath"]+ "api/files/TransferDepositToTucangCC?url=" + url);
var result = await _httpService.GetAsync<UploadResult>(_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;
}

Expand Down Expand Up @@ -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);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PerfectionOverview, long> _perfectionOverviewRepository;
private readonly IRepository<Almanac, long> _almanacRepository;
Expand All @@ -147,7 +149,7 @@ public AdminAPIController(IRepository<UserOnlineInfor, long> userOnlineInforRepo
IArticleService articleService, IUserService userService, IExamineService examineService, IRepository<Rank, long> rankRepository, INewsService newsService, ISteamInforService steamInforService,
IRepository<Article, long> articleRepository, IAppHelper appHelper, IRepository<Entry, int> entryRepository, IFavoriteFolderService favoriteFolderService, IRepository<Periphery, long> peripheryRepository,
IRepository<Examine, long> examineRepository, IRepository<Tag, int> tagRepository, IPeripheryService peripheryService, IRepository<GameNews, long> gameNewsRepository, IRepository<SteamInforTableModel, long> steamInforTableModelRepository,
IVoteService voteService, IRepository<Vote, long> voteRepository, IRepository<SteamInfor, long> steamInforRepository, ILotteryService lotteryService, IRepository<RobotReply, long> robotReplyRepository,
IVoteService voteService, IRepository<Vote, long> voteRepository, IRepository<SteamInfor, long> steamInforRepository, ILotteryService lotteryService, IRepository<RobotReply, long> robotReplyRepository, IStoreInfoService storeInfoService,
IRepository<WeeklyNews, long> weeklyNewsRepository, IConfiguration configuration, IRepository<Lottery, long> lotteryRepository, IRepository<LotteryUser, long> lotteryUserRepository, ILogger<AdminAPIController> logger,
IRepository<LotteryAward, long> lotteryAwardRepository, ISearchHelper searchHelper, IChartService chartService, IOperationRecordService operationRecordService, IRepository<PlayedGame, long> playedGameRepository, ITimedTaskService timedTaskService,
IRepository<LotteryPrize, long> lotteryPrizeRepository, IRepository<OperationRecord, long> operationRecordRepository, IRepository<RankUser, long> rankUsersRepository, IRepository<Video, long> videoRepository, IRepository<Almanac, long> almanacRepository,
Expand Down Expand Up @@ -223,6 +225,7 @@ public AdminAPIController(IRepository<UserOnlineInfor, long> userOnlineInforRepo
_almanacEntryRepository = almanacEntryRepository;
_timedTaskService = timedTaskService;
_backgroundTaskService = backgroundTaskService;
_storeInfoService= storeInfoService;
}

/// <summary>
Expand Down Expand Up @@ -325,11 +328,7 @@ public async Task<ActionResult<Result>> 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 };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
<div>
<CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaIcon Type="@Icon" IconString="@IconString"/>
@($"{Title}{(string.IsNullOrWhiteSpace(Title)?"":"")}{Text}")
<span>@((MarkupString)$"{Title}{(string.IsNullOrWhiteSpace(Title) ? "" : "")}{Text}")</span>
</div>
}
else
Expand Down

0 comments on commit 38894fd

Please sign in to comment.