Ejemplo n.º 1
0
        public async Task <ActionResult <GetResult> > Add([FromBody] ChannelGroup request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.SettingsContentGroup))
            {
                return(Unauthorized());
            }

            if (await _contentGroupRepository.IsExistsAsync(request.SiteId, request.GroupName))
            {
                return(this.Error("保存失败,已存在相同名称的内容组!"));
            }

            var groupInfo = new ContentGroup
            {
                SiteId      = request.SiteId,
                GroupName   = request.GroupName,
                Description = request.Description
            };

            await _contentGroupRepository.InsertAsync(groupInfo);

            await _authManager.AddSiteLogAsync(request.SiteId, "新增内容组", $"内容组:{groupInfo.GroupName}");

            var groups = await _contentGroupRepository.GetContentGroupsAsync(request.SiteId);

            return(new GetResult
            {
                Groups = groups
            });
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <ListResult> > Add([FromBody] AddRequest request)
        {
            if (await _contentGroupRepository.IsExistsAsync(request.SiteId, request.GroupName))
            {
                return(this.Error("保存失败,已存在相同名称的内容组!"));
            }

            var groupInfo = new ContentGroup
            {
                SiteId      = request.SiteId,
                GroupName   = request.GroupName,
                Description = request.Description
            };

            await _contentGroupRepository.InsertAsync(groupInfo);

            await _authManager.AddSiteLogAsync(request.SiteId, "新增内容组", $"内容组:{groupInfo.GroupName}");

            var groups = await _contentGroupRepository.GetContentGroupsAsync(request.SiteId);

            var groupNames = groups.Select(x => x.GroupName);

            return(new ListResult
            {
                GroupNames = groupNames,
                Groups = groups
            });
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <GetResult> > Default([FromBody] TemplateRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.Templates))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var templateInfo = await _templateRepository.GetAsync(request.TemplateId);

            if (templateInfo != null && !templateInfo.DefaultTemplate)
            {
                await _templateRepository.SetDefaultAsync(request.TemplateId);

                await _authManager.AddSiteLogAsync(site.Id,
                                                   $"设置默认{templateInfo.TemplateType.GetDisplayName()}",
                                                   $"模板名称:{templateInfo.TemplateName}");
            }

            return(await GetResultAsync(site));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <ObjectResult <Cascade <int> > > > Submit([FromBody] MatchRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.TemplatesMatch))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            if (request.ChannelIds != null && request.ChannelIds.Count > 0)
            {
                if (request.IsChannelTemplate)
                {
                    foreach (var channelId in request.ChannelIds)
                    {
                        var channelInfo = await _channelRepository.GetAsync(channelId);

                        channelInfo.ChannelTemplateId = request.TemplateId;
                        await _channelRepository.UpdateChannelTemplateIdAsync(channelInfo);
                    }
                }
                else
                {
                    foreach (var channelId in request.ChannelIds)
                    {
                        var channelInfo = await _channelRepository.GetAsync(channelId);

                        channelInfo.ContentTemplateId = request.TemplateId;
                        await _channelRepository.UpdateContentTemplateIdAsync(channelInfo);
                    }
                }
            }

            await _authManager.AddSiteLogAsync(request.SiteId, "模板匹配");

            var channel = await _channelRepository.GetAsync(request.SiteId);

            var cascade = await _channelRepository.GetCascadeAsync(site, channel, async summary =>
            {
                var count  = await _contentRepository.GetCountAsync(site, summary);
                var entity = await _channelRepository.GetAsync(summary.Id);
                return(new
                {
                    Count = count,
                    entity.ChannelTemplateId,
                    entity.ContentTemplateId
                });
            });

            return(new ObjectResult <Cascade <int> >
            {
                Value = cascade
            });
        }
Ejemplo n.º 5
0
        public async Task <ActionResult <IEnumerable <RelatedField> > > Delete([FromBody] DeleteRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.SettingsStyleRelatedField))
            {
                return(Unauthorized());
            }

            await _relatedFieldRepository.DeleteAsync(request.RelatedFieldId);

            await _authManager.AddSiteLogAsync(request.SiteId, "删除联动字段");

            return(await _relatedFieldRepository.GetRelatedFieldsAsync(request.SiteId));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.SettingsCreate))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            site.IsCreateDoubleClick             = request.IsCreateDoubleClick;
            site.IsCreateContentIfContentChanged = request.IsCreateContentIfContentChanged;
            site.IsCreateChannelIfChannelChanged = request.IsCreateChannelIfChannelChanged;
            site.IsCreateShowPageInfo            = request.IsCreateShowPageInfo;
            site.IsCreateIe8Compatible           = request.IsCreateIe8Compatible;
            site.IsCreateBrowserNoCache          = request.IsCreateBrowserNoCache;
            site.IsCreateJsIgnoreError           = request.IsCreateJsIgnoreError;
            site.IsCreateWithJQuery             = request.IsCreateWithJQuery;
            site.CreateStaticMaxPage            = request.CreateStaticMaxPage;
            site.IsCreateUseDefaultFileName     = request.IsCreateUseDefaultFileName;
            site.CreateDefaultFileName          = request.CreateDefaultFileName;
            site.IsCreateStaticContentByAddDate = request.IsCreateStaticContentByAddDate;
            site.CreateStaticContentAddDate     = request.CreateStaticContentAddDate;

            await _siteRepository.UpdateAsync(site);

            await _authManager.AddSiteLogAsync(request.SiteId, "修改页面生成设置");

            return(new BoolResult
            {
                Value = true
            });
        }
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.SettingsCreateTrigger))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(this.Error("无法确定内容对应的站点"));
            }

            var channel = await _channelRepository.GetAsync(request.ChannelId);

            channel.IsCreateChannelIfContentChanged  = request.IsCreateChannelIfContentChanged;
            channel.CreateChannelIdsIfContentChanged = ListUtils.ToString(request.CreateChannelIdsIfContentChanged);

            await _channelRepository.UpdateAsync(channel);

            await _authManager.AddSiteLogAsync(request.SiteId, request.ChannelId, 0, "设置栏目变动生成页面", $"栏目:{channel.ChannelName}");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 8
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.SettingsUploadImage))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            site.ImageUploadDirectoryName    = request.ImageUploadDirectoryName;
            site.ImageUploadDateFormatString = request.ImageUploadDateFormatString;
            site.IsImageUploadChangeFileName = request.IsImageUploadChangeFileName;
            site.ImageUploadExtensions       = request.ImageUploadExtensions.Replace("|", ",");
            site.ImageUploadTypeMaxSize      = request.ImageUploadTypeMaxSize;
            site.PhotoSmallWidth             = request.PhotoSmallWidth;
            site.PhotoMiddleWidth            = request.PhotoMiddleWidth;

            await _siteRepository.UpdateAsync(site);

            await _authManager.AddSiteLogAsync(request.SiteId, "修改图片上传设置");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 9
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.SettingsWaterMark))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            site.IsWaterMark           = request.IsWaterMark;
            site.WaterMarkPosition     = request.WaterMarkPosition;
            site.WaterMarkTransparency = request.WaterMarkTransparency;
            site.WaterMarkMinWidth     = request.WaterMarkMinWidth;
            site.WaterMarkMinHeight    = request.WaterMarkMinHeight;
            site.IsImageWaterMark      = request.IsImageWaterMark;
            site.WaterMarkFormatString = request.WaterMarkFormatString;
            site.WaterMarkFontName     = request.WaterMarkFontName;
            site.WaterMarkFontSize     = request.WaterMarkFontSize;
            site.WaterMarkImagePath    = _pathManager.GetVirtualUrl(site, request.WaterMarkImagePath);

            await _siteRepository.UpdateAsync(site);

            await _authManager.AddSiteLogAsync(request.SiteId, "修改图片水印设置");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 10
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Arrange))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var channel = await _channelRepository.GetAsync(request.ChannelId);

            if (channel == null)
            {
                return(this.Error("无法确定内容对应的栏目"));
            }

            await _contentRepository.UpdateArrangeTaxisAsync(site, channel, request.AttributeName, request.IsDesc);

            await _authManager.AddSiteLogAsync(request.SiteId, "批量整理", string.Empty);

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 11
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Edit))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var summaries = ContentUtility.ParseSummaries(request.ChannelContentIds);

            foreach (var summary in summaries)
            {
                var channel = await _channelRepository.GetAsync(summary.ChannelId);

                var content = await _contentRepository.GetAsync(site, channel, summary.Id);

                if (content == null)
                {
                    continue;
                }

                if (request.IsAdd)
                {
                    content.Hits += request.Hits;
                }
                else
                {
                    content.Hits -= request.Hits;
                }

                if (content.Hits < 0)
                {
                    content.Hits = 0;
                }
                await _contentRepository.UpdateAsync(site, channel, content);
            }

            await _authManager.AddSiteLogAsync(request.SiteId, "设置内容点击量");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 12
0
        public async Task <ActionResult <BoolResult> > Delete([FromBody] FileRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.TemplatesAssets))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            FileUtils.DeleteFileIfExists(await _pathManager.GetSitePathAsync(site, request.DirectoryPath, request.FileName));
            await _authManager.AddSiteLogAsync(request.SiteId, "删除资源文件", $"{request.DirectoryPath}:{request.FileName}");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 13
0
        public async Task <ActionResult <DeleteResult> > Delete([FromBody] SpecialIdRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Specials))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            var specialInfo = await _pathManager.DeleteSpecialAsync(site, request.SpecialId);

            await _authManager.AddSiteLogAsync(request.SiteId,
                                               "删除专题",
                                               $"专题名称:{specialInfo.Title}");

            var specialInfoList = await _specialRepository.GetSpecialsAsync(request.SiteId);

            return(new DeleteResult
            {
                Specials = specialInfoList
            });
        }
Ejemplo n.º 14
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.SettingsContent))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            site.IsSaveImageInTextEditor = request.IsSaveImageInTextEditor;

            var isReCalculate = false;

            if (request.IsAutoPageInTextEditor)
            {
                if (site.IsAutoPageInTextEditor == false)
                {
                    isReCalculate = true;
                }
                else if (site.AutoPageWordNum != request.AutoPageWordNum)
                {
                    isReCalculate = true;
                }
            }

            site.PageSize = request.PageSize;
            site.IsAutoPageInTextEditor     = request.IsAutoPageInTextEditor;
            site.AutoPageWordNum            = request.AutoPageWordNum;
            site.IsContentTitleBreakLine    = request.IsContentTitleBreakLine;
            site.IsContentSubTitleBreakLine = request.IsContentSubTitleBreakLine;
            site.IsAutoCheckKeywords        = request.IsAutoCheckKeywords;

            site.CheckContentLevel        = request.CheckContentLevel;
            site.CheckContentDefaultLevel = request.CheckContentDefaultLevel;

            await _siteRepository.UpdateAsync(site);

            if (isReCalculate)
            {
                await _contentRepository.SetAutoPageContentToSiteAsync(site);
            }

            await _authManager.AddSiteLogAsync(request.SiteId, "修改内容设置");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 15
0
        public async Task <ActionResult <BoolResult> > Delete([FromBody] DeleteRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.SettingsContentTag))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            await _contentTagRepository.DeleteAsync(request.SiteId, request.TagName);

            await _authManager.AddSiteLogAsync(request.SiteId, "删除内容标签", $"内容标签:{request.TagName}");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 16
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId, Types.SitePermissions.SettingsCrossSiteTrans))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            site.IsCrossSiteTransChecked = request.IsCrossSiteTransChecked;

            await _siteRepository.UpdateAsync(site);

            await _authManager.AddSiteLogAsync(request.SiteId, "修改默认跨站转发设置");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 17
0
        private async Task <ActionResult <GetResult> > SaveAsync(Site site, Template request)
        {
            if (request.TemplateType != TemplateType.ChannelTemplate)
            {
                if (!request.CreatedFileFullName.StartsWith("~") && !request.CreatedFileFullName.StartsWith("@"))
                {
                    request.CreatedFileFullName = PageUtils.Combine("@", request.CreatedFileFullName);
                }
            }
            else
            {
                request.CreatedFileFullName = request.CreatedFileFullName.TrimStart('~', '@');
                request.CreatedFileFullName = request.CreatedFileFullName.Replace("/", string.Empty);
            }

            Template template;

            var adminId = _authManager.AdminId;

            if (request.Id > 0)
            {
                var templateId = request.Id;
                template = await _templateRepository.GetAsync(templateId);

                if (template.TemplateName != request.TemplateName)
                {
                    var templateNameList = await _templateRepository.GetTemplateNamesAsync(request.SiteId, template.TemplateType);

                    if (templateNameList.Contains(request.TemplateName))
                    {
                        return(this.Error("模板修改失败,模板名称已存在!"));
                    }
                }
                Template previousTemplate = null;
                var      isChanged        = false;
                if (PathUtils.RemoveExtension(template.RelatedFileName) != PathUtils.RemoveExtension(request.RelatedFileName))                //文件名改变
                {
                    var fileNameList = await _templateRepository.GetRelatedFileNamesAsync(request.SiteId, template.TemplateType);

                    foreach (var fileName in fileNameList)
                    {
                        var fileNameWithoutExtension = PathUtils.RemoveExtension(fileName);
                        if (StringUtils.EqualsIgnoreCase(fileNameWithoutExtension, request.RelatedFileName))
                        {
                            return(this.Error("模板修改失败,模板文件已存在!"));
                        }
                    }

                    isChanged = true;
                }

                if (GetTemplateFileExtension(template) != request.CreatedFileExtName)                //文件后缀改变
                {
                    isChanged = true;
                }

                if (isChanged)
                {
                    previousTemplate = new Template
                    {
                        Id                  = template.Id,
                        SiteId              = template.SiteId,
                        TemplateName        = template.TemplateName,
                        TemplateType        = template.TemplateType,
                        RelatedFileName     = template.RelatedFileName,
                        CreatedFileFullName = template.CreatedFileFullName,
                        CreatedFileExtName  = template.CreatedFileExtName,
                        DefaultTemplate     = template.DefaultTemplate
                    };
                }

                template.TemplateName        = request.TemplateName;
                template.RelatedFileName     = request.RelatedFileName + request.CreatedFileExtName;
                template.CreatedFileExtName  = request.CreatedFileExtName;
                template.CreatedFileFullName = request.CreatedFileFullName + request.CreatedFileExtName;

                await _templateRepository.UpdateAsync(_pathManager, site, template, request.Content, adminId);

                if (previousTemplate != null)
                {
                    FileUtils.DeleteFileIfExists(await _pathManager.GetTemplateFilePathAsync(site, previousTemplate));
                }
                await CreatePagesAsync(template);

                await _authManager.AddSiteLogAsync(request.SiteId,
                                                   $"修改{template.TemplateType.GetDisplayName()}",
                                                   $"模板名称:{template.TemplateName}");
            }
            else
            {
                var templateNameList = await _templateRepository.GetTemplateNamesAsync(request.SiteId, request.TemplateType);

                if (templateNameList.Contains(request.TemplateName))
                {
                    return(this.Error("模板添加失败,模板名称已存在!"));
                }
                var fileNameList = await _templateRepository.GetRelatedFileNamesAsync(request.SiteId, request.TemplateType);

                if (ListUtils.ContainsIgnoreCase(fileNameList, request.RelatedFileName))
                {
                    return(this.Error("模板添加失败,模板文件已存在!"));
                }

                template = new Template
                {
                    SiteId              = request.SiteId,
                    TemplateName        = request.TemplateName,
                    TemplateType        = request.TemplateType,
                    RelatedFileName     = request.RelatedFileName + request.CreatedFileExtName,
                    CreatedFileExtName  = request.CreatedFileExtName,
                    CreatedFileFullName = request.CreatedFileFullName + request.CreatedFileExtName,
                    DefaultTemplate     = false
                };

                template.Id = await _templateRepository.InsertAsync(_pathManager, site, template, request.Content, adminId);
                await CreatePagesAsync(template);

                await _authManager.AddSiteLogAsync(request.SiteId,
                                                   $"添加{template.TemplateType.GetDisplayName()}",
                                                   $"模板名称:{template.TemplateName}");
            }

            return(new GetResult
            {
                Template = await GetTemplateResultAsync(template, site)
            });
        }
Ejemplo n.º 18
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Delete))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var summaries = ContentUtility.ParseSummaries(request.ChannelContentIds);

            if (!request.IsRetainFiles)
            {
                foreach (var summary in summaries)
                {
                    await _createManager.DeleteContentAsync(site, summary.ChannelId, summary.Id);
                }
            }

            if (summaries.Count == 1)
            {
                var summary = summaries[0];

                var content = await _contentRepository.GetAsync(site, summary.ChannelId, summary.Id);

                if (content != null)
                {
                    await _authManager.AddSiteLogAsync(request.SiteId, summary.ChannelId, summary.Id, "删除内容",
                                                       $"栏目:{await _channelRepository.GetChannelNameNavigationAsync(request.SiteId, summary.ChannelId)},内容标题:{content.Title}");
                }
            }
            else
            {
                await _authManager.AddSiteLogAsync(request.SiteId, "批量删除内容",
                                                   $"栏目:{await _channelRepository.GetChannelNameNavigationAsync(request.SiteId, request.ChannelId)},内容条数:{summaries.Count}");
            }

            var adminId = _authManager.AdminId;

            foreach (var distinctChannelId in summaries.Select(x => x.ChannelId).Distinct())
            {
                var distinctChannel = await _channelRepository.GetAsync(distinctChannelId);

                var contentIdList = summaries.Where(x => x.ChannelId == distinctChannelId)
                                    .Select(x => x.Id).ToList();
                await _contentRepository.TrashContentsAsync(site, distinctChannel, contentIdList, adminId);

                await _createManager.TriggerContentChangedEventAsync(request.SiteId, distinctChannelId);
            }

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 19
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Edit))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var summaries = ContentUtility.ParseSummaries(request.ChannelContentIds);
            var isUp      = request.IsUp;

            if (isUp == false)
            {
                summaries.Reverse();
            }

            foreach (var summary in summaries)
            {
                var channel = await _channelRepository.GetAsync(summary.ChannelId);

                var content = await _contentRepository.GetAsync(site, channel, summary.Id);

                if (content == null)
                {
                    continue;
                }

                var isTop = content.Top;
                for (var i = 1; i <= request.Taxis; i++)
                {
                    if (isUp)
                    {
                        if (await _contentRepository.SetTaxisToUpAsync(site, channel, summary.Id, isTop) == false)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (await _contentRepository.SetTaxisToDownAsync(site, channel, summary.Id, isTop) == false)
                        {
                            break;
                        }
                    }
                }
            }

            foreach (var distinctChannelId in summaries.Select(x => x.ChannelId).Distinct())
            {
                await _createManager.TriggerContentChangedEventAsync(request.SiteId, distinctChannelId);
            }

            await _authManager.AddSiteLogAsync(request.SiteId, request.ChannelId, 0, "对内容排序", string.Empty);

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 20
0
        public async Task <ActionResult <BoolResult> > Add([FromBody] AddRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Edit))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var channelContentIds = ContentUtility.ParseSummaries(request.ChannelContentIds);

            var group = new ContentGroup
            {
                GroupName   = request.GroupName,
                SiteId      = request.SiteId,
                Description = request.Description
            };

            if (await _contentGroupRepository.IsExistsAsync(request.SiteId, group.GroupName))
            {
                await _contentGroupRepository.UpdateAsync(group);

                await _authManager.AddSiteLogAsync(request.SiteId, "修改内容组", $"内容组:{group.GroupName}");
            }
            else
            {
                await _contentGroupRepository.InsertAsync(group);

                await _authManager.AddSiteLogAsync(request.SiteId, "添加内容组", $"内容组:{group.GroupName}");
            }

            foreach (var channelContentId in channelContentIds)
            {
                var channel = await _channelRepository.GetAsync(channelContentId.ChannelId);

                var content = await _contentRepository.GetAsync(site, channel, channelContentId.Id);

                if (content == null)
                {
                    continue;
                }

                var list = ListUtils.GetStringList(content.GroupNames);
                if (!list.Contains(group.GroupName))
                {
                    list.Add(group.GroupName);
                }
                content.GroupNames = list;

                await _contentRepository.UpdateAsync(site, channel, content);
            }

            await _authManager.AddSiteLogAsync(request.SiteId, "批量设置内容组", $"内容组:{group.GroupName}");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 21
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Edit))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var summaries = ContentUtility.ParseSummaries(request.ChannelContentIds);

            foreach (var summary in summaries)
            {
                var channel = await _channelRepository.GetAsync(summary.ChannelId);

                var content = await _contentRepository.GetAsync(site, channel, summary.Id);

                if (content == null)
                {
                    continue;
                }

                if (request.IsTop)
                {
                    content.Top = !request.IsCancel;
                }
                if (request.IsRecommend)
                {
                    content.Recommend = !request.IsCancel;
                }
                if (request.IsHot)
                {
                    content.Hot = !request.IsCancel;
                }
                if (request.IsColor)
                {
                    content.Color = !request.IsCancel;
                }

                await _contentRepository.UpdateAsync(site, channel, content);
            }

            await _authManager.AddSiteLogAsync(request.SiteId, request.IsCancel? "取消内容属性" : "设置内容属性");

            //else if (pageType == "setHits")
            //{
            //    foreach (var channelContentId in channelContentIds)
            //    {
            //        var channelInfo = await _channelRepository.GetAsync(channelContentId.ChannelId);
            //        var contentInfo = await _contentRepository.GetAsync(site, channelInfo, channelContentId.Id);
            //        if (contentInfo == null) continue;

            //        contentInfo.Hits = hits;
            //        await _contentRepository.UpdateAsync(site, channelInfo, contentInfo);
            //    }

            //    await request.AddSiteLogAsync(siteId, "设置内容点击量");
            //}

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 22
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Edit))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var allTagNames = await _contentTagRepository.GetTagNamesAsync(request.SiteId);

            foreach (var tagName in request.TagNames)
            {
                if (!allTagNames.Contains(tagName))
                {
                    await _contentTagRepository.InsertAsync(request.SiteId, tagName);
                }
            }

            var summaries = ContentUtility.ParseSummaries(request.ChannelContentIds);

            foreach (var summary in summaries)
            {
                var channel = await _channelRepository.GetAsync(summary.ChannelId);

                var content = await _contentRepository.GetAsync(site, channel, summary.Id);

                if (content == null)
                {
                    continue;
                }

                var list = new List <string>();
                foreach (var tagName in ListUtils.GetStringList(content.TagNames))
                {
                    if (allTagNames.Contains(tagName))
                    {
                        list.Add(tagName);
                    }
                }

                foreach (var name in request.TagNames)
                {
                    if (request.IsCancel)
                    {
                        if (list.Contains(name))
                        {
                            list.Remove(name);
                        }
                    }
                    else
                    {
                        if (!list.Contains(name))
                        {
                            list.Add(name);
                        }
                    }
                }
                content.TagNames = list;

                await _contentRepository.UpdateAsync(site, channel, content);
            }

            await _authManager.AddSiteLogAsync(request.SiteId, request.IsCancel? "批量取消内容标签" : "批量设置内容标签");

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 23
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Add))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var channelInfo = await _channelRepository.GetAsync(request.ChannelId);

            if (channelInfo == null)
            {
                return(this.Error("无法确定内容对应的栏目"));
            }

            var caching   = new CacheUtils(_cacheManager);
            var isChecked = request.CheckedLevel >= site.CheckContentLevel;

            var contentIdList = new List <int>();

            var adminId = _authManager.AdminId;

            if (request.ImportType == "zip")
            {
                foreach (var fileName in request.FileNames)
                {
                    var localFilePath = _pathManager.GetTemporaryFilesPath(fileName);

                    if (!FileUtils.IsType(FileType.Zip, PathUtils.GetExtension(localFilePath)))
                    {
                        continue;
                    }

                    var importObject = new ImportObject(_pathManager, _databaseManager, caching, site, adminId);
                    contentIdList.AddRange(await importObject.ImportContentsByZipFileAsync(channelInfo, localFilePath, request.IsOverride, isChecked, request.CheckedLevel, adminId, 0, SourceManager.Default));
                }
            }
            else if (request.ImportType == "csv")
            {
                foreach (var fileName in request.FileNames)
                {
                    var localFilePath = _pathManager.GetTemporaryFilesPath(fileName);

                    if (!FileUtils.IsType(FileType.Csv, PathUtils.GetExtension(localFilePath)))
                    {
                        continue;
                    }

                    var importObject = new ImportObject(_pathManager, _databaseManager, caching, site, adminId);
                    contentIdList.AddRange(await importObject.ImportContentsByCsvFileAsync(channelInfo, localFilePath, request.IsOverride, isChecked, request.CheckedLevel, adminId, 0, SourceManager.Default));
                }
            }
            else if (request.ImportType == "txt")
            {
                foreach (var fileName in request.FileNames)
                {
                    var localFilePath = _pathManager.GetTemporaryFilesPath(fileName);
                    if (!FileUtils.IsType(FileType.Txt, PathUtils.GetExtension(localFilePath)))
                    {
                        continue;
                    }

                    var importObject = new ImportObject(_pathManager, _databaseManager, caching, site, adminId);
                    contentIdList.AddRange(await importObject.ImportContentsByTxtFileAsync(channelInfo, localFilePath, request.IsOverride, isChecked, request.CheckedLevel, adminId, 0, SourceManager.Default));
                }
            }

            foreach (var contentId in contentIdList)
            {
                await _createManager.CreateContentAsync(request.SiteId, channelInfo.Id, contentId);
            }
            await _createManager.CreateChannelAsync(request.SiteId, channelInfo.Id);

            await _authManager.AddSiteLogAsync(request.SiteId, request.ChannelId, 0, "导入内容", string.Empty);

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 24
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.CheckLevel1))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var isChecked = request.CheckedLevel >= site.CheckContentLevel;

            if (isChecked)
            {
                request.CheckedLevel = 0;
            }

            var summaries = ContentUtility.ParseSummaries(request.ChannelContentIds);

            summaries.Reverse();

            var adminId = _authManager.AdminId;

            foreach (var summary in summaries)
            {
                var contentChannelInfo = await _channelRepository.GetAsync(summary.ChannelId);

                var contentInfo = await _contentRepository.GetAsync(site, contentChannelInfo, summary.Id);

                if (contentInfo == null)
                {
                    continue;
                }

                contentInfo.Set(ColumnsManager.CheckAdminId, adminId);
                contentInfo.Set(ColumnsManager.CheckDate, DateTime.Now);
                contentInfo.Set(ColumnsManager.CheckReasons, request.Reasons);

                contentInfo.Checked      = isChecked;
                contentInfo.CheckedLevel = request.CheckedLevel;

                await _contentRepository.UpdateAsync(site, contentChannelInfo, contentInfo);

                await _contentCheckRepository.InsertAsync(new ContentCheck
                {
                    SiteId       = request.SiteId,
                    ChannelId    = contentInfo.ChannelId,
                    ContentId    = contentInfo.Id,
                    AdminId      = adminId,
                    Checked      = isChecked,
                    CheckedLevel = request.CheckedLevel,
                    CheckDate    = DateTime.Now,
                    Reasons      = request.Reasons
                });

                if (request.IsTranslate)
                {
                    await ContentUtility.TranslateAsync(_pathManager, _databaseManager, _pluginManager, site, summary.ChannelId, summary.Id, request.TransSiteId, request.TransChannelId, TranslateType.Cut, _createManager, _authManager.AdminId);
                }
            }

            await _authManager.AddSiteLogAsync(request.SiteId, "批量审核内容");

            if (request.IsTranslate)
            {
                await _createManager.TriggerContentChangedEventAsync(request.TransSiteId, request.TransChannelId);
            }
            else
            {
                foreach (var summary in summaries)
                {
                    await _createManager.CreateContentAsync(request.SiteId, summary.ChannelId, summary.Id);
                }
            }

            foreach (var distinctChannelId in summaries.Select(x => x.ChannelId).Distinct())
            {
                await _createManager.TriggerContentChangedEventAsync(request.SiteId, distinctChannelId);
            }

            return(new BoolResult
            {
                Value = true
            });
        }
Ejemplo n.º 25
0
        public async Task <ActionResult <GetResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.SettingsCreateRule))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(this.Error("无法确定内容对应的站点"));
            }

            var channel = await _channelRepository.GetAsync(request.ChannelId);

            if (request.ChannelId != request.SiteId)
            {
                channel.LinkUrl  = request.LinkUrl;
                channel.LinkType = request.LinkType;

                var filePath = channel.FilePath;
                if (!string.IsNullOrEmpty(request.FilePath) && !StringUtils.EqualsIgnoreCase(filePath, request.FilePath))
                {
                    if (!DirectoryUtils.IsDirectoryNameCompliant(request.FilePath))
                    {
                        return(this.Error("栏目页面路径不符合系统要求!"));
                    }

                    if (PathUtils.IsDirectoryPath(request.FilePath))
                    {
                        request.FilePath = PageUtils.Combine(request.FilePath, "index.html");
                    }

                    var filePathArrayList = await _channelRepository.GetAllFilePathBySiteIdAsync(request.SiteId);

                    if (filePathArrayList.Contains(request.FilePath))
                    {
                        return(this.Error("栏目修改失败,栏目页面路径已存在!"));
                    }
                }

                if (request.FilePath != await _pathManager.GetInputChannelUrlAsync(site, channel, false))
                {
                    channel.FilePath = request.FilePath;
                }
            }

            if (!string.IsNullOrEmpty(request.ChannelFilePathRule))
            {
                var filePathRule = request.ChannelFilePathRule.Replace("|", string.Empty);
                if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule))
                {
                    return(this.Error("栏目页面命名规则不符合系统要求!"));
                }
                if (PathUtils.IsDirectoryPath(filePathRule))
                {
                    return(this.Error("栏目页面命名规则必须包含生成文件的后缀!"));
                }
            }

            if (!string.IsNullOrEmpty(request.ContentFilePathRule))
            {
                var filePathRule = request.ContentFilePathRule.Replace("|", string.Empty);
                if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule))
                {
                    return(this.Error("内容页面命名规则不符合系统要求!"));
                }
                if (PathUtils.IsDirectoryPath(filePathRule))
                {
                    return(this.Error("内容页面命名规则必须包含生成文件的后缀!"));
                }
            }

            if (request.ChannelFilePathRule != await _pathManager.GetChannelFilePathRuleAsync(site, request.ChannelId))
            {
                channel.ChannelFilePathRule = request.ChannelFilePathRule;
            }
            if (request.ContentFilePathRule != await _pathManager.GetContentFilePathRuleAsync(site, request.ChannelId))
            {
                channel.ContentFilePathRule = request.ContentFilePathRule;
            }

            await _channelRepository.UpdateAsync(channel);

            await _createManager.CreateChannelAsync(request.SiteId, request.ChannelId);

            await _authManager.AddSiteLogAsync(request.SiteId, request.ChannelId, 0, "设置页面生成规则", $"栏目:{channel.ChannelName}");

            var cascade = await _channelRepository.GetCascadeAsync(site, channel, async (summary) =>
            {
                var count               = await _contentRepository.GetCountAsync(site, summary);
                var entity              = await _channelRepository.GetAsync(summary.Id);
                var filePath            = await _pathManager.GetInputChannelUrlAsync(site, entity, false);
                var contentFilePathRule = string.IsNullOrEmpty(entity.ContentFilePathRule)
                    ? await _pathManager.GetContentFilePathRuleAsync(site, summary.Id)
                    : entity.ContentFilePathRule;
                return(new
                {
                    Count = count,
                    FilePath = filePath,
                    ContentFilePathRule = contentFilePathRule
                });
            });

            return(new GetResult
            {
                Channel = cascade
            });
        }