diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/ErrorCounts/ErrorCountService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/ErrorCounts/ErrorCountService.cs deleted file mode 100644 index da1701e64..000000000 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/ErrorCounts/ErrorCountService.cs +++ /dev/null @@ -1,79 +0,0 @@ -using BootstrapBlazor.Components; -using CnGalWebSite.APIServer.DataReositories; -using CnGalWebSite.DataModel.Model; -using CnGalWebSite.DataModel.ViewModel.Admin; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace CnGalWebSite.APIServer.Application.ErrorCounts -{ - public class ErrorCountService : IErrorCountService - { - private readonly IRepository _errorCountRepository; - - private static readonly ConcurrentDictionary, string, SortOrder, IEnumerable>> SortLambdaCache = new(); - - - public ErrorCountService(IRepository errorCountRepository) - { - _errorCountRepository = errorCountRepository; - } - public Task> GetPaginatedResult(CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions options, ListErrorCountAloneModel searchModel) - { - IEnumerable items = _errorCountRepository.GetAll().AsNoTracking(); - // 处理高级搜索 - if (!string.IsNullOrWhiteSpace(searchModel.Text)) - { - items = items.Where(item => item.Text?.Contains(searchModel.Text, StringComparison.OrdinalIgnoreCase) ?? false); - } - - - - // 处理 SearchText 模糊搜索 - if (!string.IsNullOrWhiteSpace(options.SearchText)) - { - items = items.Where(item => (item.Text?.Contains(options.SearchText) ?? false)); - } - - // 排序 - var isSorted = false; - if (!string.IsNullOrWhiteSpace(options.SortName)) - { - // 外部未进行排序,内部自动进行排序处理 - var invoker = SortLambdaCache.GetOrAdd(typeof(ErrorCount), key => LambdaExtensions.GetSortLambda().Compile()); - items = invoker(items, options.SortName, (BootstrapBlazor.Components.SortOrder)options.SortOrder); - isSorted = true; - } - - // 设置记录总数 - var total = items.Count(); - - // 内存分页 - items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList(); - - //复制数据 - var resultItems = new List(); - foreach (var item in items) - { - resultItems.Add(new ListErrorCountAloneModel - { - Id = item.Id, - Text = item.Text, - LastUpdateTime = item.LastUpdateTime - }); - } - - return Task.FromResult(new QueryData() - { - Items = resultItems, - TotalCount = total, - IsSorted = isSorted, - // IsFiltered = isFiltered - }); - } - } -} diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/ErrorCounts/IErrorCountService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/ErrorCounts/IErrorCountService.cs deleted file mode 100644 index ce455191f..000000000 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/ErrorCounts/IErrorCountService.cs +++ /dev/null @@ -1,11 +0,0 @@ -using BootstrapBlazor.Components; -using CnGalWebSite.DataModel.ViewModel.Admin; -using System.Threading.Tasks; - -namespace CnGalWebSite.APIServer.Application.ErrorCounts -{ - public interface IErrorCountService - { - Task> GetPaginatedResult(CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions options, ListErrorCountAloneModel searchModel); - } -} diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Files/FileService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Files/FileService.cs index b4ce61dc7..2442f160c 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Files/FileService.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Files/FileService.cs @@ -8,6 +8,7 @@ using CnGalWebSite.DataModel.ViewModel.Admin; using CnGalWebSite.DataModel.ViewModel.Files; using CnGalWebSite.DrawingBed.Helper.Services; +using CnGalWebSite.DrawingBed.Models.ViewModels; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json.Linq; using System.Collections.Concurrent; @@ -50,39 +51,15 @@ public async Task TransferDepositFile(string url) { try { - if (string.IsNullOrWhiteSpace(url)) + var result = await _httpService.GetAsync(_configuration["ImageApiPath"]+ "api/files/TransferDepositToTucangCC?url=" + url); + + if (result.Uploaded) { - _logger.LogError("转存图片失败,图片为空"); - return null; - } - - if (url.Contains("http") == false) - { - url = "https:" + url; - } - - var client = await _httpService.GetClientAsync(); - using var content = new MultipartFormDataContent(); - using var fileContent = new StreamContent(await client.GetStreamAsync(url)); - - content.Add( - content: fileContent, - name: "file", - fileName: "test.png"); - content.Add(new StringContent(_configuration["TucangCCAPIToken"]), "token"); - - var response = await client.PostAsync(_configuration["TucangCCAPIUrl"], content); - - var newUploadResults = await response.Content.ReadAsStringAsync(); - var result = JObject.Parse(newUploadResults); - - if (result["code"].ToObject() == 200) - { - return $"{_configuration["CustomTucangCCUrl"]}{result["data"]["url"].ToObject().Split('/').LastOrDefault()}?{url}"; + return $"{result.Url}?{url}"; } else { - _logger.LogError("转存图片失败,接口返回代码:{code},消息:{msg},图片:{url}", result["code"].ToObject(), result["msg"].ToObject(), url); + _logger.LogError("转存图片({img})失败,{msg}",url,result.Error); return null; } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Helper/AppHelper.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Helper/AppHelper.cs index b0f61751f..922b15b6c 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Helper/AppHelper.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Helper/AppHelper.cs @@ -51,7 +51,6 @@ public class AppHelper : IAppHelper private readonly IRepository _commentRepository; private readonly IRepository _userRepository; private readonly IRepository _historyUserRepository; - private readonly IRepository _errorCountRepository; private readonly IRepository _userFileRepository; private readonly IRepository _backUpArchiveRepository; private readonly IRepository _backUpArchiveDetailRepository; @@ -68,7 +67,7 @@ public class AppHelper : IAppHelper private readonly HttpClient _httpClient; public AppHelper(IRepository backUpArchiveRepository, IRepository signInDayRepository, IRepository backUpArchiveDetailRepository, IRepository userFileRepository, - IRepository favoriteFolderRepository, IRepository errorCountRepository, IRepository historyUserRepository, IRepository userRepository, + IRepository favoriteFolderRepository, IRepository historyUserRepository, IRepository userRepository, IRepository commentRepository, IConfiguration configuration, IRepository loginkeyRepository, IHttpClientFactory clientFactory, IRepository fileManagerRepository, IEmailService EmailService, IRepository tokenCustomRepository, IRepository aricleRepository, IRepository entryRepository, IRepository sendCountRepository, HttpClient httpClient, @@ -89,7 +88,6 @@ public class AppHelper : IAppHelper _commentRepository = commentRepository; _examineRepository = examineRepository; _historyUserRepository = historyUserRepository; - _errorCountRepository = errorCountRepository; _backUpArchiveDetailRepository = backUpArchiveDetailRepository; _backUpArchiveRepository = backUpArchiveRepository; _userFileRepository = userFileRepository; @@ -445,33 +443,6 @@ public async Task DeleteComment(long id) return; } - public async Task IsExceedMaxErrorCount(string text, int limit, int maxMinutes) - { - var timeNow = DateTime.Now.ToCstTime(); - var errors = await _errorCountRepository.GetAll().CountAsync(s => s.Text == text && s.LastUpdateTime.AddMinutes(maxMinutes) > timeNow); - return errors >= limit; - } - - public async Task AddErrorCount(string text) - { - _ = await _errorCountRepository.InsertAsync(new ErrorCount - { - LastUpdateTime = DateTime.Now.ToCstTime(), - Text = text - }); - } - - public async Task RemoveErrorCount(string text) - { - //查找是否存在计数器 - var error = await _errorCountRepository.FirstOrDefaultAsync(s => s.Text == text); - if (error != null) - { - await _errorCountRepository.DeleteAsync(error); - return; - } - } - public async Task IsExceedMaxSendCount(string mail, int limit, int maxMinutes) { var timeNow = DateTime.Now.ToCstTime(); @@ -1086,48 +1057,5 @@ public async Task DeleteAllBackupInfor() await _backUpArchiveDetailRepository.GetAll().Where(s => true).ExecuteDeleteAsync(); await _backUpArchiveRepository.GetAll().Where(s => true).ExecuteDeleteAsync(); } - - public async Task CheckStringCompliance(string text, string ip) - { - try - { - //检查是否超过上限 - if (await IsExceedMaxErrorCount(ip, 5, 1)) - { - return "请求验证用户名合规次数达到上限"; - } - - //初始化 - var API_KEY = _configuration["BaiduAPIKey"]; - var SECRET_KEY = _configuration["BaiduSecretKey"]; - - //获取令牌 - var client = _clientFactory.CreateClient(); - var jsonContent = await client.GetStringAsync("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + API_KEY + "&client_secret=" + SECRET_KEY + "&"); - var obj = JObject.Parse(jsonContent); - var access_token = obj["access_token"].ToString(); - - - var token = access_token; - var host = "https://aip.baidubce.com/rest/2.0/solution/v1/text_censor/v2/user_defined?access_token=" + token + "&text=" + text; - - jsonContent = await client.GetStringAsync(host); - obj = JObject.Parse(jsonContent); - - var conclusion = obj["conclusion"].ToString(); - - - - //增加审核次数 - await AddErrorCount(ip); - - return conclusion == "合规" ? null : "文本存在敏感词"; - } - catch (Exception) - { - return "请求审核文本失败"; - } - - } } } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Helper/IAppHelper.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Helper/IAppHelper.cs index cca5f3ed5..34bbeb350 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Helper/IAppHelper.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Helper/IAppHelper.cs @@ -120,26 +120,6 @@ public interface IAppHelper /// Task DeleteComment(long id); /// - /// 判断用户错误次数是否超过上限 - /// - /// 唯一标识符 - /// 限制次数 - /// 限制时间 - /// - Task IsExceedMaxErrorCount(string text, int limit, int maxMinutes); - /// - /// 增加错误次数 - /// - /// 唯一标识符 - /// - Task AddErrorCount(string text); - /// - /// 移除计数器 - /// - /// 唯一标识符 - /// - Task RemoveErrorCount(string text); - /// /// 判断是否通过人机验证 /// /// @@ -244,13 +224,6 @@ public interface IAppHelper /// Task DeleteAllBackupInfor(); /// - /// 检查文本是否合规 - /// - /// 文本 - /// 请求的ip - /// - Task CheckStringCompliance(string text, string ip); - /// /// 将markdown转化为html /// /// diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Lotteries/ILotteryService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Lotteries/ILotteryService.cs index 3fd0c6b3b..d2ad14524 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Lotteries/ILotteryService.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Lotteries/ILotteryService.cs @@ -1,6 +1,5 @@ using BootstrapBlazor.Components; using CnGalWebSite.DataModel.Model; -using CnGalWebSite.DataModel.ViewModel.Admin; using CnGalWebSite.DataModel.ViewModel.Lotteries; using CnGalWebSite.DataModel.ViewModel.OperationRecords; using System.Threading.Tasks; @@ -11,8 +10,6 @@ public interface ILotteryService { Task SendPrizeToWinningUser(LotteryUser user, LotteryAward award); - Task> GetPaginatedResult(CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions options, ListLotteryAloneModel searchModel); - Task> GetPaginatedResult(CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions options, ListLotteryUserAloneModel searchModel, long lotteryId); Task DrawAllLottery(); diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Lotteries/LotteryService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Lotteries/LotteryService.cs index 2ae6895e5..7203f9720 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Lotteries/LotteryService.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Lotteries/LotteryService.cs @@ -5,7 +5,6 @@ using CnGalWebSite.APIServer.DataReositories; using CnGalWebSite.DataModel.Helper; using CnGalWebSite.DataModel.Model; -using CnGalWebSite.DataModel.ViewModel.Admin; using CnGalWebSite.DataModel.ViewModel.Lotteries; using CnGalWebSite.DataModel.ViewModel.OperationRecords; using Microsoft.AspNetCore.Http; @@ -55,74 +54,6 @@ public class LotteryService : ILotteryService _playedGameRepository = playedGameRepository; _logger = logger; } - public Task> GetPaginatedResult(CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions options, ListLotteryAloneModel searchModel) - { - var items = _lotteryRepository.GetAll().Where(s => string.IsNullOrWhiteSpace(s.Name) == false).AsNoTracking(); - // 处理高级搜索 - if (!string.IsNullOrWhiteSpace(searchModel.Name)) - { - items = items.Where(item => item.Name.Contains(searchModel.Name, StringComparison.OrdinalIgnoreCase)); - } - if (!string.IsNullOrWhiteSpace(searchModel.BriefIntroduction)) - { - items = items.Where(item => item.BriefIntroduction.Contains(searchModel.BriefIntroduction, StringComparison.OrdinalIgnoreCase)); - } - - - - // 处理 SearchText 模糊搜索 - if (!string.IsNullOrWhiteSpace(options.SearchText)) - { - items = items.Where(item => item.Name.Contains(options.SearchText) - || item.BriefIntroduction.Contains(options.SearchText)); - } - - - // 排序 - var isSorted = false; - if (!string.IsNullOrWhiteSpace(options.SortName)) - { - items = items.OrderBy(s => s.Id).Sort(options.SortName, (BootstrapBlazor.Components.SortOrder)options.SortOrder); - isSorted = true; - } - - // 设置记录总数 - var total = items.Count(); - - // 内存分页 - var list = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList(); - - //复制数据 - var resultItems = new List(); - foreach (var item in list) - { - resultItems.Add(new ListLotteryAloneModel - { - Id = item.Id, - Name = item.Name, - IsHidden = item.IsHidden, - BriefIntroduction = _appHelper.GetStringAbbreviation(item.BriefIntroduction, 20), - Priority = item.Priority, - LastEditTime = item.LastEditTime, - ReaderCount = item.ReaderCount, - CanComment = item.CanComment ?? true, - CommentCount = item.CommentCount, - BeginTime = item.BeginTime, - EndTime = item.EndTime, - Type = item.Type, - IsEnd = item.IsEnd, - LotteryTime = item.LotteryTime, - }); - } - - return Task.FromResult(new QueryData() - { - Items = resultItems, - TotalCount = total, - IsSorted = isSorted, - // IsFiltered = isFiltered - }); - } public Task> GetPaginatedResult(CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions options, ListLotteryUserAloneModel searchModel, long lotteryId) { diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Users/UserService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Users/UserService.cs index d0ecf6ac8..7eda7c275 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Users/UserService.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Users/UserService.cs @@ -271,7 +271,6 @@ public async Task BindGroupQQ(string code, long groupQQ) var userId = ToolHelper.Base64DecodeString(await _appHelper.GetUserFromLoginKeyAsync(code)); if (string.IsNullOrWhiteSpace(userId)) { - await _appHelper.AddErrorCount(groupQQ.ToString()); return new Result { Successful = false, Error = $"身份验证失败" }; } var user = await _userRepository.FirstOrDefaultAsync(s=>s.Id==userId); diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Votes/IVoteService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Votes/IVoteService.cs index 3348673c2..52d91b19a 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Votes/IVoteService.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Votes/IVoteService.cs @@ -6,6 +6,6 @@ namespace CnGalWebSite.APIServer.Application.Votes { public interface IVoteService { - Task> GetPaginatedResult(CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions options, ListVoteAloneModel searchModel); + } } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Application/Votes/VoteService.cs b/CnGalWebSite/CnGalWebSite.APIServer/Application/Votes/VoteService.cs index 58146a70d..6e9ee60c4 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Application/Votes/VoteService.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Application/Votes/VoteService.cs @@ -26,75 +26,6 @@ public VoteService(IAppHelper appHelper, IRepository voteRepository) _voteRepository = voteRepository; _appHelper = appHelper; } - public Task> GetPaginatedResult(CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions options, ListVoteAloneModel searchModel) - { - IEnumerable items = _voteRepository.GetAll().Where(s => string.IsNullOrWhiteSpace(s.Name) == false).AsNoTracking(); - // 处理高级搜索 - if (!string.IsNullOrWhiteSpace(searchModel.Name)) - { - items = items.Where(item => item.Name?.Contains(searchModel.Name, StringComparison.OrdinalIgnoreCase) ?? false); - } - if (!string.IsNullOrWhiteSpace(searchModel.BriefIntroduction)) - { - items = items.Where(item => item.BriefIntroduction?.Contains(searchModel.BriefIntroduction, StringComparison.OrdinalIgnoreCase) ?? false); - } - - - - // 处理 SearchText 模糊搜索 - if (!string.IsNullOrWhiteSpace(options.SearchText)) - { - items = items.Where(item => (item.Name?.Contains(options.SearchText) ?? false) - || (item.BriefIntroduction?.Contains(options.SearchText) ?? false)); - } - - - // 排序 - var isSorted = false; - if (!string.IsNullOrWhiteSpace(options.SortName)) - { - // 外部未进行排序,内部自动进行排序处理 - var invoker = SortLambdaCachePeriphery.GetOrAdd(typeof(Vote), key => LambdaExtensions.GetSortLambda().Compile()); - items = invoker(items, options.SortName, (BootstrapBlazor.Components.SortOrder)options.SortOrder); - isSorted = true; - } - - // 设置记录总数 - var total = items.Count(); - - // 内存分页 - items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems).ToList(); - - //复制数据 - var resultItems = new List(); - foreach (var item in items) - { - resultItems.Add(new ListVoteAloneModel - { - Id = item.Id, - Name = item.Name, - IsHidden = item.IsHidden, - BriefIntroduction = _appHelper.GetStringAbbreviation(item.BriefIntroduction, 20), - Priority = item.Priority, - LastEditTime = item.LastEditTime, - ReaderCount = item.ReaderCount, - CanComment = item.CanComment ?? true, - CommentCount = item.CommentCount, - BeginTime = item.BeginTime, - EndTime = item.EndTime, - Type = item.Type, - }); - } - - return Task.FromResult(new QueryData() - { - Items = resultItems, - TotalCount = total, - IsSorted = isSorted, - // IsFiltered = isFiltered - }); - } - } } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AdminAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AdminAPIController.cs index 9d969f733..456215bed 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AdminAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AdminAPIController.cs @@ -2,7 +2,6 @@ using CnGalWebSite.APIServer.Application.Charts; using CnGalWebSite.APIServer.Application.Comments; using CnGalWebSite.APIServer.Application.Entries; -using CnGalWebSite.APIServer.Application.ErrorCounts; using CnGalWebSite.APIServer.Application.Examines; using CnGalWebSite.APIServer.Application.Favorites; using CnGalWebSite.APIServer.Application.Files; @@ -28,6 +27,7 @@ using CnGalWebSite.DataModel.Models; using CnGalWebSite.DataModel.ViewModel; using CnGalWebSite.DataModel.ViewModel.Admin; +using CnGalWebSite.DataModel.ViewModel.Lotteries; using CnGalWebSite.DataModel.ViewModel.OperationRecords; using CnGalWebSite.DataModel.ViewModel.Others; using CnGalWebSite.DataModel.ViewModel.Peripheries; @@ -80,7 +80,6 @@ public class AdminAPIController : ControllerBase private readonly IRepository _userOnlineInforRepository; private readonly IRepository _userRepository; private readonly IRepository _signInDayRepository; - private readonly IRepository _errorCountRepository; private readonly IRepository _favoriteFolderRepository; private readonly IRepository _favoriteObjectRepository; private readonly IRepository _rankRepository; @@ -96,7 +95,6 @@ public class AdminAPIController : ControllerBase private readonly ICommentService _commentService; private readonly IMessageService _messageService; private readonly IFileService _fileService; - private readonly IErrorCountService _errorCountService; private readonly IFavoriteFolderService _favoriteFolderService; private readonly IRankService _rankService; private readonly IPeripheryService _peripheryService; @@ -131,10 +129,10 @@ public class AdminAPIController : ControllerBase private readonly IRepository _perfectionOverviewRepository; public AdminAPIController(IRepository userOnlineInforRepository, IRepository userFileRepository, IRepository favoriteObjectRepository, IRepository entryStaffRepository, - IFileService fileService, IRepository signInDayRepository, IRepository errorCountRepository, IRepository backUpArchiveDetailRepository, IVideoService videoService, - IRepository thumbsUpRepository, IRepository disambigRepository, IRepository backUpArchiveRepository, IRankService rankService, + IFileService fileService, IRepository signInDayRepository, IRepository backUpArchiveDetailRepository, IVideoService videoService, + IRepository thumbsUpRepository, IRepository disambigRepository, IRankService rankService, IRepository userRepository, IMessageService messageService, ICommentService commentService, IRepository commentRepository, IWeiXinService weiXinService, IEditRecordService editRecordService, - IRepository messageRepository, IErrorCountService errorCountService, IRepository favoriteFolderRepository, IPerfectionService perfectionService, IWebHostEnvironment webHostEnvironment, + IRepository messageRepository,IRepository favoriteFolderRepository, IWebHostEnvironment webHostEnvironment, IRepository friendLinkRepository, IRepository carouselRepositor, IEntryService entryService, IRepository searchCacheRepository, IArticleService articleService, IUserService userService, IExamineService examineService, IRepository rankRepository, INewsService newsService, ISteamInforService steamInforService, IRepository articleRepository, IAppHelper appHelper, IRepository entryRepository, IFavoriteFolderService favoriteFolderService, IRepository peripheryRepository, @@ -169,8 +167,6 @@ public class AdminAPIController : ControllerBase _disambigRepository = disambigRepository; _fileService = fileService; _signInDayRepository = signInDayRepository; - _errorCountService = errorCountService; - _errorCountRepository = errorCountRepository; _favoriteFolderRepository = favoriteFolderRepository; _favoriteFolderService = favoriteFolderService; _backUpArchiveDetailRepository = backUpArchiveDetailRepository; @@ -291,14 +287,6 @@ public async Task>> GetErrorCountListAsync(ErrorCountsPagesInfor input) - { - var dtos = await _errorCountService.GetPaginatedResult(input.Options, input.SearchModel); - - return dtos; - } - [HttpPost] public async Task>> GetFavoriteFolderListAsync(FavoriteFoldersPagesInfor input) { @@ -307,172 +295,6 @@ public async Task>> GetVoteListAsync(VotesPagesInfor input) - { - var dtos = await _voteService.GetPaginatedResult(input.Options, input.SearchModel); - - return dtos; - } - - [HttpPost] - public async Task>> GetLotteryListAsync(LotteriesPagesInfor input) - { - var dtos = await _lotteryService.GetPaginatedResult(input.Options, input.SearchModel); - - return dtos; - } - - - /// - /// 管理主页 包括友情链接 轮播图 - /// - /// - [HttpGet] - public async Task> ManageHomeAsync() - { - var model = new ManageHomeViewModel - { - Links = await _friendLinkRepository.GetAll().OrderByDescending(s => s.Priority).ToListAsync() - }; - foreach (var item in model.Links) - { - item.Image = _appHelper.GetImagePath(item.Image, ""); - } - model.Carousels = await _carouselRepository.GetAll().OrderByDescending(s => s.Priority).ToListAsync(); - foreach (var item in model.Carousels) - { - item.Image = _appHelper.GetImagePath(item.Image, ""); - } - - - model.AppImage = _appHelper.GetImagePath("", "app.png"); - model.UserImage = _appHelper.GetImagePath("", "user.png"); - model.UserBackgroundImage = _appHelper.GetImagePath("", "userbackground.jpg"); - model.CertificateImage = _appHelper.GetImagePath("", "certificate.png"); - model.BackgroundImage = _appHelper.GetImagePath("", "background.png"); - - return model; - } - - /// - /// 编辑轮播图 - /// - /// - [HttpGet] - public async Task> EditCarouselsAsync() - { - //根据类别生成首个视图模型 - var model = new EditCarouselsViewModel(); - var carousels = await _carouselRepository.GetAll().OrderByDescending(s => s.Priority).ToListAsync(); - foreach (var item in carousels) - { - model.Carousels.Add(new CarouselModel - { - Link = item.Link, - Priority = item.Priority, - Note = item.Note, - Image = _appHelper.GetImagePath(item.Image, ""), - Type=item.Type, - }); - - } - - return model; - } - - /// - /// 编辑轮播图 - /// - /// - /// - [HttpPost] - public async Task> EditCarouselsAsync(EditCarouselsViewModel model) - { - //先把删除当前所有图片 - var carousels = await _carouselRepository.GetAll().ToListAsync(); - foreach (var item in carousels) - { - //_appHelper.DeleteImage(item.Image); - await _carouselRepository.DeleteAsync(item); - } - //循环添加视图中的图片 - if (model.Carousels != null) - { - foreach (var item in model.Carousels) - { - _ = await _carouselRepository.InsertAsync(new Carousel - { - Image = item.Image, - Link = item.Link, - Priority = item.Priority, - Note = item.Note, - Type=item.Type - }); - } - } - return new Result { Successful = true }; - } - - /// - /// 编辑友情链接 - /// - /// - [HttpGet] - public async Task> EditFriendLinksAsync() - { - //根据类别生成首个视图模型 - var model = new EditFriendLinksViewModel - { - FriendLinks = new List() - }; - var friendLinks = await _friendLinkRepository.GetAll().OrderByDescending(s => s.Priority).ToListAsync(); - foreach (var item in friendLinks) - { - model.FriendLinks.Add(new FriendLinkModel - { - Link = item.Link, - Name = item.Name, - Priority = item.Priority, - Image = _appHelper.GetImagePath(item.Image, "app.png") - }); - } - return model; - } - - /// - /// 编辑友情链接 - /// - /// - /// - [HttpPost] - public async Task> EditFriendLinksAsync(EditFriendLinksViewModel model) - { - - //先把删除当前所有图片 - var friendLinks = await _friendLinkRepository.GetAll().ToListAsync(); - foreach (var item in friendLinks) - { - //_appHelper.DeleteImage(item.Image); - await _friendLinkRepository.DeleteAsync(item); - } - //循环添加视图中的图片 - if (model.FriendLinks != null) - { - foreach (var item in model.FriendLinks) - { - _ = await _friendLinkRepository.InsertAsync(new FriendLink - { - Image = item.Image, - Name = item.Name, - Link = item.Link, - Priority = item.Priority - }); - } - } - return new Result { Successful = true }; - } - /// /// 刷新ES缓存 /// diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AnniversariesAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AnniversariesAPIController.cs index 0d1361281..4f67c4ad8 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AnniversariesAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/AnniversariesAPIController.cs @@ -1,47 +1,13 @@ -using CnGalWebSite.APIServer.Application.Articles; -using CnGalWebSite.APIServer.Application.Charts; -using CnGalWebSite.APIServer.Application.Comments; -using CnGalWebSite.APIServer.Application.Entries; -using CnGalWebSite.APIServer.Application.ErrorCounts; -using CnGalWebSite.APIServer.Application.Favorites; -using CnGalWebSite.APIServer.Application.Files; -using CnGalWebSite.APIServer.Application.Helper; -using CnGalWebSite.APIServer.Application.Lotteries; -using CnGalWebSite.APIServer.Application.Messages; -using CnGalWebSite.APIServer.Application.News; -using CnGalWebSite.APIServer.Application.Perfections; -using CnGalWebSite.APIServer.Application.Peripheries; -using CnGalWebSite.APIServer.Application.Ranks; -using CnGalWebSite.APIServer.Application.Search; +using CnGalWebSite.APIServer.Application.Helper; using CnGalWebSite.APIServer.Application.Users; -using CnGalWebSite.APIServer.Application.Votes; -using CnGalWebSite.APIServer.Application.WeiXin; using CnGalWebSite.APIServer.DataReositories; -using CnGalWebSite.APIServer.ExamineX; -using CnGalWebSite.APIServer.Model; using CnGalWebSite.DataModel.Helper; using CnGalWebSite.DataModel.Model; -using CnGalWebSite.DataModel.Models; -using CnGalWebSite.DataModel.ViewModel.Admin; using CnGalWebSite.DataModel.ViewModel.Anniversaries; -using CnGalWebSite.DataModel.ViewModel.Others; using CnGalWebSite.DataModel.ViewModel.PlayedGames; -using CnGalWebSite.DataModel.ViewModel.Search; -using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace CnGalWebSite.APIServer.Controllers { @@ -53,123 +19,16 @@ public class AnniversariesAPIController : ControllerBase private readonly IRepository _entryRepository; - private readonly IRepository _examineRepository; - private readonly IRepository _tagRepository; - private readonly IRepository _articleRepository; - private readonly IRepository _friendLinkRepository; - private readonly IRepository _carouselRepository; - private readonly IRepository _userFileRepository; - private readonly IRepository _disambigRepository; - private readonly IRepository _messageRepository; - private readonly IRepository _commentRepository; - private readonly IRepository _thumbsUpRepository; - private readonly IRepository _backUpArchiveDetailRepository; - private readonly IRepository _userOnlineInforRepository; - private readonly IRepository _userRepository; - private readonly IRepository _signInDayRepository; - private readonly IRepository _errorCountRepository; - private readonly IRepository _favoriteFolderRepository; - private readonly IRepository _favoriteObjectRepository; - private readonly IRepository _rankRepository; - private readonly IRepository _peripheryRepository; - private readonly IRepository _voteRepository; - private readonly IRepository _steamInforRepository; private readonly IUserService _userService; private readonly IAppHelper _appHelper; - private readonly IExamineService _examineService; - private readonly IEntryService _entryService; - private readonly IArticleService _articleService; - private readonly ICommentService _commentService; - private readonly IMessageService _messageService; - private readonly IFileService _fileService; - private readonly IErrorCountService _errorCountService; - private readonly IFavoriteFolderService _favoriteFolderService; - private readonly IRankService _rankService; - private readonly IPeripheryService _peripheryService; - private readonly IVoteService _voteService; - private readonly ILotteryService _lotteryService; - private readonly IWeiXinService _weiXinService; - private readonly INewsService _newsService; - private readonly IRepository _gameNewsRepository; - private readonly IRepository _weeklyNewsRepository; - private readonly IRepository _lotteryRepository; - private readonly ISearchHelper _searchHelper; - private readonly IConfiguration _configuration; - private readonly IRepository _lotteryUserRepository; - private readonly IRepository _lotteryAwardRepository; - private readonly IRepository _lotteryPrizeRepository; - private readonly IRepository _robotReplyRepository; - private readonly IRepository _searchCacheRepository; private readonly IRepository _playedGameRepository; - private readonly IWebHostEnvironment _webHostEnvironment; - private readonly IChartService _chartService; - public AnniversariesAPIController(IRepository userOnlineInforRepository, IRepository userFileRepository, IRepository favoriteObjectRepository, - IFileService fileService, IRepository signInDayRepository, IRepository errorCountRepository, IRepository backUpArchiveDetailRepository, - IRepository thumbsUpRepository, IRepository disambigRepository, IRepository backUpArchiveRepository, IRankService rankService, - IRepository userRepository, IMessageService messageService, ICommentService commentService, IRepository commentRepository, IWeiXinService weiXinService, - IRepository messageRepository, IErrorCountService errorCountService, IRepository favoriteFolderRepository, IPerfectionService perfectionService, IWebHostEnvironment webHostEnvironment, - IRepository friendLinkRepository, IRepository carouselRepositor, IEntryService entryService, IRepository searchCacheRepository, - IArticleService articleService, IUserService userService, IExamineService examineService, IRepository rankRepository, INewsService newsService, - IRepository articleRepository, IAppHelper appHelper, IRepository entryRepository, IFavoriteFolderService favoriteFolderService, IRepository peripheryRepository, - IRepository examineRepository, IRepository tagRepository, IPeripheryService peripheryService, IRepository gameNewsRepository, IRepository playedGameRepository, - IVoteService voteService, IRepository voteRepository, IRepository steamInforRepository, ILotteryService lotteryService, IRepository robotReplyRepository, - IRepository weeklyNewsRepository, IConfiguration configuration, IRepository lotteryRepository, IRepository lotteryUserRepository, - IRepository lotteryAwardRepository, ISearchHelper searchHelper, IChartService chartService, - IRepository lotteryPrizeRepository) + public AnniversariesAPIController(IUserService userService, IAppHelper appHelper, IRepository entryRepository,IRepository playedGameRepository) { _entryRepository = entryRepository; - _examineRepository = examineRepository; - _tagRepository = tagRepository; - _appHelper = appHelper; - _articleRepository = articleRepository; - _examineService = examineService; - + _appHelper = appHelper; _userService = userService; - _entryService = entryService; - _articleService = articleService; - _friendLinkRepository = friendLinkRepository; - _carouselRepository = carouselRepositor; - _messageRepository = messageRepository; - _commentRepository = commentRepository; - _commentService = commentService; - _messageService = messageService; - _userRepository = userRepository; - _userFileRepository = userFileRepository; - _userOnlineInforRepository = userOnlineInforRepository; - _thumbsUpRepository = thumbsUpRepository; - _disambigRepository = disambigRepository; - _fileService = fileService; - _signInDayRepository = signInDayRepository; - _errorCountService = errorCountService; - _errorCountRepository = errorCountRepository; - _favoriteFolderRepository = favoriteFolderRepository; - _favoriteFolderService = favoriteFolderService; - _backUpArchiveDetailRepository = backUpArchiveDetailRepository; - _favoriteObjectRepository = favoriteObjectRepository; - _rankRepository = rankRepository; - _rankService = rankService; - _peripheryRepository = peripheryRepository; - _peripheryService = peripheryService; - _newsService = newsService; - _gameNewsRepository = gameNewsRepository; - _weeklyNewsRepository = weeklyNewsRepository; - _voteService = voteService; - _voteRepository = voteRepository; - _configuration = configuration; - _steamInforRepository = steamInforRepository; - _lotteryRepository = lotteryRepository; - _lotteryService = lotteryService; - _lotteryUserRepository = lotteryUserRepository; - _lotteryAwardRepository = lotteryAwardRepository; - _lotteryPrizeRepository = lotteryPrizeRepository; - _searchHelper = searchHelper; - _weiXinService = weiXinService; - _robotReplyRepository = robotReplyRepository; - _searchCacheRepository = searchCacheRepository; - _webHostEnvironment = webHostEnvironment; - _chartService = chartService; _playedGameRepository = playedGameRepository; } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/ArticlesAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/ArticlesAPIController.cs index f2b22cd18..350d4e4a8 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/ArticlesAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/ArticlesAPIController.cs @@ -1280,7 +1280,7 @@ public async Task>> GetRandomArticle return model; } - + [Authorize(Roles = "Admin")] [HttpPost] public async Task> List(QueryParameterModel model) { diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/CommentsAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/CommentsAPIController.cs index 98593b14e..a84953a15 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/CommentsAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/CommentsAPIController.cs @@ -431,6 +431,7 @@ public async Task> UserHiddenCommentAsync(HiddenCommentMode return new Result { Successful = true }; } + [Authorize(Roles = "Admin")] [HttpPost] public async Task> List(QueryParameterModel model) { diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/EntriesAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/EntriesAPIController.cs index 799046b9b..457682d0a 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/EntriesAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/EntriesAPIController.cs @@ -111,7 +111,7 @@ public async Task> GetEntryViewAsync(int id, [ .Include(s => s.Articles).ThenInclude(s => s.CreateUser) .Include(s => s.Videos).ThenInclude(s => s.CreateUser) .Include(s => s.Articles).ThenInclude(s => s.Entries) - .Include(s => s.Information).ThenInclude(s => s.Additional) + .Include(s => s.Information) .Include(s => s.Tags) .Include(s => s.Pictures) .Include(s=>s.Releases) @@ -435,7 +435,7 @@ public async Task> EditAddInforAsync(int Id) //获取词条 var entry = await _entryRepository.GetAll().AsNoTracking() .Include(s=>s.Booking).ThenInclude(s=>s.Goals) - .Include(s => s.Information).ThenInclude(s => s.Additional) + .Include(s => s.Information) .Include(s=>s.EntryStaffFromEntryNavigation).ThenInclude(s=>s.ToEntryNavigation) .Include(s=>s.Releases) .FirstOrDefaultAsync(s => s.Id == Id && s.IsHidden != true); @@ -484,14 +484,14 @@ public async Task> EditAddInforAsync(EditAddInforViewModel //查找词条 var currentEntry = await _entryRepository.GetAll() .Include(s => s.Booking).ThenInclude(s => s.Goals) - .Include(s => s.Information).ThenInclude(s => s.Additional) + .Include(s => s.Information) .Include(s => s.EntryRelationFromEntryNavigation).ThenInclude(s => s.ToEntryNavigation) .Include(s => s.EntryStaffFromEntryNavigation).ThenInclude(s => s.ToEntryNavigation) .Include(s => s.Releases) .FirstOrDefaultAsync(x => x.Id == model.Id); var newEntry = await _entryRepository.GetAll().AsNoTracking() .Include(s => s.Booking).ThenInclude(s => s.Goals) - .Include(s => s.Information).ThenInclude(s => s.Additional) + .Include(s => s.Information) .Include(s => s.EntryRelationFromEntryNavigation).ThenInclude(s => s.ToEntryNavigation) .Include(s => s.EntryStaffFromEntryNavigation).ThenInclude(s => s.ToEntryNavigation) .Include(s => s.Releases) @@ -1746,6 +1746,7 @@ public async Task> GetEditInformationModelList(int ty }).ToList(); } + [Authorize(Roles = "Admin")] [HttpPost] public async Task> List(QueryParameterModel model) { diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/HomeAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/HomeAPIController.cs index 6c0f97ffb..2e2e9e16d 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/HomeAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/HomeAPIController.cs @@ -5,11 +5,17 @@ using CnGalWebSite.APIServer.Application.Stores; using CnGalWebSite.APIServer.DataReositories; using CnGalWebSite.APIServer.ExamineX; +using CnGalWebSite.Core.Models; +using CnGalWebSite.Core.Services.Query; using CnGalWebSite.DataModel.Application.Search.Dtos; using CnGalWebSite.DataModel.Model; using CnGalWebSite.DataModel.ViewModel; +using CnGalWebSite.DataModel.ViewModel.Admin; +using CnGalWebSite.DataModel.ViewModel.Entries; using CnGalWebSite.DataModel.ViewModel.Home; +using CnGalWebSite.DataModel.ViewModel.Ranks; using CnGalWebSite.DataModel.ViewModel.Search; +using CnGalWebSite.DataModel.ViewModel.Votes; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -20,10 +26,11 @@ using System.Linq; using System.Linq.Dynamic.Core; using System.Threading.Tasks; +using Result = CnGalWebSite.DataModel.Model.Result; namespace CnGalWebSite.APIServer.Controllers { - [AllowAnonymous] + [Authorize] [ApiController] [Route("api/home/[action]")] public class HomeAPIController : ControllerBase @@ -42,10 +49,13 @@ public class HomeAPIController : ControllerBase private readonly IHostApplicationLifetime _applicationLifetime; private readonly ILogger _logger; private readonly IStoreInfoService _storeInfoService; + private readonly IRepository _carouselRepository; + private readonly IQueryService _queryService; + private readonly IRepository _friendLinkRepository; public HomeAPIController(ISearchHelper searchHelper, IAppHelper appHelper, IRepository articleRepository, IHostApplicationLifetime applicationLifetime, ILogger logger, IRepository storeInfoRepository, IRepository entryRepository, IHomeService homeService, IExamineService examineService, IRepository examineRepository, IStoreInfoService storeInfoService, IRepository tagRepository, IRepository recommendRepository, - IRepository commentRepository) + IRepository commentRepository, IRepository carouselRepository, IQueryService queryService, IRepository friendLinkRepository) { _searchHelper = searchHelper; _entryRepository = entryRepository; @@ -59,33 +69,41 @@ public class HomeAPIController : ControllerBase _tagRepository = tagRepository; _commentRepository = commentRepository; _storeInfoService = storeInfoService; - _storeInfoRepository=storeInfoRepository; + _storeInfoRepository = storeInfoRepository; _recommendRepository = recommendRepository; + _carouselRepository = carouselRepository; + _queryService = queryService; + _friendLinkRepository = friendLinkRepository; } /// /// 获取近期发售的游戏 /// /// + [AllowAnonymous] [HttpGet] public async Task>> ListPublishedGames() { return await _homeService.ListPublishedGames(); } + /// /// 获取近期编辑的游戏或制作组 /// /// + [AllowAnonymous] [HttpGet] public async Task>> ListRecentlyEditedGames() { return await _homeService.ListRecentlyEditedGames(); } + /// /// 获取即将发售游戏 /// /// + [AllowAnonymous] [HttpGet] public async Task>> ListUpcomingGames() { @@ -97,6 +115,7 @@ public async Task>> ListUpcomingGames() /// 获取友情链接 /// /// + [AllowAnonymous] [HttpGet] public async Task>> ListFriendLinks() { @@ -108,46 +127,55 @@ public async Task>> ListFriendLinks() /// 获取通知 /// /// + [AllowAnonymous] [HttpGet] public async Task>> ListAnnouncements() { return await _homeService.ListAnnouncements(); } + /// /// 获取最近发布的文章 /// /// + [AllowAnonymous] [HttpGet] public async Task>> ListLatestArticles() { return await _homeService.ListLatestArticles(); } + /// /// 获取最近发布的视频 /// /// + [AllowAnonymous] [HttpGet] public async Task>> ListLatestVideos() { return await _homeService.ListLatestVideos(); } + /// /// 获取最近发布的动态 /// /// + [AllowAnonymous] [HttpGet] public async Task>> GetHomeNewsViewAsync() { return await _homeService.GetHomeNewsViewAsync(); } + /// /// 获取轮播图 /// /// + [AllowAnonymous] [HttpGet] public async Task>> GetHomeCarouselsViewAsync() { @@ -172,6 +200,7 @@ public async Task>> GetHomeCarouselsViewAsy /// /// /// + [AllowAnonymous] [HttpGet] public async Task> SearchAsync([FromQuery] string[] Types, [FromQuery] string[] Times, [FromQuery] string Text, [FromQuery] string Sort, [FromQuery] int Page) { @@ -188,16 +217,19 @@ public async Task> SearchAsync([FromQuery] string[ return NotFound(ex.Message); } } + /// /// 获取搜索提示 /// /// + [AllowAnonymous] [HttpGet] public async Task>> GetSearchTipListAsync() { return await _entryRepository.GetAll().Where(s => s.IsHidden != true).AsNoTracking().Select(s => s.Name).Where(s => string.IsNullOrWhiteSpace(s) == false).ToArrayAsync(); } + [AllowAnonymous] [HttpGet] public async Task>> GetDocumentsAsync() { @@ -283,10 +315,11 @@ public async Task>> GetDocumentsAsync() return model; } + [AllowAnonymous] [HttpPost] public async Task> GetPersonalizedRecommendations(IEnumerable ids) { - var model =new List(); + var model = new List(); //上限 if (ids.Count() > 100) @@ -301,12 +334,12 @@ public async Task> GetPersonalizedRecommendations(I .Select(s => s.Id) .ToListAsync(); - entryIds = entryIds.Random().Take(10).ToList() ; + entryIds = entryIds.Random().Take(10).ToList(); var entries = await _entryRepository.GetAll().AsNoTracking() .Include(s => s.Releases) .Include(s => s.Pictures) - .Include(s=>s.Tags) + .Include(s => s.Tags) .Where(s => entryIds.Contains(s.Id)) .ToListAsync(); @@ -314,12 +347,12 @@ public async Task> GetPersonalizedRecommendations(I var random = new Random(); //图墙 - if(entries.Count(s=>s.Pictures.Any())>=5) + if (entries.Count(s => s.Pictures.Any()) >= 5) { - + var imageEntries = new List(); - foreach(var item in entries.Where(s => s.Pictures.Any()).Take(5)) + foreach (var item in entries.Where(s => s.Pictures.Any()).Take(5)) { imageEntries.Add(item); } @@ -337,7 +370,7 @@ public async Task> GetPersonalizedRecommendations(I temp.ImageCards.Add(new PersonalRecommendImageCardModel { Id = item.Id, - Name=item.DisplayName, + Name = item.DisplayName, Image = item.Pictures.ToList().Random().OrderBy(s => s.Priority).FirstOrDefault()?.Url }); } @@ -364,7 +397,7 @@ public async Task> GetPersonalizedRecommendations(I }; if (string.IsNullOrWhiteSpace(item.MainPicture) == false) { - temp.Images.Insert(0,item.MainPicture); + temp.Images.Insert(0, item.MainPicture); } model.Add(temp); @@ -405,7 +438,7 @@ public async Task> GetPersonalizedRecommendations(I Time = release.Time, TimeNote = release.TimeNote, Type = release.Type, - StoreInfor = await _storeInfoService.Get(release.PublishPlatformType, release.PublishPlatformName, release.Link,release.Name, item.Id) + StoreInfor = await _storeInfoService.Get(release.PublishPlatformType, release.PublishPlatformName, release.Link, release.Name, item.Id) }; temp.Release = infor; } @@ -490,10 +523,10 @@ public async Task>> ListEvaluations() { var entryIds = await _entryRepository.GetAll().AsNoTracking() .Include(s => s.WebsiteAddInfor).ThenInclude(s => s.Images) - .Include(s=>s.Pictures) + .Include(s => s.Pictures) .Where(s => s.Articles.Count >= 3 && s.WebsiteAddInfor != null && s.WebsiteAddInfor.Images.Any()) .Where(s => s.IsHidden == false && string.IsNullOrWhiteSpace(s.Name) == false) - .Select(s=>s.Id) + .Select(s => s.Id) .ToListAsync(); entryIds = entryIds.ToList().Random().Take(4).ToList(); @@ -512,14 +545,14 @@ public async Task>> ListEvaluations() { model.Add(new EvaluationItemModel { - Image = _appHelper.GetImagePath(item.Pictures.Any(s=>s.Priority!=0)? item.Pictures.OrderByDescending(s => s.Priority).First().Url : item.WebsiteAddInfor.Images.OrderByDescending(s=>s.Priority).ThenBy(s=>s.Type).ThenBy(s=>s.Size).First().Url, "app.png"), + Image = _appHelper.GetImagePath(item.Pictures.Any(s => s.Priority != 0) ? item.Pictures.OrderByDescending(s => s.Priority).First().Url : item.WebsiteAddInfor.Images.OrderByDescending(s => s.Priority).ThenBy(s => s.Type).ThenBy(s => s.Size).First().Url, "app.png"), Name = item.DisplayName, Url = "entries/index/" + item.Id, - Articles=item.Articles.OrderByDescending(s=>s.Priority).ThenByDescending(s=>s.Type).Take(4).Select(s=>new EvaluationArticleItemModel + Articles = item.Articles.OrderByDescending(s => s.Priority).ThenByDescending(s => s.Type).Take(4).Select(s => new EvaluationArticleItemModel { Id = s.Id, Image = _appHelper.GetImagePath(s.MainPicture, "app.png"), - Name=s.Name, + Name = s.Name, OriginalAuthor = string.IsNullOrWhiteSpace(s.OriginalAuthor) ? s.CreateUser.UserName : s.OriginalAuthor, Type = s.Type, }).ToList() @@ -532,11 +565,11 @@ public async Task>> ListEvaluations() [AllowAnonymous] [HttpGet] - public async Task>> ListLatestComments([FromQuery]bool renderMarkdown=true) + public async Task>> ListLatestComments([FromQuery] bool renderMarkdown = true) { var comments = await _commentRepository.GetAll().AsNoTracking() - .Include(s=>s.ApplicationUser) - .Where(s => s.IsHidden == false&&string.IsNullOrWhiteSpace(s.Text)==false) + .Include(s => s.ApplicationUser) + .Where(s => s.IsHidden == false && string.IsNullOrWhiteSpace(s.Text) == false) .OrderByDescending(s => s.CommentTime) .Take(6) .ToListAsync(); @@ -550,9 +583,9 @@ public async Task>> ListLatestComments Url = item.EntryId != null ? $"entries/index/{item.EntryId}" : item.ArticleId != null ? $"articles/index/{item.ArticleId}" : item.Periphery != null ? $"peripheries/index/{item.PeripheryId}" : item.LotteryId != null ? $"lotteries/index/{item.LotteryId}" : item.VoteId != null ? $"votes/index/{item.VoteId}" : item.VideoId != null ? $"videos/index/{item.VideoId}" : $"space/index/{item.ApplicationUserId}", UserName = item.ApplicationUser.UserName, Time = item.CommentTime.ToTimeFromNowString(), - Content = renderMarkdown? _appHelper.MarkdownToHtml(item.Text): item.Text, + Content = renderMarkdown ? _appHelper.MarkdownToHtml(item.Text) : item.Text, UserImage = _appHelper.GetImagePath(item.ApplicationUser.PhotoPath, "user.png"), - UserId=item.ApplicationUserId + UserId = item.ApplicationUserId }); } @@ -564,11 +597,11 @@ public async Task>> ListLatestComments public async Task>> ListHotTags() { var entries = await _tagRepository.GetAll().AsNoTracking() - .Include(s=>s.Entries) - .Where(s => s.Entries.Count >= 6 ) + .Include(s => s.Entries) + .Where(s => s.Entries.Count >= 6) .Where(s => s.IsHidden == false && string.IsNullOrWhiteSpace(s.Name) == false) - .Where(s=>s.Name.Contains("STAFF")==false&& s.Name.Contains("配音") == false && s.Name.Contains("城市群") == false && s.Name.Contains("声线") == false && s.Name.Contains("字幕") == false) - .OrderByDescending(s => s.Priority).ThenByDescending(s=>s.Entries.Count) + .Where(s => s.Name.Contains("STAFF") == false && s.Name.Contains("配音") == false && s.Name.Contains("城市群") == false && s.Name.Contains("声线") == false && s.Name.Contains("字幕") == false) + .OrderByDescending(s => s.Priority).ThenByDescending(s => s.Entries.Count) .Take(15) .ToListAsync(); @@ -593,13 +626,13 @@ public async Task>> ListHotRecommends() var entryIds = await _recommendRepository.GetAll().AsNoTracking() .Include(s => s.Entry) .Where(s => s.Entry != null && s.Entry.IsHidden == false && s.IsHidden == false) - .Select(s=>s.EntryId) + .Select(s => s.EntryId) .ToListAsync(); entryIds = entryIds.ToList().Random().Take(16).ToList(); var entries = await _recommendRepository.GetAll().AsNoTracking() - .Include(s=>s.Entry) + .Include(s => s.Entry) .Where(s => entryIds.Contains(s.EntryId)).ToListAsync(); var model = new List(); @@ -611,12 +644,197 @@ public async Task>> ListHotRecommends() Name = item.Entry.DisplayName, Url = "entries/index/" + item.EntryId, BriefIntroduction = item.Entry.BriefIntroduction, - Reason=item.Reason + Reason = item.Reason + }); + } + + return model; + } + + [Authorize(Roles = "Admin")] + [HttpPost] + public async Task> ListCarousels(QueryParameterModel model) + { + var (items, total) = await _queryService.QueryAsync(_carouselRepository.GetAll().AsSingleQuery(), model, + s => string.IsNullOrWhiteSpace(model.SearchText) || (s.Note.Contains(model.SearchText))); + + return new QueryResultModel + { + Items = await items.Select(s => new CarouselOverviewModel + { + Id = s.Id, + Priority = s.Priority, + Type = s.Type, + Image = s.Image, + Link = s.Link, + Note = s.Note + }).ToListAsync(), + Total = total, + Parameter = model + }; + } + + [Authorize(Roles = "Admin")] + [HttpGet] + public async Task> EditCarouselAsync(int id) + { + var item = await _carouselRepository.FirstOrDefaultAsync(s => s.Id == id); + if (item == null) + { + return NotFound("无法找到目标"); + } + + var model = new CarouselEditModel + { + Id = item.Id, + Priority = item.Priority, + Type = item.Type, + Image = item.Image, + Link = item.Link, + Note = item.Note + }; + + return model; + } + + [Authorize(Roles = "Admin")] + [HttpPost] + public async Task> EditCarouselAsync(CarouselEditModel model) + { + Carousel item = null; + if (model.Id == 0) + { + item = await _carouselRepository.InsertAsync(new Carousel + { + Id = model.Id, + Priority = model.Priority, + Type = model.Type, + Image = model.Image, + Link = model.Link, + Note = model.Note }); + model.Id = item.Id; + _carouselRepository.Clear(); + } + + item = await _carouselRepository.GetAll().FirstOrDefaultAsync(s => s.Id == model.Id); + + + if (item == null) + { + return new Result { Successful = false, Error = "项目不存在" }; } + item.Id = model.Id; + item.Priority = model.Priority; + item.Type = model.Type; + item.Image = model.Image; + item.Link = model.Link; + item.Note = model.Note; + + await _carouselRepository.UpdateAsync(item); + + return new Result { Successful = true }; + } + + [Authorize(Roles = "Admin")] + [HttpPost] + public async Task> EditCarouselPriorityAsync(EditEntryPriorityViewModel model) + { + await _carouselRepository.GetAll().Where(s => model.Ids.Contains(s.Id)).ExecuteUpdateAsync(s => s.SetProperty(s => s.Priority, b => b.Priority + model.PlusPriority)); + + return new Result { Successful = true }; + } + + [Authorize(Roles = "Admin")] + [HttpPost] + public async Task> ListFriendLinks(QueryParameterModel model) + { + var (items, total) = await _queryService.QueryAsync(_friendLinkRepository.GetAll().AsSingleQuery(), model, + s => string.IsNullOrWhiteSpace(model.SearchText) || (s.Name.Contains(model.SearchText))); + + return new QueryResultModel + { + Items = await items.Select(s => new FriendLinkOverviewModel + { + Id = s.Id, + Priority = s.Priority, + Image = s.Image, + Link = s.Link, + Name=s.Name, + }).ToListAsync(), + Total = total, + Parameter = model + }; + } + + [Authorize(Roles = "Admin")] + [HttpGet] + public async Task> EditFriendLinkAsync(int id) + { + var item = await _friendLinkRepository.FirstOrDefaultAsync(s => s.Id == id); + if (item == null) + { + return NotFound("无法找到目标"); + } + + var model = new FriendLinkEditModel + { + Id = item.Id, + Priority = item.Priority, + Name = item.Name, + Image = item.Image, + Link = item.Link, + }; + return model; } + [Authorize(Roles = "Admin")] + [HttpPost] + public async Task> EditFriendLinkAsync(FriendLinkEditModel model) + { + FriendLink item = null; + if (model.Id == 0) + { + item = await _friendLinkRepository.InsertAsync(new FriendLink + { + Id = model.Id, + Priority = model.Priority, + Name = model.Name, + Image = model.Image, + Link = model.Link, + }); + model.Id = item.Id; + _friendLinkRepository.Clear(); + } + + item = await _friendLinkRepository.GetAll().FirstOrDefaultAsync(s => s.Id == model.Id); + + + if (item == null) + { + return new Result { Successful = false, Error = "项目不存在" }; + } + + item.Id = model.Id; + item.Priority = model.Priority; + item.Name = model.Name; + item.Image = model.Image; + item.Link = model.Link; + + await _friendLinkRepository.UpdateAsync(item); + + return new Result { Successful = true }; + } + + [Authorize(Roles = "Admin")] + [HttpPost] + public async Task> EditFriendLinkPriorityAsync(EditEntryPriorityViewModel model) + { + await _friendLinkRepository.GetAll().Where(s => model.Ids.Contains(s.Id)).ExecuteUpdateAsync(s => s.SetProperty(s => s.Priority, b => b.Priority + model.PlusPriority)); + + return new Result { Successful = true }; + } } } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/LotteryAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/LotteryAPIController.cs index a100fabf6..187af7e20 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/LotteryAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/LotteryAPIController.cs @@ -4,8 +4,11 @@ using CnGalWebSite.APIServer.Application.Ranks; using CnGalWebSite.APIServer.Application.Users; using CnGalWebSite.APIServer.DataReositories; +using CnGalWebSite.Core.Models; +using CnGalWebSite.Core.Services.Query; using CnGalWebSite.DataModel.Helper; using CnGalWebSite.DataModel.Model; +using CnGalWebSite.DataModel.ViewModel.Admin; using CnGalWebSite.DataModel.ViewModel.Lotteries; using CnGalWebSite.DataModel.ViewModel.Tables; using Markdig; @@ -53,10 +56,11 @@ public class LotteryAPIController : ControllerBase private readonly ILogger _logger; private readonly IOperationRecordService _operationRecordService; private readonly IUserService _userService; + private readonly IQueryService _queryService; public LotteryAPIController(IRepository voteRepository, IRepository voteOptionRepository, IRepository voteUserRepository, IRankService rankService, IUserService userService, IRepository weiboUserInforRepository, IRepository userRepository, ILogger logger, IOperationRecordService operationRecordService, - IAppHelper appHelper, IRepository gameNewsRepository, IRepository commentRepository, IRepository bookingRepository, + IAppHelper appHelper, IRepository gameNewsRepository, IRepository commentRepository, IRepository bookingRepository, IQueryService queryService, IRepository weeklyNewsRepository, IRepository lotteryRepository, IRepository lotteryUserRepository, IRepository lotteryAwardRepository, IRepository lotteryPrizeRepository, ILotteryService lotteryService, IRepository playedGameRepository, IRepository entryRepository, IRepository bookingUserRepository) { @@ -80,6 +84,7 @@ public class LotteryAPIController : ControllerBase _entryRepository = entryRepository; _bookingRepository = bookingRepository; _userService = userService; + _queryService = queryService; } @@ -906,5 +911,34 @@ public async Task>> GetNamesAsync() return await _lotteryRepository.GetAll().AsNoTracking().Where(s => s.IsHidden != true && string.IsNullOrWhiteSpace(s.Name) == false).Select(s => s.Name).ToArrayAsync(); } + [Authorize(Roles = "Admin")] + [HttpPost] + public async Task> List(QueryParameterModel model) + { + var (items, total) = await _queryService.QueryAsync(_lotteryRepository.GetAll().AsSingleQuery().Where(s => string.IsNullOrWhiteSpace(s.Name) == false), model, + s => string.IsNullOrWhiteSpace(model.SearchText) || (s.Name.Contains(model.SearchText))); + + return new QueryResultModel + { + Items = await items.Select(s => new LotteryOverviewModel + { + Id = s.Id, + Name = s.Name, + IsHidden = s.IsHidden, + CanComment = s.CanComment ?? true, + Priority = s.Priority, + Type = s.Type, + LastEditTime = s.LastEditTime, + BeginTime = s.BeginTime, + EndTime = s.EndTime, + IsEnd = s.IsEnd, + LotteryTime = s.LotteryTime, + }).ToListAsync(), + Total = total, + Parameter = model + }; + } + + } } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/PeripheriesAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/PeripheriesAPIController.cs index cc5e46de6..8562831aa 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/PeripheriesAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/PeripheriesAPIController.cs @@ -1097,6 +1097,7 @@ public async Task> CheckPeripheryIs return model; } + [Authorize(Roles = "Admin")] [HttpPost] public async Task> List(QueryParameterModel model) { diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/RanksAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/RanksAPIController.cs index 01654876b..4ffc613d5 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/RanksAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/RanksAPIController.cs @@ -187,6 +187,7 @@ public async Task> AddUserRankAsync(AddUserRankModel model) return new Result { Successful = true }; } + [Authorize(Roles = "Admin")] [HttpPost] public async Task> ListRanks(QueryParameterModel model) { diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/RobotAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/RobotAPIController.cs index 97b778699..4d978761c 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/RobotAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/RobotAPIController.cs @@ -1,7 +1,6 @@ using CnGalWebSite.APIServer.Application.Articles; using CnGalWebSite.APIServer.Application.Comments; using CnGalWebSite.APIServer.Application.Entries; -using CnGalWebSite.APIServer.Application.ErrorCounts; using CnGalWebSite.APIServer.Application.Favorites; using CnGalWebSite.APIServer.Application.Files; using CnGalWebSite.APIServer.Application.GPT; diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/TagsAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/TagsAPIController.cs index b106a415c..6a880963a 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/TagsAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/TagsAPIController.cs @@ -1035,6 +1035,7 @@ public async Task> GetCVThematicPageViewMo } + [Authorize(Roles = "Admin")] [HttpPost] public async Task> List(QueryParameterModel model) { diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/VideoAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/VideoAPIController.cs index 560396b41..7738c6de6 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/VideoAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/VideoAPIController.cs @@ -931,6 +931,7 @@ public async Task> RevokeExamine(RevokeExamineModel model) } + [Authorize(Roles = "Admin")] [HttpPost] public async Task> List(QueryParameterModel model) { diff --git a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/VoteAPIController.cs b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/VoteAPIController.cs index c4bfd9816..f8e96b135 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/Controllers/VoteAPIController.cs +++ b/CnGalWebSite/CnGalWebSite.APIServer/Controllers/VoteAPIController.cs @@ -5,9 +5,12 @@ using CnGalWebSite.APIServer.Application.Peripheries; using CnGalWebSite.APIServer.Application.Ranks; using CnGalWebSite.APIServer.DataReositories; +using CnGalWebSite.Core.Models; +using CnGalWebSite.Core.Services.Query; using CnGalWebSite.DataModel.Helper; using CnGalWebSite.DataModel.Model; using CnGalWebSite.DataModel.ViewModel; +using CnGalWebSite.DataModel.ViewModel.Admin; using CnGalWebSite.DataModel.ViewModel.Votes; using Markdig; using Microsoft.AspNetCore.Authentication.JwtBearer; @@ -43,9 +46,10 @@ public class VoteAPIController : ControllerBase private readonly IRepository _voteUserRepository; private readonly ILogger _logger; private readonly IOperationRecordService _operationRecordService; + private readonly IQueryService _queryService; public VoteAPIController(IRepository voteRepository, IRepository voteOptionRepository, IRepository voteUserRepository, IOperationRecordService operationRecordService, - IRepository userRepository, IEntryService entryService, IArticleService articleService, IRankService rankService, ILogger logger, + IRepository userRepository, IEntryService entryService, IArticleService articleService, IRankService rankService, ILogger logger, IQueryService queryService, IRepository articleRepository, IAppHelper appHelper, IRepository entryRepository, IRepository peripheryRepository, IPeripheryService peripheryService) { _entryRepository = entryRepository; @@ -62,6 +66,7 @@ public class VoteAPIController : ControllerBase _voteUserRepository = voteUserRepository; _logger = logger; _operationRecordService = operationRecordService; + _queryService = queryService; } [AllowAnonymous] @@ -73,7 +78,7 @@ public async Task> GetVoteViewAsync(long id) .Include(s => s.Entries).ThenInclude(s => s.EntryRelationFromEntryNavigation).ThenInclude(s => s.ToEntryNavigation) .Include(s => s.Entries).ThenInclude(s => s.EntryStaffFromEntryNavigation).ThenInclude(s => s.ToEntryNavigation) .Include(s => s.Entries).ThenInclude(s => s.EntryRelationFromEntryNavigation).ThenInclude(s => s.ToEntryNavigation).ThenInclude(s => s.EntryStaffFromEntryNavigation).ThenInclude(s => s.ToEntryNavigation) - .Include(s => s.Entries).ThenInclude(s => s.Information).ThenInclude(s => s.Additional) + .Include(s => s.Entries).ThenInclude(s => s.Information) .Include(s => s.Peripheries) .Include(s => s.VoteUsers).ThenInclude(s => s.SeletedOptions) .Include(s => s.VoteOptions) @@ -941,5 +946,32 @@ public async Task>> GetRelatedVotesAsync(Vo return model; } + + [Authorize(Roles = "Admin")] + [HttpPost] + public async Task> List(QueryParameterModel model) + { + var (items, total) = await _queryService.QueryAsync(_voteRepository.GetAll().AsSingleQuery().Where(s => string.IsNullOrWhiteSpace(s.Name) == false), model, + s => string.IsNullOrWhiteSpace(model.SearchText) || (s.Name.Contains(model.SearchText))); + + return new QueryResultModel + { + Items = await items.Select(s => new VoteOverviewModel + { + Id = s.Id, + Name = s.Name, + IsHidden = s.IsHidden, + CanComment = s.CanComment ?? true, + Priority = s.Priority, + Type = s.Type, + LastEditTime = s.LastEditTime, + BeginTime = s.BeginTime, + EndTime = s.EndTime, + }).ToListAsync(), + Total = total, + Parameter = model + }; + } + } } diff --git a/CnGalWebSite/CnGalWebSite.APIServer/appsettings.json b/CnGalWebSite/CnGalWebSite.APIServer/appsettings.json index eda370837..9c26e18bb 100644 --- a/CnGalWebSite/CnGalWebSite.APIServer/appsettings.json +++ b/CnGalWebSite/CnGalWebSite.APIServer/appsettings.json @@ -14,7 +14,10 @@ "SenderName": "CnGal资料站", "SenderEmail": "kanban@cngal.org", "Account": "kanban@cngal.org", - //转存图片API地址 + //图床API + "ImageApiPath": "http://localhost:5098/", + //"ImageApiPath": "https://api.cngal.top/" + //图仓 "TucangCCAPIUrl": "https://tucang.cc/api/v1/upload", "CustomTucangCCUrl": "https://tucang.cngal.top/api/image/show/", //RSS相关配置 diff --git a/CnGalWebSite/CnGalWebSite.DataModel/Model/ErrorCount.cs b/CnGalWebSite/CnGalWebSite.DataModel/Model/ErrorCount.cs index 1156ccf02..e553d7c70 100644 --- a/CnGalWebSite/CnGalWebSite.DataModel/Model/ErrorCount.cs +++ b/CnGalWebSite/CnGalWebSite.DataModel/Model/ErrorCount.cs @@ -1,6 +1,7 @@ using System; namespace CnGalWebSite.DataModel.Model { + [Obsolete("已移除")] public class ErrorCount { public long Id { get; set; } diff --git a/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Admin/ListLotteriesViewModel.cs b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Admin/ListLotteriesViewModel.cs deleted file mode 100644 index 28c2cfd0e..000000000 --- a/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Admin/ListLotteriesViewModel.cs +++ /dev/null @@ -1,63 +0,0 @@ -using CnGalWebSite.DataModel.Model; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace CnGalWebSite.DataModel.ViewModel.Admin -{ - public class ListLotteriesInforViewModel - { - public long Hiddens { get; set; } - - public long All { get; set; } - } - - public class ListLotteriesViewModel - { - public List Lotteries { get; set; } = new List { }; - } - public class ListLotteryAloneModel - { - [Display(Name = "Id")] - public long Id { get; set; } - [Display(Name = "类型")] - public LotteryType Type { get; set; } - [Display(Name = "名称")] - public string Name { get; set; } - [Display(Name = "简介")] - public string BriefIntroduction { get; set; } - [Display(Name = "开始时间")] - public DateTime BeginTime { get; set; } - [Display(Name = "截止时间")] - public DateTime EndTime { get; set; } - [Display(Name = "抽奖时间")] - public DateTime LotteryTime { get; set; } - [Display(Name = "优先级")] - public int Priority { get; set; } - - [Display(Name = "阅读数")] - public int ReaderCount { get; set; } - - [Display(Name = "评论数")] - public int CommentCount { get; set; } - - [Display(Name = "最后编辑时间")] - public DateTime? LastEditTime { get; set; } - - [Display(Name = "是否隐藏")] - public bool IsHidden { get; set; } - - [Display(Name = "是否结束")] - public bool IsEnd { get; set; } - - [Display(Name = "是否可以评论")] - public bool CanComment { get; set; } - } - - public class LotteriesPagesInfor - { - public CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions Options { get; set; } - public ListLotteryAloneModel SearchModel { get; set; } - } - -} diff --git a/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Admin/ListVotesViewModel.cs b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Admin/ListVotesViewModel.cs deleted file mode 100644 index a4c3c3f6c..000000000 --- a/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Admin/ListVotesViewModel.cs +++ /dev/null @@ -1,58 +0,0 @@ -using CnGalWebSite.DataModel.Model; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; - -namespace CnGalWebSite.DataModel.ViewModel.Admin -{ - public class ListVotesInforViewModel - { - public long Hiddens { get; set; } - - public long All { get; set; } - } - - public class ListVotesViewModel - { - public List Votes { get; set; } = new List { }; - } - public class ListVoteAloneModel - { - [Display(Name = "Id")] - public long Id { get; set; } - [Display(Name = "类型")] - public VoteType Type { get; set; } - [Display(Name = "名称")] - public string Name { get; set; } - [Display(Name = "简介")] - public string BriefIntroduction { get; set; } - [Display(Name = "开始时间")] - public DateTime BeginTime { get; set; } - [Display(Name = "截止时间")] - public DateTime EndTime { get; set; } - [Display(Name = "优先级")] - public int Priority { get; set; } - - [Display(Name = "阅读数")] - public int ReaderCount { get; set; } - - [Display(Name = "评论数")] - public int CommentCount { get; set; } - - [Display(Name = "最后编辑时间")] - public DateTime? LastEditTime { get; set; } - - [Display(Name = "是否隐藏")] - public bool IsHidden { get; set; } - - [Display(Name = "是否可以评论")] - public bool CanComment { get; set; } - } - - public class VotesPagesInfor - { - public CnGalWebSite.DataModel.ViewModel.Search.QueryPageOptions Options { get; set; } - public ListVoteAloneModel SearchModel { get; set; } - } - -} diff --git a/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Home/CarouselOverviewModel.cs b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Home/CarouselOverviewModel.cs new file mode 100644 index 000000000..c980daf83 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Home/CarouselOverviewModel.cs @@ -0,0 +1,29 @@ +using CnGalWebSite.DataModel.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CnGalWebSite.DataModel.ViewModel.Home +{ + public class CarouselOverviewModel + { + public int Id { get; set; } + + public CarouselType Type { get; set; } + + public string Image { get; set; } + + public string Link { get; set; } + + public string Note { get; set; } + + public int Priority { get; set; } + } + + public class CarouselEditModel: CarouselOverviewModel + { + + } +} diff --git a/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Home/FriendLinkOverviewModel.cs b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Home/FriendLinkOverviewModel.cs new file mode 100644 index 000000000..5526ec244 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Home/FriendLinkOverviewModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CnGalWebSite.DataModel.ViewModel.Home +{ + public class FriendLinkOverviewModel + { + public int Id { get; set; } + + public string Image { get; set; } + + public string Link { get; set; } + + public string Name { get; set; } + + public int Priority { get; set; } + } + + public class FriendLinkEditModel: FriendLinkOverviewModel + { + + } +} diff --git a/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Lotteries/LotteryOverviewModel.cs b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Lotteries/LotteryOverviewModel.cs new file mode 100644 index 000000000..d0dad50a4 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Lotteries/LotteryOverviewModel.cs @@ -0,0 +1,56 @@ +using CnGalWebSite.DataModel.Model; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace CnGalWebSite.DataModel.ViewModel.Lotteries +{ + public class LotteryOverviewModel + { + public long Id { get; set; } + /// + /// 类型 + /// + public LotteryType Type { get; set; } + /// + /// 名称 + /// + public string Name { get; set; } + /// + /// 开始时间 + /// + public DateTime BeginTime { get; set; } + /// + /// 截止时间 + /// + public DateTime EndTime { get; set; } + /// + /// 抽奖时间 + /// + public DateTime LotteryTime { get; set; } + /// + /// 优先级 + /// + public int Priority { get; set; } + + /// + /// 最后编辑时间 + /// + public DateTime LastEditTime { get; set; } + + /// + /// 是否隐藏 + /// + public bool IsHidden { get; set; } + + /// + /// 是否结束 + /// + public bool IsEnd { get; set; } + + /// + /// 是否可以评论 + /// + public bool CanComment { get; set; } + } +} diff --git a/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Votes/VoteOverviewModel.cs b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Votes/VoteOverviewModel.cs new file mode 100644 index 000000000..3a66a3726 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.DataModel/ViewModel/Votes/VoteOverviewModel.cs @@ -0,0 +1,47 @@ +using CnGalWebSite.DataModel.Model; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; + +namespace CnGalWebSite.DataModel.ViewModel.Admin +{ + public class VoteOverviewModel + { + public long Id { get; set; } + /// + /// 类型 + /// + public VoteType Type { get; set; } + /// + /// 名称 + /// + public string Name { get; set; } + /// + /// 开始时间 + /// + public DateTime BeginTime { get; set; } + /// + /// 截止时间 + /// + public DateTime EndTime { get; set; } + /// + /// 优先级 + /// + public int Priority { get; set; } + + /// + /// 最后编辑时间 + /// + public DateTime LastEditTime { get; set; } + + /// + /// 是否隐藏 + /// + public bool IsHidden { get; set; } + + /// + /// 是否可以评论 + /// + public bool CanComment { get; set; } + } +} diff --git a/CnGalWebSite/CnGalWebSite.DrawingBed.Helper/Services/FileUploadService.cs b/CnGalWebSite/CnGalWebSite.DrawingBed.Helper/Services/FileUploadService.cs index 9e2f5d394..f2c5d8907 100644 --- a/CnGalWebSite/CnGalWebSite.DrawingBed.Helper/Services/FileUploadService.cs +++ b/CnGalWebSite/CnGalWebSite.DrawingBed.Helper/Services/FileUploadService.cs @@ -34,20 +34,20 @@ public FileUploadService(ILogger logger, IHttpService httpSer _baseUrl = configuration["ImageApiPath"]; } - public async Task UploadImagesAsync(IBrowserFile file, ImageAspectType type) + public async Task UploadImagesAsync(IBrowserFile file, ImageAspectType type,bool gallery) { using var fileContent = new StreamContent(file.OpenReadStream(file.Size)); - return await UploadImagesAsync(fileContent, file.Name, type, file.Size); + return await UploadImagesAsync(fileContent, file.Name, type, gallery); } - public async Task UploadImagesAsync(byte[] bytes, string fileName, ImageAspectType type) + public async Task UploadImagesAsync(byte[] bytes, string fileName, ImageAspectType type, bool gallery) { //复制数据 using var fileContent = new StreamContent(new MemoryStream(bytes)); - return await UploadImagesAsync(fileContent, fileName, type, bytes.LongLength); + return await UploadImagesAsync(fileContent, fileName, type, gallery); } - public async Task UploadImagesAsync(StreamContent steam, string fileName, ImageAspectType type, long size) + public async Task UploadImagesAsync(StreamContent steam, string fileName, ImageAspectType type, bool gallery) { using var content = new MultipartFormDataContent(); @@ -81,7 +81,7 @@ public async Task UploadImagesAsync(StreamContent steam, string fi break; } var client = await _httpService.GetClientAsync(); - var response = await client.PostAsync($"{_baseUrl}api/files/Upload?x={x}&y={y}", content); + var response = await client.PostAsync($"{_baseUrl}api/files/Upload?x={x}&y={y}&gallery={gallery}", content); var newUploadResults = await response.Content .ReadFromJsonAsync>(); diff --git a/CnGalWebSite/CnGalWebSite.DrawingBed.Helper/Services/IFileUploadService.cs b/CnGalWebSite/CnGalWebSite.DrawingBed.Helper/Services/IFileUploadService.cs index 09c1d9013..77a238365 100644 --- a/CnGalWebSite/CnGalWebSite.DrawingBed.Helper/Services/IFileUploadService.cs +++ b/CnGalWebSite/CnGalWebSite.DrawingBed.Helper/Services/IFileUploadService.cs @@ -12,9 +12,9 @@ namespace CnGalWebSite.DrawingBed.Helper.Services { public interface IFileUploadService { - Task UploadImagesAsync(IBrowserFile file, ImageAspectType type); + Task UploadImagesAsync(IBrowserFile file, ImageAspectType type, bool gallery); - Task UploadImagesAsync(byte[] bytes, string fileName, ImageAspectType type); + Task UploadImagesAsync(byte[] bytes, string fileName, ImageAspectType type, bool gallery); Task UploadAudioAsync(IBrowserFile file); diff --git a/CnGalWebSite/CnGalWebSite.DrawingBed/Controllers/FileController.cs b/CnGalWebSite/CnGalWebSite.DrawingBed/Controllers/FileController.cs index 40918803d..7e3901473 100644 --- a/CnGalWebSite/CnGalWebSite.DrawingBed/Controllers/FileController.cs +++ b/CnGalWebSite/CnGalWebSite.DrawingBed/Controllers/FileController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using System.IO; using System.Text; namespace CnGalWebSite.DrawingBed.Controllers @@ -20,10 +21,11 @@ public class FileController : ControllerBase private readonly IConfiguration _configuration; private readonly IHttpClientFactory _clientFactory; private readonly IFileService _fileService; + private readonly IUploadService _uploadService; private readonly IQueryService _queryService; private readonly IRepository _uploadRecordRepository; - public FileController(IHttpClientFactory clientFactory, IWebHostEnvironment webHostEnvironment, IConfiguration configuration, IFileService fileService, IQueryService queryService, IRepository uploadRecordRepository) + public FileController(IHttpClientFactory clientFactory, IWebHostEnvironment webHostEnvironment, IConfiguration configuration, IFileService fileService, IQueryService queryService, IRepository uploadRecordRepository, IUploadService uploadService) { _clientFactory = clientFactory; _webHostEnvironment = webHostEnvironment; @@ -31,18 +33,16 @@ public FileController(IHttpClientFactory clientFactory, IWebHostEnvironment webH _fileService = fileService; _queryService = queryService; _uploadRecordRepository = uploadRecordRepository; + _uploadService = uploadService; } /// /// 上传图片 /// - /// - /// - /// /// [HttpPost] [AllowAnonymous] - public async Task>> UploadAsync([FromForm] List files, [FromQuery] double x, [FromQuery] double y, [FromQuery] UploadFileType type) + public async Task>> UploadAsync([FromForm] List files, [FromQuery] double x, [FromQuery] double y, [FromQuery] UploadFileType type, [FromQuery] bool gallery=false) { if (files.Count == 0) { @@ -53,7 +53,7 @@ public async Task>> UploadAsync([FromForm] List< { try { - model.Add(await _fileService.UploadFormFile(item, x, y, type)); + model.Add(await _fileService.UploadFormFile(item,gallery, x, y, type)); } catch (Exception ex) { @@ -73,11 +73,10 @@ public async Task>> UploadAsync([FromForm] List< /// /// 转存图片 /// - /// /// [HttpPost] [AllowAnonymous] - public async Task> linkToImgUrlAsync([FromQuery] string url, [FromQuery] double x, [FromQuery] double y, [FromQuery] UploadFileType type) + public async Task> linkToImgUrlAsync([FromQuery] string url, [FromQuery] double x, [FromQuery] double y, [FromQuery] UploadFileType type, [FromQuery] bool gallery = false) { if (string.IsNullOrWhiteSpace(url)) { @@ -102,7 +101,7 @@ public async Task> linkToImgUrlAsync([FromQuery] stri try { - var result= await _fileService.TransferDepositFile(url, x, y, type); + var result= await _fileService.TransferDepositFile(url,gallery, x, y, type); return result; } @@ -119,6 +118,42 @@ public async Task> linkToImgUrlAsync([FromQuery] stri } + /// + /// 转存图片到TucangCC + /// + /// + [HttpGet] + [AllowAnonymous] + public async Task> TransferDepositToTucangCCAsync([FromQuery] string url) + { + string path=""; + try + { + path = await _fileService.SaveFileFromUrl(url, UploadFileType.Image); + var result = await _uploadService.UploadToTucangCC(path); + _fileService.DeleteFile(path); + + return new UploadResult + { + Url = result, + OriginalUrl = url, + Uploaded=true + }; + } + catch (Exception ex) + { + _fileService.DeleteFile(path); + return new UploadResult + { + Uploaded = false, + OriginalUrl = url, + Error = ex.Message + }; + } + + } + + [HttpPost] public async Task> List(QueryParameterModel model) { diff --git a/CnGalWebSite/CnGalWebSite.DrawingBed/Services/FileService.cs b/CnGalWebSite/CnGalWebSite.DrawingBed/Services/FileService.cs index b0f21963c..dcebe60db 100644 --- a/CnGalWebSite/CnGalWebSite.DrawingBed/Services/FileService.cs +++ b/CnGalWebSite/CnGalWebSite.DrawingBed/Services/FileService.cs @@ -5,6 +5,7 @@ using COSXML.Auth; using FFmpeg.NET; using MediaInfo; +using Newtonsoft.Json.Linq; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Processing; using System.Security.Policy; @@ -17,7 +18,7 @@ public class FileService : IFileService { private readonly IWebHostEnvironment _webHostEnvironment; private readonly IConfiguration _configuration; - private readonly HttpClient _httpClient; + private readonly IHttpClientFactory _httpClientFactory; private readonly string _imageTempPath = ""; private readonly string _audioTempPath = ""; private readonly string _fileTempPath = ""; @@ -25,9 +26,9 @@ public class FileService : IFileService private readonly IUploadService _uploadService; private readonly IRecordService _recordService; - public FileService(HttpClient httpClient, IWebHostEnvironment webHostEnvironment, IConfiguration configuration, ILogger logger ,IUploadService uploadService, IRecordService recordService) + public FileService(IHttpClientFactory httpClientFactory, IWebHostEnvironment webHostEnvironment, IConfiguration configuration, ILogger logger ,IUploadService uploadService, IRecordService recordService) { - _httpClient = httpClient; + _httpClientFactory = httpClientFactory; _webHostEnvironment = webHostEnvironment; _configuration = configuration; _logger = logger; @@ -43,7 +44,7 @@ public FileService(HttpClient httpClient, IWebHostEnvironment webHostEnvironment Directory.CreateDirectory(_audioTempPath); } - public async Task TransferDepositFile(string url, double x = 0, double y = 0, UploadFileType type = UploadFileType.Image) + public async Task TransferDepositFile(string url,bool gallery , double x = 0, double y = 0, UploadFileType type = UploadFileType.Image ) { string pathSaveFile = null; string pathCutFile = null; @@ -87,7 +88,7 @@ public async Task TransferDepositFile(string url, double x = 0, do } else { - model.Url = await UploadLocalFileToServer(pathCompressFile, sha1, type); + model.Url = await UploadLocalFileToServer(pathCompressFile, sha1, type, gallery); //添加文件上传记录 await _recordService.Add(model); } @@ -108,7 +109,7 @@ public async Task TransferDepositFile(string url, double x = 0, do } } - public async Task UploadFormFile(IFormFile file, double x = 0, double y = 0, UploadFileType type = UploadFileType.Image) + public async Task UploadFormFile(IFormFile file,bool gallery, double x = 0, double y = 0,UploadFileType type = UploadFileType.Image ) { string pathSaveFile = null; string pathCompressFile = null; @@ -117,7 +118,7 @@ public async Task UploadFormFile(IFormFile file, double x = 0, dou try { - pathSaveFile = SaveFormFile(file, type); + pathSaveFile =await SaveFormFile(file, type); if (type == UploadFileType.Image) { @@ -145,7 +146,7 @@ public async Task UploadFormFile(IFormFile file, double x = 0, dou if (string.IsNullOrWhiteSpace(model.Url)) { - model.Url = await UploadLocalFileToServer(pathCompressFile, sha1, type); + model.Url = await UploadLocalFileToServer(pathCompressFile, sha1, type,gallery); //添加文件上传记录 await _recordService.Add(model); } @@ -168,21 +169,26 @@ public async Task UploadFormFile(IFormFile file, double x = 0, dou #region 上传文件 - private async Task UploadLocalFileToServer(string filePath,string shar1, UploadFileType type) + private async Task UploadLocalFileToServer(string filePath,string shar1, UploadFileType type, bool gallery) { - return 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) + { + url = await _uploadService.UploadToTucangCC(filePath)+"?"+ url; + } + return url; + } #endregion + + #region 处理文件 private static string GetFileSuffixName(string path, UploadFileType type) { @@ -192,13 +198,14 @@ private static string GetFileSuffixName(string path, UploadFileType type) return Suffix.Length > 4 ? defaultName : Suffix; } - private string SaveFormFile(IFormFile file, UploadFileType type) + private async Task SaveFormFile(IFormFile file, UploadFileType type) { - var tempName = Guid.NewGuid().ToString() + "." + GetFileSuffixName(file.FileName, type); + var tempName = new Random().Next() + "." + GetFileSuffixName(file.FileName, type); //保存图片到本地 var newPath = Path.Combine(type switch { UploadFileType.Image => _imageTempPath, UploadFileType.Audio => _audioTempPath, _ => _fileTempPath }, tempName); - SaveFile(file, newPath); + using var steam = file.OpenReadStream(); + await SaveFile(steam, newPath); _logger.LogInformation("保存客户端传输的文件:{file}" ,file.FileName); @@ -207,51 +214,24 @@ private string SaveFormFile(IFormFile file, UploadFileType type) public async Task SaveFileFromUrl(string url, UploadFileType type) { - var Bytes = await _httpClient.GetByteArrayAsync(url); - - - using Stream stream = new MemoryStream(Bytes); - IFormFile image = new FormFile(stream, 0, stream.Length, ".png", "测试.png"); + if (url.Contains("http") == false) + { + url = "https:" + url; + } - var tempName = Guid.NewGuid().ToString() + "." + GetFileSuffixName(url,type); + var response = await _httpClientFactory.CreateClient().GetAsync(url); + 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); - SaveFile(image, newPath); + await SaveFile(stream, newPath); _logger.LogInformation( "下载远程链接里的文件:{file}" ,url); return newPath; } - - private static string GetFileBase64(string path) - { - using var fsForRead = new FileStream(path, FileMode.Open); - string base64Str; - try - { - //读入一个字节 - //读写指针移到距开头10个字节处 - _ = fsForRead.Seek(0, SeekOrigin.Begin); - var bs = new byte[fsForRead.Length]; - var log = Convert.ToInt32(fsForRead.Length); - //从文件中读取10个字节放到数组bs中 - _ = fsForRead.Read(bs, 0, log); - base64Str = Convert.ToBase64String(bs); - - return base64Str; - } - catch - { - } - finally - { - fsForRead.Close(); - } - return ""; - } - private string GetSHA1(string path) { try @@ -275,20 +255,12 @@ private string GetSHA1(string path) } } - private static void SaveFile(IFormFile sourceFile, string destinationPath) + private static async Task SaveFile(Stream file, string destinationPath) { - using var stmMemory = new MemoryStream(); - using var stream = sourceFile.OpenReadStream(); - var buffer = new byte[stream.Length]; - int i; - //将字节逐个放入到Byte中 - while ((i = stream.Read(buffer, 0, buffer.Length)) > 0) - { - stmMemory.Write(buffer, 0, i); - } - - using var fs = new FileStream(destinationPath, FileMode.OpenOrCreate); - stmMemory.WriteTo(fs); + using var fs = File.Create(destinationPath); + await file.CopyToAsync(fs); + file.Close(); + fs.Close(); } #endregion @@ -440,7 +412,7 @@ private bool DeleteFiles(string path) } - private void DeleteFile(string path) + public void DeleteFile(string path) { if (string.IsNullOrWhiteSpace(path)) { diff --git a/CnGalWebSite/CnGalWebSite.DrawingBed/Services/IFileService.cs b/CnGalWebSite/CnGalWebSite.DrawingBed/Services/IFileService.cs index b60e4d5c5..dd11e345c 100644 --- a/CnGalWebSite/CnGalWebSite.DrawingBed/Services/IFileService.cs +++ b/CnGalWebSite/CnGalWebSite.DrawingBed/Services/IFileService.cs @@ -5,8 +5,12 @@ namespace CnGalWebSite.DrawingBed.Services { public interface IFileService { - Task TransferDepositFile(string url, double x = 0, double y = 0, UploadFileType type = UploadFileType.Image); + Task TransferDepositFile(string url, bool gallery,double x = 0, double y = 0, UploadFileType type = UploadFileType.Image ); - Task UploadFormFile(IFormFile file, double x = 0, double y = 0, UploadFileType type = UploadFileType.Image); + Task UploadFormFile(IFormFile file,bool gallery, double x = 0, double y = 0, UploadFileType type = UploadFileType.Image); + + Task SaveFileFromUrl(string url, UploadFileType type); + + void DeleteFile(string path); } } diff --git a/CnGalWebSite/CnGalWebSite.DrawingBed/Services/IUploadService.cs b/CnGalWebSite/CnGalWebSite.DrawingBed/Services/IUploadService.cs index cd0e9f489..5c34ea6ea 100644 --- a/CnGalWebSite/CnGalWebSite.DrawingBed/Services/IUploadService.cs +++ b/CnGalWebSite/CnGalWebSite.DrawingBed/Services/IUploadService.cs @@ -5,5 +5,7 @@ public interface IUploadService Task UploadToTencentOSS(string filePath, string shar1); Task UploadToAliyunOSS(string filePath, string shar1); + + Task UploadToTucangCC(string filePath); } } diff --git a/CnGalWebSite/CnGalWebSite.DrawingBed/Services/UploadService.cs b/CnGalWebSite/CnGalWebSite.DrawingBed/Services/UploadService.cs index 44f297fe9..54f405dad 100644 --- a/CnGalWebSite/CnGalWebSite.DrawingBed/Services/UploadService.cs +++ b/CnGalWebSite/CnGalWebSite.DrawingBed/Services/UploadService.cs @@ -7,6 +7,7 @@ using System.Security.AccessControl; using System.Security.Policy; using Aliyun.OSS; +using Newtonsoft.Json.Linq; namespace CnGalWebSite.DrawingBed.Services { @@ -14,16 +15,18 @@ public class UploadService : IUploadService { private readonly ILogger _logger; private readonly IConfiguration _configuration; + private readonly HttpClient _httpClient; private string _aliyunBucketName; private CosXml _tencentCosXml; private OssClient _aliyunOssClient; - public UploadService(ILogger logger, IConfiguration configuration) + public UploadService(ILogger logger, IConfiguration configuration, HttpClient httpClient) { _logger = logger; _configuration = configuration; + _httpClient = httpClient; InitTencentOSS(); InitAliyunOSS(); @@ -114,5 +117,49 @@ public async Task UploadToTencentOSS(string filePath, string shar1) throw; } } + + /// + /// 转存图片到公共图床 + /// + /// + public async Task UploadToTucangCC(string filePath) + { + try + { + using var content = new MultipartFormDataContent(); + using var fileContent = new StreamContent(File.OpenRead(filePath)); + + content.Add( + content: fileContent, + name: "file", + fileName: "test.png"); + content.Add(new StringContent(_configuration["TucangCCAPIToken"]), "token"); + + var response = await _httpClient.PostAsync(_configuration["TucangCCAPIUrl"], content); + + var newUploadResults = await response.Content.ReadAsStringAsync(); + var result = JObject.Parse(newUploadResults); + + if (result["code"].ToObject() == 200) + { + + var url= $"{_configuration["CustomTucangCCUrl"]}{result["data"]["url"].ToObject().Split('/').LastOrDefault()}"; + await _httpClient.GetAsync(url); + _logger.LogInformation("成功上传图片到TucangCC:{url}", url); + return url; + } + else + { + _logger.LogError("转存图片失败,接口返回代码:{code},消息:{msg},图片:{filePath}", result["code"].ToObject(), result["msg"].ToObject(), filePath); + throw new Exception("转存图片失败"); + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "转存图片失败:{filePath}", filePath); + throw; + } + } } } diff --git a/CnGalWebSite/CnGalWebSite.DrawingBed/appsettings.json b/CnGalWebSite/CnGalWebSite.DrawingBed/appsettings.json index be1da6905..e25255948 100644 --- a/CnGalWebSite/CnGalWebSite.DrawingBed/appsettings.json +++ b/CnGalWebSite/CnGalWebSite.DrawingBed/appsettings.json @@ -2,7 +2,9 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Microsoft.AspNetCore": "Warning", + "Microsoft.EntityFrameworkCore": "Warning", + "System.Net.Http.HttpClient": "Warning" } }, //OSS相关 diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/EditCard.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/EditCard.razor new file mode 100644 index 000000000..be0b6b303 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/EditCard.razor @@ -0,0 +1,116 @@ +@inject IHttpService _httpService +@inject IPopupService PopupService + + +@if (Model == null) +{ + + + + + +} +else +{ + + + @(Id == 0 ? $"添加{_name}" : $"编辑{_name}") @Model.Note + + + Id:@Model.Id + + + + + + + + + + + + + + + + + + + + + + + + + mdi-check + 保存 + + + +} + + + +@code { + [Parameter] + public long Id { get; set; } + [Parameter] + public EventCallback OnEdited { get; set; } + + CarouselEditModel Model; + + private string _baseUrl = "api/home/EditCarousel"; + private string _name = "轮播图"; + + + [CascadingParameter] + public ErrorHandler ErrorHandler { get; set; } + + protected override async Task OnInitializedAsync() + { + await Refresh(); + } + + public async Task Refresh() + { + try + { + Model = null; + StateHasChanged(); + Model = Id == 0 ? new CarouselEditModel() : await _httpService.GetAsync($"{_baseUrl}?id={Id}"); + StateHasChanged(); + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, $"获取{_name}信息失败"); + } + } + + public async Task SaveEdit() + { + try + { + var result = await _httpService.PostAsync($"{_baseUrl}", Model); + if (result.Successful) + { + if (!string.IsNullOrWhiteSpace(result.Error)) + { + await PopupService.EnqueueSnackbarAsync(result.Error, AlertTypes.Success); + } + await OnEdited.InvokeAsync(Model); + StateHasChanged(); + } + else + { + await PopupService.EnqueueSnackbarAsync(result.Error ?? "操作失败", AlertTypes.Error); + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, Model.Id == 0 ? $"添加{_name}失败" : $"编辑{_name}信息失败"); + } + + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/LinkChip.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/LinkChip.razor new file mode 100644 index 000000000..2980ea7b9 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/LinkChip.razor @@ -0,0 +1,14 @@ +@inject IEventService _eventService + + + + + @code { + [Parameter] + public string Link { get; set; } + + public void OnClick() + { + _eventService.OpenNewPage(Link); + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/ListCard.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/ListCard.razor new file mode 100644 index 000000000..c64e5b5b9 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/ListCard.razor @@ -0,0 +1,130 @@ +@inject IHttpService _httpService +@inject IPopupService PopupService +@inject NavigationManager NavigationManager + + + + @if (context.Header.Value == "actions") + { +
+ @IconType.Edit.ToIconString() + @IconType.Up.ToIconString() + @IconType.Down.ToIconString() +
+ } + else if (context.Header.Value == nameof(CarouselOverviewModel.Type)) + { + + } + else if (context.Header.Value == nameof(CarouselOverviewModel.Image)) + { + + } + else if (context.Header.Value == nameof(CarouselOverviewModel.Link)) + { + + } + else + { + @context.Value + } +
+
+ + + +@code { + private string _baseUrl = "api/home/ListCarousels"; + private string _name = "轮播图"; + + private List> _headers = new List> +{ + new () + { + Text= "Id", + Align= DataTableHeaderAlign.Start, + Value= nameof(CarouselOverviewModel.Id) + }, + new (){ Text= "类型", Value= nameof(CarouselOverviewModel.Type)}, + new (){ Text= "图片", Value= nameof(CarouselOverviewModel.Image)}, + new (){ Text= "备注", Value= nameof(CarouselOverviewModel.Note)}, + new (){ Text= "链接", Value= nameof(CarouselOverviewModel.Link)}, + new (){ Text= "优先级", Value= nameof(CarouselOverviewModel.Priority)}, + new (){ Text= "操作", Value= "actions",Sortable=false } + }; + + DataTableCard dataTableCard; + + EditCard editCard; + private bool _editDialog; + private long _editedItemId; + private bool _detailDialog; + + + [CascadingParameter] + public ErrorHandler ErrorHandler { get; set; } + + public async void EditItem(CarouselOverviewModel item) + { + _editedItemId = item.Id; + _editDialog = true; + StateHasChanged(); + if (editCard != null) + { + await editCard.Refresh(); + } + } + + public void OnEdited() + { + _editDialog = false; + StateHasChanged(); + if (dataTableCard != null) + { + dataTableCard.GetDataFromApi(); + } + } + + public async Task AddItem() + { + _editedItemId = 0; + _editDialog = true; + StateHasChanged(); + if (editCard != null) + { + await editCard.Refresh(); + } + } + + public async Task EditItemPriority(CarouselOverviewModel model, bool up) + { + string operationName = up ? "增权重" : "降权重"; + try + { + var obj = await _httpService.PostAsync("api/home/EditCarouselPriority", new EditEntryPriorityViewModel { Ids = new int[] { model.Id }, PlusPriority = up ? 1 : -1 }); + + if (obj.Successful == false) + { + await PopupService.EnqueueSnackbarAsync(operationName + "失败", obj.Error, AlertTypes.Error); + } + else + { + + await PopupService.EnqueueSnackbarAsync(operationName + "成功", AlertTypes.Success); + dataTableCard.GetDataFromApi(); + + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, operationName + "失败"); + } + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/TypeChip.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/TypeChip.razor new file mode 100644 index 000000000..54fcd0e0c --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Carousels/TypeChip.razor @@ -0,0 +1,28 @@ + + + + + @code { + [Parameter] + public CarouselType Type { get; set; } + + public string GetColor(CarouselType type) + { + return type switch + { + CarouselType.Home => "success", + CarouselType.ThematicPage => "info", + _ => "purple", + }; + } + + public IconType GetIcon(CarouselType type) + { + return type switch + { + CarouselType.Home => IconType.Home, + CarouselType.ThematicPage => IconType.Dub, + _ => IconType.UnknowTime, + }; + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/FriendLinks/EditCard.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/FriendLinks/EditCard.razor new file mode 100644 index 000000000..c70b206f3 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/FriendLinks/EditCard.razor @@ -0,0 +1,113 @@ +@inject IHttpService _httpService +@inject IPopupService PopupService + + +@if (Model == null) +{ + + + + + +} +else +{ + + + @(Id == 0 ? $"添加{_name}" : $"编辑{_name}") @Model.Name + + + Id:@Model.Id + + + + + + + + + + + + + + + + + + + + + + mdi-check + 保存 + + + +} + + + +@code { + [Parameter] + public long Id { get; set; } + [Parameter] + public EventCallback OnEdited { get; set; } + + FriendLinkEditModel Model; + + private string _baseUrl = "api/home/EditFriendLink"; + private string _name = "友情链接"; + + + [CascadingParameter] + public ErrorHandler ErrorHandler { get; set; } + + protected override async Task OnInitializedAsync() + { + await Refresh(); + } + + public async Task Refresh() + { + try + { + Model = null; + StateHasChanged(); + Model = Id == 0 ? new FriendLinkEditModel() : await _httpService.GetAsync($"{_baseUrl}?id={Id}"); + StateHasChanged(); + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, $"获取{_name}信息失败"); + } + } + + public async Task SaveEdit() + { + try + { + var result = await _httpService.PostAsync($"{_baseUrl}", Model); + if (result.Successful) + { + if (!string.IsNullOrWhiteSpace(result.Error)) + { + await PopupService.EnqueueSnackbarAsync(result.Error, AlertTypes.Success); + } + await OnEdited.InvokeAsync(Model); + StateHasChanged(); + } + else + { + await PopupService.EnqueueSnackbarAsync(result.Error ?? "操作失败", AlertTypes.Error); + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, Model.Id == 0 ? $"添加{_name}失败" : $"编辑{_name}信息失败"); + } + + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/FriendLinks/ListCard.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/FriendLinks/ListCard.razor new file mode 100644 index 000000000..3acad1442 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/FriendLinks/ListCard.razor @@ -0,0 +1,125 @@ +@inject IHttpService _httpService +@inject IPopupService PopupService +@inject NavigationManager NavigationManager + + + + @if (context.Header.Value == "actions") + { +
+ @IconType.Edit.ToIconString() + @IconType.Up.ToIconString() + @IconType.Down.ToIconString() +
+ } + else if (context.Header.Value == nameof(CarouselOverviewModel.Image)) + { + + } + else if (context.Header.Value == nameof(CarouselOverviewModel.Link)) + { + + } + else + { + @context.Value + } +
+
+ + + +@code { + private string _baseUrl = "api/home/ListFriendLinks"; + private string _name = "友情链接"; + + private List> _headers = new List> +{ + new () + { + Text= "Id", + Align= DataTableHeaderAlign.Start, + Value= nameof(FriendLinkOverviewModel.Id) + }, + new (){ Text= "图片", Value= nameof(FriendLinkOverviewModel.Image)}, + new (){ Text= "备注", Value= nameof(FriendLinkOverviewModel.Name)}, + new (){ Text= "链接", Value= nameof(FriendLinkOverviewModel.Link)}, + new (){ Text= "优先级", Value= nameof(FriendLinkOverviewModel.Priority)}, + new (){ Text= "操作", Value= "actions",Sortable=false } + }; + + DataTableCard dataTableCard; + + EditCard editCard; + private bool _editDialog; + private long _editedItemId; + private bool _detailDialog; + + + [CascadingParameter] + public ErrorHandler ErrorHandler { get; set; } + + public async void EditItem(FriendLinkOverviewModel item) + { + _editedItemId = item.Id; + _editDialog = true; + StateHasChanged(); + if (editCard != null) + { + await editCard.Refresh(); + } + } + + public void OnEdited() + { + _editDialog = false; + StateHasChanged(); + if (dataTableCard != null) + { + dataTableCard.GetDataFromApi(); + } + } + + public async Task AddItem() + { + _editedItemId = 0; + _editDialog = true; + StateHasChanged(); + if (editCard != null) + { + await editCard.Refresh(); + } + } + + public async Task EditItemPriority(FriendLinkOverviewModel model, bool up) + { + string operationName = up ? "增权重" : "降权重"; + try + { + var obj = await _httpService.PostAsync("api/home/EditFriendLinkPriority", new EditEntryPriorityViewModel { Ids = new int[] { model.Id }, PlusPriority = up ? 1 : -1 }); + + if (obj.Successful == false) + { + await PopupService.EnqueueSnackbarAsync(operationName + "失败", obj.Error, AlertTypes.Error); + } + else + { + + await PopupService.EnqueueSnackbarAsync(operationName + "成功", AlertTypes.Success); + dataTableCard.GetDataFromApi(); + + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, operationName + "失败"); + } + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Lotteries/IsEndChip.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Lotteries/IsEndChip.razor new file mode 100644 index 000000000..5badc7494 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Lotteries/IsEndChip.razor @@ -0,0 +1,25 @@ + + + + @code { + [Parameter] + public bool IsEnd { get; set; } + + public string GetColor() + { + return IsEnd switch + { + true => "success", + false => "info" + }; + } + + public IconType GetIcon() + { + return IsEnd switch + { + false => IconType.State, + true => IconType.Check, + }; + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Lotteries/ListCard.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Lotteries/ListCard.razor new file mode 100644 index 000000000..2ee520284 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Lotteries/ListCard.razor @@ -0,0 +1,198 @@ +@inject IHttpService _httpService +@inject IPopupService PopupService +@inject NavigationManager NavigationManager + + + + @if (context.Header.Value == "actions") + { +
+ @IconType.Up.ToIconString() + @IconType.Down.ToIconString() + @if (context.Item.CanComment) + { + @IconType.DisableComment.ToIconString() + } + else + { + @IconType.Comment.ToIconString() + } + @if (context.Item.IsHidden) + { + @IconType.Check.ToIconString() + } + else + { + @IconType.Close.ToIconString() + } + +
+ } + else if (context.Header.Value == nameof(LotteryOverviewModel.IsHidden)) + { + + } + else if (context.Header.Value == nameof(LotteryOverviewModel.Name)) + { + + } + else if (context.Header.Value == nameof(LotteryOverviewModel.IsEnd)) + { + + } + else if (context.Header.Value == nameof(LotteryOverviewModel.Type)) + { + @context.Item.Type.GetDisplayName() + } + else if (context.Header.Value == nameof(LotteryOverviewModel.LotteryTime)) + { + @if(context.Item.LotteryTime.Year==1) + { + @("无") + } + else + { + @context.Item.LotteryTime.ToString("yyyy-MM-dd HH:mm") + } + } + else if (context.Header.Value == nameof(LotteryOverviewModel.BeginTime)) + { + @context.Item.BeginTime.ToString("yyyy-MM-dd HH:mm") + } + else if (context.Header.Value == nameof(LotteryOverviewModel.EndTime)) + { + @context.Item.EndTime.ToString("yyyy-MM-dd HH:mm") + } + else if (context.Header.Value == nameof(LotteryOverviewModel.LastEditTime)) + { + @context.Item.LastEditTime.ToString("yyyy-MM-dd HH:mm") + } + else if (context.Header.Value == nameof(LotteryOverviewModel.CanComment)) + { + + } + else + { + @context.Value + } +
+
+ +@code { + private string _baseUrl = "api/lotteries/List"; + private string _name = "抽奖"; + + private List> _headers = new List> +{ + new () + { + Text= "Id", + Align= DataTableHeaderAlign.Start, + Value= nameof(LotteryOverviewModel.Id) + }, + new (){ Text= "类型", Value= nameof(LotteryOverviewModel.Type)}, + new (){ Text= "名称", Value= nameof(LotteryOverviewModel.Name)}, + new (){ Text= "抽奖时间", Value= nameof(LotteryOverviewModel.LotteryTime)}, + new (){ Text= "开始时间", Value= nameof(LotteryOverviewModel.BeginTime)}, + new (){ Text= "结束时间", Value= nameof(LotteryOverviewModel.EndTime)}, + new (){ Text= "最后编辑时间", Value= nameof(LotteryOverviewModel.LastEditTime)}, + new (){ Text= "优先级", Value= nameof(LotteryOverviewModel.Priority)}, + new (){ Text= "状态", Value= nameof(LotteryOverviewModel.IsEnd)}, + new (){ Text= "状态", Value= nameof(LotteryOverviewModel.IsHidden)}, + new (){ Text= "留言板", Value= nameof(LotteryOverviewModel.CanComment)}, + new (){ Text= "操作", Value= "actions",Sortable=false } + }; + + DataTableCard dataTableCard; + + [CascadingParameter] + public ErrorHandler ErrorHandler { get; set; } + + + public async Task EditItemPriority(LotteryOverviewModel model, bool up) + { + string operationName = up ? "增权重" : "降权重"; + try + { + var obj = await _httpService.PostAsync("api/Lotteries/EditLotteryPriority", new EditLotteryPriorityViewModel { Ids = new long[] { model.Id }, PlusPriority = up?1:-1 }); + + if (obj.Successful == false) + { + await PopupService.EnqueueSnackbarAsync(operationName + "失败", obj.Error, AlertTypes.Error); + } + else + { + + await PopupService.EnqueueSnackbarAsync(operationName + "成功", AlertTypes.Success); + dataTableCard.GetDataFromApi(); + + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, operationName + "失败"); + } + } + + public async Task HideItem(LotteryOverviewModel model, bool isHidden) + { + string operationName = (isHidden ? "隐藏" : "显示") + _name; + try + { + var obj = await _httpService.PostAsync("api/Lotteries/HiddenLottery", new HiddenLotteryModel { Ids = new long[] { model.Id }, IsHidden = isHidden }); + + if (obj.Successful == false) + { + await PopupService.EnqueueSnackbarAsync(operationName + "失败", obj.Error, AlertTypes.Error); + } + else + { + + await PopupService.EnqueueSnackbarAsync(operationName + "成功", AlertTypes.Success); + dataTableCard.GetDataFromApi(); + + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, operationName + "失败"); + } + } + + public async Task EditItemCanComment(LotteryOverviewModel model, bool canComment) + { + string operationName = canComment ? "开启留言板" : "关闭留言板"; + try + { + var obj = await _httpService.PostAsync("api/comments/EditLotteryCanComment", new EditLotteryCanCommentModel { Ids = new long[] { model.Id }, CanComment = canComment }); + + if (obj.Successful == false) + { + await PopupService.EnqueueSnackbarAsync(operationName + "失败", obj.Error, AlertTypes.Error); + } + else + { + + await PopupService.EnqueueSnackbarAsync(operationName + "成功", AlertTypes.Success); + dataTableCard.GetDataFromApi(); + + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, operationName + "失败"); + } + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Lotteries/LotteryChip.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Lotteries/LotteryChip.razor new file mode 100644 index 000000000..b584867f7 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Lotteries/LotteryChip.razor @@ -0,0 +1,18 @@ +@inject NavigationManager NavigationManager + + + + + @code { + [Parameter] + public string Name { get; set; } + [Parameter] + public long Id { get; set; } + + public void OnClick() + { + + NavigationManager.NavigateTo($"/lotteries/index/{Id}"); + + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Votes/ListCard.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Votes/ListCard.razor new file mode 100644 index 000000000..1f0ed5442 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Votes/ListCard.razor @@ -0,0 +1,181 @@ +@inject IHttpService _httpService +@inject IPopupService PopupService +@inject NavigationManager NavigationManager + + + + @if (context.Header.Value == "actions") + { +
+ @IconType.Up.ToIconString() + @IconType.Down.ToIconString() + @if (context.Item.CanComment) + { + @IconType.DisableComment.ToIconString() + } + else + { + @IconType.Comment.ToIconString() + } + @if (context.Item.IsHidden) + { + @IconType.Check.ToIconString() + } + else + { + @IconType.Close.ToIconString() + } + +
+ } + else if (context.Header.Value == nameof(VoteOverviewModel.IsHidden)) + { + + } + else if (context.Header.Value == nameof(VoteOverviewModel.Name)) + { + + } + else if (context.Header.Value == nameof(VoteOverviewModel.Type)) + { + @context.Item.Type.GetDisplayName() + } + else if (context.Header.Value == nameof(VoteOverviewModel.BeginTime)) + { + @context.Item.BeginTime.ToString("yyyy-MM-dd HH:mm") + } + else if (context.Header.Value == nameof(VoteOverviewModel.EndTime)) + { + @context.Item.EndTime.ToString("yyyy-MM-dd HH:mm") + } + else if (context.Header.Value == nameof(VoteOverviewModel.LastEditTime)) + { + @context.Item.LastEditTime.ToString("yyyy-MM-dd HH:mm") + } + else if (context.Header.Value == nameof(VoteOverviewModel.CanComment)) + { + + } + else + { + @context.Value + } +
+
+ +@code { + private string _baseUrl = "api/votes/List"; + private string _name = "投票"; + + private List> _headers = new List> +{ + new () + { + Text= "Id", + Align= DataTableHeaderAlign.Start, + Value= nameof(VoteOverviewModel.Id) + }, + new (){ Text= "类型", Value= nameof(VoteOverviewModel.Type)}, + new (){ Text= "名称", Value= nameof(VoteOverviewModel.Name)}, + new (){ Text= "开始时间", Value= nameof(VoteOverviewModel.BeginTime)}, + new (){ Text= "结束时间", Value= nameof(VoteOverviewModel.EndTime)}, + new (){ Text= "最后编辑时间", Value= nameof(VoteOverviewModel.LastEditTime)}, + new (){ Text= "优先级", Value= nameof(VoteOverviewModel.Priority)}, + new (){ Text= "状态", Value= nameof(VoteOverviewModel.IsHidden)}, + new (){ Text= "留言板", Value= nameof(VoteOverviewModel.CanComment)}, + new (){ Text= "操作", Value= "actions",Sortable=false } + }; + + DataTableCard dataTableCard; + + [CascadingParameter] + public ErrorHandler ErrorHandler { get; set; } + + + public async Task EditItemPriority(VoteOverviewModel model, bool up) + { + string operationName = up ? "增权重" : "降权重"; + try + { + var obj = await _httpService.PostAsync("api/votes/EditVotePriority", new EditVotePriorityViewModel { Ids = new long[] { model.Id }, PlusPriority = up?1:-1 }); + + if (obj.Successful == false) + { + await PopupService.EnqueueSnackbarAsync(operationName + "失败", obj.Error, AlertTypes.Error); + } + else + { + + await PopupService.EnqueueSnackbarAsync(operationName + "成功", AlertTypes.Success); + dataTableCard.GetDataFromApi(); + + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, operationName + "失败"); + } + } + + public async Task HideItem(VoteOverviewModel model, bool isHidden) + { + string operationName = (isHidden ? "隐藏" : "显示") + _name; + try + { + var obj = await _httpService.PostAsync("api/votes/HiddenVote", new HiddenVoteModel { Ids = new long[] { model.Id }, IsHidden = isHidden }); + + if (obj.Successful == false) + { + await PopupService.EnqueueSnackbarAsync(operationName + "失败", obj.Error, AlertTypes.Error); + } + else + { + + await PopupService.EnqueueSnackbarAsync(operationName + "成功", AlertTypes.Success); + dataTableCard.GetDataFromApi(); + + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, operationName + "失败"); + } + } + + public async Task EditItemCanComment(VoteOverviewModel model, bool canComment) + { + string operationName = canComment ? "开启留言板" : "关闭留言板"; + try + { + var obj = await _httpService.PostAsync("api/comments/EditVoteCanComment", new EditVoteCanCommentModel { Ids = new long[] { model.Id }, CanComment = canComment }); + + if (obj.Successful == false) + { + await PopupService.EnqueueSnackbarAsync(operationName + "失败", obj.Error, AlertTypes.Error); + } + else + { + + await PopupService.EnqueueSnackbarAsync(operationName + "成功", AlertTypes.Success); + dataTableCard.GetDataFromApi(); + + } + } + catch (Exception ex) + { + ErrorHandler.ProcessError(ex, operationName + "失败"); + } + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Votes/VoteChip.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Votes/VoteChip.razor new file mode 100644 index 000000000..31de96558 --- /dev/null +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/PC/Admin/Votes/VoteChip.razor @@ -0,0 +1,18 @@ +@inject NavigationManager NavigationManager + + + + + @code { + [Parameter] + public string Name { get; set; } + [Parameter] + public long Id { get; set; } + + public void OnClick() + { + + NavigationManager.NavigateTo($"/votes/index/{Id}"); + + } +} diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/Shared/Cards/Images/ImageCropperViewTip.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/Shared/Cards/Images/ImageCropperViewTip.razor index f68bcedeb..2e1438f27 100644 --- a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/Shared/Cards/Images/ImageCropperViewTip.razor +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/Shared/Cards/Images/ImageCropperViewTip.razor @@ -45,6 +45,8 @@ [Parameter] public EventCallback OnUploadedImage { get; set; } + [Parameter] + public bool Gallery { get; set; } private Cropper cropper; @@ -116,7 +118,7 @@ try { //上传 - var obj = await _fileUploadService.UploadImagesAsync(await args.GetDataAsync(), File.Name, Type); + var obj = await _fileUploadService.UploadImagesAsync(await args.GetDataAsync(), File.Name, Type, Gallery); if (obj.Uploaded == true) { @@ -145,7 +147,7 @@ { try { - var obj = await _fileUploadService.UploadImagesAsync(File, Type); + var obj = await _fileUploadService.UploadImagesAsync(File, Type, Gallery); if (obj.Uploaded == true) { diff --git a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/Shared/Editors/Buttons/ImageUploadButton.razor b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/Shared/Editors/Buttons/ImageUploadButton.razor index 949d1467f..817467b45 100644 --- a/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/Shared/Editors/Buttons/ImageUploadButton.razor +++ b/CnGalWebSite/CnGalWebSite.Shared.MasaComponent/Shared/Editors/Buttons/ImageUploadButton.razor @@ -67,7 +67,7 @@ - + @code { [Parameter] @@ -90,6 +90,8 @@ public IconType Icon { get; set; } = IconType.Upload; [Parameter] public string Class { get; set; } + [Parameter] + public bool Gallery { get; set; } private readonly string Id = "input" + new Random().Next(); bool isUploading; @@ -133,7 +135,7 @@ { try { - var obj = await _fileUploadService.UploadImagesAsync(file, Type); + var obj = await _fileUploadService.UploadImagesAsync(file, Type,Gallery); if (obj.Uploaded == true) { await ChangeImageUrl(obj.Url); diff --git a/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ListLotteries.razor b/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ListLotteries.razor index afa9722a3..52c9570ef 100644 --- a/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ListLotteries.razor +++ b/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ListLotteries.razor @@ -1,273 +1,7 @@ @page "/admin/listlotteries" @attribute [Authorize(Roles = "Admin")] -@inject IHttpService _httpService -@inject ToastService? ToastService -@inject IServiceProvider Provider -@inject NavigationManager NavigationManager -@inject IJSRuntime JS - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - -@code { - - [NotNull] - private Table? TableRows { get; set; } - private List SelectedRows { get; set; } = new(); - - - public ListLotteriesViewModel ListModel { get; set; } = new ListLotteriesViewModel { Lotteries = new List() }; - - private ListLotteryAloneModel SearchModelArticle { get; set; } = new ListLotteryAloneModel(); - - private IEnumerable PageItems => new int[] { 10, 20, 40, 80, 200, 5000 }; - - [CascadingParameter] - public ErrorHandler ErrorHandler { get; set; } - - protected override async Task OnInitializedAsync() - { - - } - - private async Task> OnQueryBasicAsync(QueryPageOptions options) - { - try - { - return await _httpService.PostAsync>("api/admin/GetLotteryList", new LotteriesPagesInfor { SearchModel = SearchModelArticle, Options = (QueryPageOptionsHelper)options }); - } - catch (Exception ex) - { - ErrorHandler.ProcessError(ex, "无法获取抽奖列表"); - return new QueryData(); - } - } - private async Task OnRowEditPriorityClick(long[] ids, int plusPriority, bool showMessage) - { - //调用API - try - { - var obj = await _httpService.PostAsync("api/Lotteries/EditLotteryPriority", new EditLotteryPriorityViewModel { Ids = ids, PlusPriority = plusPriority }); - if (obj.Successful == false) - { - await ToastService.Error("修改抽奖权重失败", obj.Error); - } - else - { - if (showMessage) - { - await ToastService.Success("修改抽奖权重成功", "修改抽奖权重成功"); - await TableRows.QueryAsync(); - } - - } - } - catch (Exception ex) - { - ErrorHandler.ProcessError(ex, "修改抽奖权重失败"); - } - - } - - - private async Task OnPriorityUpClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改抽奖权重", "请选中抽奖"); - return; - } - - await OnRowEditPriorityClick(items.Select(s => s.Id).ToArray(), 1, false); - await ToastService.Success("修改抽奖权重成功", "修改抽奖权重成功"); - await TableRows.QueryAsync(); - } - private async Task OnPriorityDownClick(IEnumerable items) - { - - if (items.Count() == 0) - { - await ToastService.Information("没有修改抽奖权重", "请选中抽奖"); - return; - } - - await OnRowEditPriorityClick(items.Select(s => s.Id).ToArray(), -1, false); - - await ToastService.Success("修改抽奖权重成功", "修改抽奖权重成功"); - await TableRows.QueryAsync(); - } - - private async Task OnRowEditIsHiddenClick(long[] ids, bool isHidden, bool showMessage) - { - string tempString = isHidden == true ? "隐藏" : "显示"; - //调用API - try - { - var obj = await _httpService.PostAsync("api/Lotteries/HiddenLottery", new HiddenLotteryModel { Ids = ids, IsHidden = isHidden }); - - - - if (obj.Successful == false) - { - await ToastService.Error(tempString + "抽奖失败", obj.Error); - } - else - { - if (showMessage) - { - await ToastService.Success(tempString + "抽奖成功", tempString + "抽奖成功"); - await TableRows.QueryAsync(); - } - } - } - catch (Exception ex) - { - ErrorHandler.ProcessError(ex, tempString + "抽奖失败"); - } - } - - private async Task OnHiddenClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改抽奖显示状态", "请选中抽奖"); - return; - } - - await OnRowEditIsHiddenClick(items.Select(s => s.Id).ToArray(), true, false); - - await ToastService.Success("隐藏抽奖成功", "隐藏抽奖成功"); - await TableRows.QueryAsync(); - } - private async Task OnUnHiddenClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改抽奖显示状态", "请选中抽奖"); - return; - } - - await OnRowEditIsHiddenClick(items.Select(s => s.Id).ToArray(), false, false); - - await ToastService.Success("显示抽奖成功", "显示抽奖成功"); - await TableRows.QueryAsync(); - } - - public void OnRowLookClick(long id, string name) - { - NavigationManager.NavigateTo(Provider, "/lotteries/index/" + id, name, "fa fa-gift"); - - } - public void OnRowEditClick(long id, string name) - { - NavigationManager.NavigateTo(Provider, "/lotteries/editlottery/" + id, "编辑投票", "fa fa-pencil"); - - } - - - private async Task OnRowEditCanCommentClick(long[] ids, bool canComment, bool showMessage) - { - string tempString = canComment == true ? "启用抽奖评论" : "关闭抽奖评论"; - //调用API - try - { - var obj = await _httpService.PostAsync("api/comments/EditLotteryCanComment", new EditLotteryCanCommentModel { Ids = ids, CanComment = canComment }); - - - - if (obj.Successful == false) - { - await ToastService.Error(tempString + "失败", obj.Error); - } - else - { - if (showMessage) - { - await ToastService.Success(tempString + "成功", tempString + "成功"); - await TableRows.QueryAsync(); - } - } - } - catch (Exception ex) - { - ErrorHandler.ProcessError(ex, tempString + "失败"); - } - } - - private async Task OnCanCommentClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改抽奖评论状态", "请选中抽奖"); - return; - } - - await OnRowEditCanCommentClick(items.Select(s => s.Id).ToArray(), true, false); - - await ToastService.Success("开启抽奖评论成功", "开启抽奖评论成功"); - await TableRows.QueryAsync(); - } - private async Task OnCanNotCommentClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改抽奖评论状态", "请选中抽奖"); - return; - } - - await OnRowEditCanCommentClick(items.Select(s => s.Id).ToArray(), false, false); - - await ToastService.Success("关闭抽奖评论成功", "关闭抽奖评论成功"); - await TableRows.QueryAsync(); - } - - - -} - + diff --git a/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ListVotes.razor b/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ListVotes.razor index ca5778fb6..7a3686065 100644 --- a/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ListVotes.razor +++ b/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ListVotes.razor @@ -1,266 +1,6 @@ @page "/admin/listvotes" @attribute [Authorize(Roles = "Admin")] -@inject IHttpService _httpService -@inject ToastService? ToastService -@inject IServiceProvider Provider -@inject NavigationManager NavigationManager -@inject IJSRuntime JS - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - -@code { - - [NotNull] - private Table? TableRows { get; set; } - private List SelectedRows { get; set; } = new(); - - - public ListVotesViewModel ListModel { get; set; } = new ListVotesViewModel { Votes = new List() }; - - private ListVoteAloneModel SearchModelArticle { get; set; } = new ListVoteAloneModel(); - - private IEnumerable PageItems => new int[] { 10, 20, 40, 80, 200, 5000 }; - - [CascadingParameter] - public ErrorHandler ErrorHandler { get; set; } - - protected override async Task OnInitializedAsync() - { - - } - - private async Task> OnQueryBasicAsync(QueryPageOptions options) - { - try - { - return await _httpService.PostAsync>("api/admin/GetVoteList", new VotesPagesInfor { SearchModel = SearchModelArticle, Options = (QueryPageOptionsHelper)options }); - } - catch (Exception ex) - { - ErrorHandler.ProcessError(ex, "无法获取投票列表"); - return new QueryData(); - } - } - private async Task OnRowEditPriorityClick(long[] ids, int plusPriority, bool showMessage) - { - //调用API - try - { - var obj = await _httpService.PostAsync("api/votes/EditVotePriority", new EditVotePriorityViewModel { Ids = ids, PlusPriority = plusPriority }); - if (obj.Successful == false) - { - await ToastService.Error("修改投票权重失败", obj.Error); - } - else - { - if (showMessage) - { - await ToastService.Success("修改投票权重成功", "修改投票权重成功"); - await TableRows.QueryAsync(); - } - - } - } - catch (Exception ex) - { - ErrorHandler.ProcessError(ex, "修改投票权重失败"); - } - - } - - - private async Task OnPriorityUpClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改投票权重", "请选中投票"); - return; - } - - await OnRowEditPriorityClick(items.Select(s => s.Id).ToArray(), 1, false); - await ToastService.Success("修改投票权重成功", "修改投票权重成功"); - await TableRows.QueryAsync(); - } - private async Task OnPriorityDownClick(IEnumerable items) - { - - if (items.Count() == 0) - { - await ToastService.Information("没有修改投票权重", "请选中投票"); - return; - } - - await OnRowEditPriorityClick(items.Select(s => s.Id).ToArray(), -1, false); - - await ToastService.Success("修改投票权重成功", "修改投票权重成功"); - await TableRows.QueryAsync(); - } - - private async Task OnRowEditIsHiddenClick(long[] ids, bool isHidden, bool showMessage) - { - string tempString = isHidden == true ? "隐藏" : "显示"; - //调用API - try - { - var obj = await _httpService.PostAsync("api/votes/HiddenVote", new HiddenVoteModel { Ids = ids, IsHidden = isHidden }); - - - - if (obj.Successful == false) - { - await ToastService.Error(tempString + "投票失败", obj.Error); - } - else - { - if (showMessage) - { - await ToastService.Success(tempString + "投票成功", tempString + "投票成功"); - await TableRows.QueryAsync(); - } - } - } - catch (Exception ex) - { - ErrorHandler.ProcessError(ex, tempString + "投票失败"); - } - } - - private async Task OnHiddenClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改投票显示状态", "请选中投票"); - return; - } - - await OnRowEditIsHiddenClick(items.Select(s => s.Id).ToArray(), true, false); - - await ToastService.Success("隐藏投票成功", "隐藏投票成功"); - await TableRows.QueryAsync(); - } - private async Task OnUnHiddenClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改投票显示状态", "请选中投票"); - return; - } - - await OnRowEditIsHiddenClick(items.Select(s => s.Id).ToArray(), false, false); - - await ToastService.Success("显示投票成功", "显示投票成功"); - await TableRows.QueryAsync(); - } - - public void OnRowLookClick(long id, string name) - { - NavigationManager.NavigateTo(Provider, "/votes/index/" + id, name, "fa fa-dropbox"); - - } - - - private async Task OnRowEditCanCommentClick(long[] ids, bool canComment, bool showMessage) - { - string tempString = canComment == true ? "启用投票评论" : "关闭投票评论"; - //调用API - try - { - var obj = await _httpService.PostAsync("api/comments/EditVoteCanComment", new EditVoteCanCommentModel { Ids = ids, CanComment = canComment }); - - - - if (obj.Successful == false) - { - await ToastService.Error(tempString + "失败", obj.Error); - } - else - { - if (showMessage) - { - await ToastService.Success(tempString + "成功", tempString + "成功"); - await TableRows.QueryAsync(); - } - } - } - catch (Exception ex) - { - ErrorHandler.ProcessError(ex, tempString + "失败"); - } - } - - private async Task OnCanCommentClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改投票评论状态", "请选中投票"); - return; - } - - await OnRowEditCanCommentClick(items.Select(s => s.Id).ToArray(), true, false); - - await ToastService.Success("开启投票评论成功", "开启投票评论成功"); - await TableRows.QueryAsync(); - } - private async Task OnCanNotCommentClick(IEnumerable items) - { - if (items.Count() == 0) - { - await ToastService.Information("没有修改投票评论状态", "请选中投票"); - return; - } - - await OnRowEditCanCommentClick(items.Select(s => s.Id).ToArray(), false, false); - - await ToastService.Success("关闭投票评论成功", "关闭投票评论成功"); - await TableRows.QueryAsync(); - } - - - -} - + diff --git a/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ManageHome.razor b/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ManageHome.razor index d4bb79404..dec1f9365 100644 --- a/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ManageHome.razor +++ b/CnGalWebSite/CnGalWebSite.Shared/Pages/Normal/Admin/ManageHome.razor @@ -21,111 +21,19 @@ 友情链接mdi-link - - 错误记录mdi-alert-circle - - - 默认图片mdi-cursor-default - - -
-
- - -
- - -
- @foreach (var item in Model.Carousels.OrderByDescending(s=>s.Priority)) - { -
- -
- } -
-
+
-
-
- - -
- -
- @foreach (var item in Model.Links.OrderByDescending(s => s.Priority)) - { -
- -
- } - -
-
-
- -
- -
-
- -
-
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
-
+ +
@code { - [CascadingParameter] - public ErrorHandler ErrorHandler { get; set; } - public StringNumber TabIndex { get; set; } = 1; - - public ManageHomeViewModel Model { get; set; } = new ManageHomeViewModel - { - Carousels = new List(), - Links = new List() - }; - - protected override async Task OnInitializedAsync() - { - try - { - Model = await _httpService.GetAsync("api/admin/managehome"); - } - catch (Exception ex) - { - ErrorHandler.ProcessError(ex, "无法获取网站主页设置相关信息"); - } - - } - - - private void ToUrl(string url) - { - NavigationManager.NavigateTo(url); - } - }