public IHttpActionResult Download()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId    = request.GetPostInt("siteId");
                var specialId = request.GetPostInt("specialId");

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSitePermissions(siteId,
                                                                     ConfigManager.SitePermissions.Specials))
                {
                    return(Unauthorized());
                }

                var siteInfo    = SiteManager.GetSiteInfo(siteId);
                var specialInfo = SpecialManager.GetSpecialInfo(siteId, specialId);

                var directoryPath    = SpecialManager.GetSpecialDirectoryPath(siteInfo, specialInfo.Url);
                var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath);
                var zipFilePath      = SpecialManager.GetSpecialZipFilePath(specialInfo.Title, directoryPath);

                FileUtils.DeleteFileIfExists(zipFilePath);
                ZipUtils.CreateZip(zipFilePath, srcDirectoryPath);
                var url = SpecialManager.GetSpecialZipFileUrl(siteInfo, specialInfo);

                return(Ok(new
                {
                    Value = url
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #2
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            if (HifUpload.PostedFile == null || "" == HifUpload.PostedFile.FileName)
            {
                FailMessage("上传压缩包失败,请选择ZIP文件上传!");
                return;
            }

            var filePath = HifUpload.PostedFile.FileName;

            if (!StringUtils.EqualsIgnoreCase(Path.GetExtension(filePath), ".zip"))
            {
                FailMessage("上传压缩包失败,必须上传ZIP文件!");
                return;
            }

            var directoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, _specialInfo.Url);

            DirectoryUtils.CreateDirectoryIfNotExists(directoryPath);

            var zipFilePath = SpecialManager.GetSpecialZipFilePath(directoryPath);

            HifUpload.PostedFile.SaveAs(zipFilePath);
            var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath);

            ZipUtils.ExtractZip(zipFilePath, srcDirectoryPath);

            DirectoryUtils.Copy(srcDirectoryPath, directoryPath, true);

            LayerUtils.Close(Page);
        }
Exemple #3
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId       = request.GetPostInt("siteId");
                var guid         = request.GetPostString("guid");
                var specialId    = request.GetPostInt("specialId");
                var isEditOnly   = request.GetPostBool("isEditOnly");
                var isUploadOnly = request.GetPostBool("isUploadOnly");
                var title        = request.GetPostString("title");
                var url          = request.GetPostString("url");
                var fileNames    = TranslateUtils.StringCollectionToStringList(request.GetPostString("fileNames"));
                var siteInfo     = SiteManager.GetSiteInfo(siteId);

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasSitePermissions(siteId,
                                                                     ConfigManager.SitePermissions.Specials))
                {
                    return(Unauthorized());
                }

                if (specialId > 0 && isEditOnly)
                {
                    var specialInfo      = SpecialManager.GetSpecialInfo(siteId, specialId);
                    var oldDirectoryPath = string.Empty;
                    var newDirectoryPath = string.Empty;

                    if (specialInfo.Title != title && DataProvider.SpecialDao.IsTitleExists(siteId, title))
                    {
                        return(BadRequest("专题修改失败,专题名称已存在!"));
                    }
                    if (specialInfo.Url != url)
                    {
                        if (DataProvider.SpecialDao.IsUrlExists(siteId, url))
                        {
                            return(BadRequest("专题修改失败,专题访问地址已存在!"));
                        }

                        oldDirectoryPath = SpecialManager.GetSpecialDirectoryPath(siteInfo, specialInfo.Url);
                        newDirectoryPath = SpecialManager.GetSpecialDirectoryPath(siteInfo, url);
                    }

                    specialInfo.Title = title;
                    specialInfo.Url   = url;
                    DataProvider.SpecialDao.Update(specialInfo);

                    if (oldDirectoryPath != newDirectoryPath)
                    {
                        DirectoryUtils.MoveDirectory(oldDirectoryPath, newDirectoryPath, true);
                    }
                }
                else if (specialId > 0 && isUploadOnly)
                {
                    var specialInfo = SpecialManager.GetSpecialInfo(siteId, specialId);

                    var directoryPath    = SpecialManager.GetSpecialDirectoryPath(siteInfo, specialInfo.Url);
                    var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath);
                    DirectoryUtils.CreateDirectoryIfNotExists(srcDirectoryPath);

                    var uploadDirectoryPath = PathUtils.GetTemporaryFilesPath(guid);
                    foreach (var filePath in DirectoryUtils.GetFilePaths(uploadDirectoryPath))
                    {
                        var fileName = PathUtils.GetFileName(filePath);
                        if (!StringUtils.ContainsIgnoreCase(fileNames, fileName))
                        {
                            continue;
                        }

                        if (EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                        {
                            ZipUtils.ExtractZip(filePath, srcDirectoryPath);
                        }
                        else
                        {
                            FileUtils.MoveFile(filePath, PathUtils.Combine(srcDirectoryPath, fileName), true);
                        }
                    }

                    DirectoryUtils.Copy(srcDirectoryPath, directoryPath);
                }
                else if (specialId == 0)
                {
                    if (DataProvider.SpecialDao.IsTitleExists(siteId, title))
                    {
                        return(BadRequest("专题添加失败,专题名称已存在!"));
                    }
                    if (DataProvider.SpecialDao.IsUrlExists(siteId, url))
                    {
                        return(BadRequest("专题添加失败,专题访问地址已存在!"));
                    }

                    var directoryPath    = SpecialManager.GetSpecialDirectoryPath(siteInfo, url);
                    var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath);
                    DirectoryUtils.CreateDirectoryIfNotExists(srcDirectoryPath);

                    var uploadDirectoryPath = PathUtils.GetTemporaryFilesPath(guid);
                    foreach (var filePath in DirectoryUtils.GetFilePaths(uploadDirectoryPath))
                    {
                        var fileName = PathUtils.GetFileName(filePath);
                        if (!StringUtils.ContainsIgnoreCase(fileNames, fileName))
                        {
                            continue;
                        }

                        if (EFileSystemTypeUtils.IsZip(PathUtils.GetExtension(filePath)))
                        {
                            ZipUtils.ExtractZip(filePath, srcDirectoryPath);
                        }
                        else
                        {
                            FileUtils.MoveFile(filePath, PathUtils.Combine(srcDirectoryPath, fileName), true);
                        }
                    }

                    DirectoryUtils.Copy(srcDirectoryPath, directoryPath);

                    specialId = DataProvider.SpecialDao.Insert(new SpecialInfo
                    {
                        Id      = 0,
                        SiteId  = siteId,
                        Title   = title,
                        Url     = url,
                        AddDate = DateTime.Now
                    });

                    request.AddSiteLog(siteId, "新建专题", $"专题名称:{title}");
                }

                CreateManager.CreateSpecial(siteId, specialId);

                return(Ok(new
                {
                    Value = specialId
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #4
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            var title = TbTitle.Text;
            var url   = PathUtility.AddVirtualToPath(TbUrl.Text);

            if (_specialInfo != null)
            {
                var oldDirectoryPath = string.Empty;
                var newDirectoryPath = string.Empty;

                if (_specialInfo.Title != title && DataProvider.SpecialDao.IsTitleExists(SiteId, title))
                {
                    FailMessage("专题修改失败,专题名称已存在!");
                    return;
                }
                if (_specialInfo.Url != url)
                {
                    if (DataProvider.SpecialDao.IsUrlExists(SiteId, url))
                    {
                        FailMessage("专题修改失败,专题访问地址已存在!");
                        return;
                    }

                    oldDirectoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, _specialInfo.Url);
                    newDirectoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, url);
                }

                _specialInfo.Title = title;
                _specialInfo.Url   = url;
                DataProvider.SpecialDao.Update(_specialInfo);

                if (oldDirectoryPath != newDirectoryPath)
                {
                    DirectoryUtils.MoveDirectory(oldDirectoryPath, newDirectoryPath, true);
                }
            }
            else
            {
                if (HifUpload.PostedFile == null || "" == HifUpload.PostedFile.FileName)
                {
                    FailMessage("专题添加失败,请选择ZIP文件上传!");
                    return;
                }

                var filePath = HifUpload.PostedFile.FileName;
                if (!StringUtils.EqualsIgnoreCase(Path.GetExtension(filePath), ".zip"))
                {
                    FailMessage("专题添加失败,必须上传ZIP文件!");
                    return;
                }

                if (DataProvider.SpecialDao.IsTitleExists(SiteId, title))
                {
                    FailMessage("专题添加失败,专题名称已存在!");
                    return;
                }
                if (DataProvider.SpecialDao.IsUrlExists(SiteId, url))
                {
                    FailMessage("专题添加失败,专题访问地址已存在!");
                    return;
                }

                var directoryPath = SpecialManager.GetSpecialDirectoryPath(SiteInfo, url);
                DirectoryUtils.CreateDirectoryIfNotExists(directoryPath);

                var zipFilePath = SpecialManager.GetSpecialZipFilePath(directoryPath);

                HifUpload.PostedFile.SaveAs(zipFilePath);
                var srcDirectoryPath = SpecialManager.GetSpecialSrcDirectoryPath(directoryPath);
                ZipUtils.ExtractZip(zipFilePath, srcDirectoryPath);

                DirectoryUtils.Copy(srcDirectoryPath, directoryPath, true);
                //var htmlFiles = Directory.GetFiles(srcDirectoryPath, "*.html", SearchOption.AllDirectories);
                //foreach (var htmlFile in htmlFiles)
                //{
                //    CreateManager.CreateFile();
                //}

                var specialInfo = new SpecialInfo
                {
                    Title   = title,
                    Url     = url,
                    SiteId  = SiteId,
                    AddDate = DateTime.Now
                };

                DataProvider.SpecialDao.Insert(specialInfo);
            }

            LayerUtils.Close(Page);
        }