Ejemplo n.º 1
0
        public override Task <string> Process()
        {
            try
            {
                _start = string.IsNullOrEmpty(Request.Query["start"]) ? 0 : Convert.ToInt32(Request.Query["start"]);
                _size  = string.IsNullOrEmpty(Request.Query["size"]) ? UeditorConfig.GetInt("imageManagerListSize") : Convert.ToInt32(Request.Query["size"]);
            }
            catch (FormatException)
            {
                _state = ResultState.InvalidParam;
                return(Task.FromResult(WriteResult()));
            }
            var buildingList = new List <string>();

            try
            {
                var localPath = AppContext.BaseDirectory + "wwwroot" + _pathToList;
                buildingList.AddRange(Directory.GetFiles(localPath, "*", SearchOption.AllDirectories).Where(x => _searchExtensions.Contains(Path.GetExtension(x).ToLower())).Select(x => _pathToList + x.Substring(localPath.Length).Replace("\\", "/")));
                _total    = buildingList.Count;
                _fileList = buildingList.OrderBy(x => x).Skip(_start).Take(_size).ToArray();
            }
            catch (UnauthorizedAccessException)
            {
                _state = ResultState.AuthorizError;
            }
            catch (DirectoryNotFoundException)
            {
                _state = ResultState.PathNotFound;
            }
            catch (IOException)
            {
                _state = ResultState.IOError;
            }
            return(Task.FromResult(WriteResult()));
        }
Ejemplo n.º 2
0
        public override void Process()
        {
            try
            {
                Start = String.IsNullOrEmpty(Request["start"]) ? 0 : Convert.ToInt32(Request["start"]);
                Size  = String.IsNullOrEmpty(Request["size"])
                    ? UeditorConfig.GetInt("imageManagerListSize")
                    : Convert.ToInt32(Request["size"]);
            }
            catch (FormatException)
            {
                State = ResultState.InvalidParam;
                WriteResult();
                return;
            }

            var buildingList = new List <String>();

            try
            {
                var localPath = Server.MapPath(PathToList);
                buildingList.AddRange(Directory.GetFiles(localPath, "*", SearchOption.AllDirectories)
                                      .Where(x => SearchExtensions.Contains(Path.GetExtension(x).ToLower()))
                                      .Select(x => PathToList + x.Substring(localPath.Length).Replace("\\", "/")));
                Total    = buildingList.Count;
                FileList = buildingList.OrderBy(x => x).Skip(Start).Take(Size).ToArray();
            }
            catch (UnauthorizedAccessException)
            {
                State = ResultState.AuthorizError;
            }
            catch (DirectoryNotFoundException)
            {
                State = ResultState.PathNotFound;
            }
            catch (IOException)
            {
                State = ResultState.IOError;
            }
            finally
            {
                WriteResult();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 百度编辑器的后端接口
        /// </summary>
        /// <param name="action">执行动作</param>
        /// <returns></returns>
        public ActionResult UEditor()
        {
            string action = Request["action"];

            switch (action)
            {
            case "config":
                return(Content(UeditorConfig.Items.ToJson()));

            case "uploadimage":
                return(UEditorUpload(new UeditorUploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("imageAllowFiles"),
                    PathFormat = UeditorConfig.GetString("imagePathFormat"),
                    SizeLimit = UeditorConfig.GetInt("imageMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("imageFieldName")
                }));

            case "uploadscrawl":
                return(UEditorUpload(new UeditorUploadConfig()
                {
                    AllowExtensions = new string[] { ".png" },
                    PathFormat = UeditorConfig.GetString("scrawlPathFormat"),
                    SizeLimit = UeditorConfig.GetInt("scrawlMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("scrawlFieldName"),
                    Base64 = true,
                    Base64Filename = "scrawl.png"
                }));

            case "uploadvideo":
                return(UEditorUpload(new UeditorUploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("videoAllowFiles"),
                    PathFormat = UeditorConfig.GetString("videoPathFormat"),
                    SizeLimit = UeditorConfig.GetInt("videoMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("videoFieldName")
                }));

            case "uploadfile":
                return(UEditorUpload(new UeditorUploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("fileAllowFiles"),
                    PathFormat = UeditorConfig.GetString("filePathFormat"),
                    SizeLimit = UeditorConfig.GetInt("fileMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("fileFieldName")
                }));

            case "listimage":
                return(ListFileManager(UeditorConfig.GetString("imageManagerListPath"), UeditorConfig.GetStringList("imageManagerAllowFiles")));

            case "listfile":
                return(ListFileManager(UeditorConfig.GetString("fileManagerListPath"), UeditorConfig.GetStringList("fileManagerAllowFiles")));

            case "catchimage":
                return(CrawlerHandler());

            default:
                return(Content(new
                {
                    state = "action 参数为空或者 action 不被支持。"
                }.ToJson()));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 百度编辑器的文件列表管理
        /// </summary>
        /// <param name="pathToList">文件列表目录</param>
        /// <param name="searchExtensions">扩展名</param>
        /// <returns></returns>
        public ActionResult ListFileManager(string pathToList, string[] searchExtensions)
        {
            int Start;
            int Size;
            int Total;

            String[] FileList;
            String[] SearchExtensions;
            SearchExtensions = searchExtensions.Select(x => x.ToLower()).ToArray();
            try
            {
                Start = String.IsNullOrEmpty(Request["start"]) ? 0 : Convert.ToInt32(Request["start"]);
                Size  = String.IsNullOrEmpty(Request["size"]) ? UeditorConfig.GetInt("imageManagerListSize") : Convert.ToInt32(Request["size"]);
            }
            catch (FormatException)
            {
                return(Content(new
                {
                    state = "参数不正确",
                    start = 0,
                    size = 0,
                    total = 0
                }.ToJson()));
            }
            var buildingList = new List <String>();

            try
            {
                var localPath = Server.MapPath(pathToList).Replace("\\Utility\\", "\\ueditor\\");
                buildingList.AddRange(Directory.GetFiles(localPath, "*", SearchOption.AllDirectories)
                                      .Where(x => SearchExtensions.Contains(Path.GetExtension(x).ToLower()))
                                      .Select(x => pathToList + x.Substring(localPath.Length).Replace("\\", "/")));
                Total    = buildingList.Count;
                FileList = buildingList.OrderBy(x => x).Skip(Start).Take(Size).ToArray();
            }
            catch (UnauthorizedAccessException)
            {
                return(Content(new
                {
                    state = "文件系统权限不足",
                    start = 0,
                    size = 0,
                    total = 0
                }.ToJson()));
            }
            catch (DirectoryNotFoundException)
            {
                return(Content(new
                {
                    state = "路径不存在",
                    start = 0,
                    size = 0,
                    total = 0
                }.ToJson()));
            }
            catch (IOException)
            {
                return(Content(new
                {
                    state = "文件系统读取错误",
                    start = 0,
                    size = 0,
                    total = 0
                }.ToJson()));
            }

            return(Content(new
            {
                state = "SUCCESS",
                list = FileList == null ? null : FileList.Select(x => new { url = x }),
                start = Start,
                size = Size,
                total = Total
            }.ToJson()));
        }
Ejemplo n.º 5
0
        public ActionResult FileUploader()
        {
            HttpContext context = System.Web.HttpContext.Current;
            Handler     action  = new NotSupportedHandler(context);

            switch (Request["action"])//管理员用
            {
            case "config":
                action = new ConfigHandler(context);
                break;

            case "uploadimage":
                action = new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("imageAllowFiles"),
                    PathFormat      = UeditorConfig.GetString("imagePathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("imageMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("imageFieldName")
                });
                break;

            case "uploadscrawl":
                action = new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = new[] { ".png" },
                    PathFormat      = UeditorConfig.GetString("scrawlPathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("scrawlMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("scrawlFieldName"),
                    Base64          = true,
                    Base64Filename  = "scrawl.png"
                });
                break;

            case "catchimage":
                action = new CrawlerHandler(context);
                break;

            case "uploadvideo":
                action = new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("videoAllowFiles"),
                    PathFormat      = UeditorConfig.GetString("videoPathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("videoMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("videoFieldName")
                });
                break;

            case "uploadfile":
                action = new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("fileAllowFiles"),
                    PathFormat      = UeditorConfig.GetString("filePathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("fileMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("fileFieldName")
                });
                break;

            case "listimage":
                action = new ListFileManager(context, UeditorConfig.GetString("imageManagerListPath"), UeditorConfig.GetStringList("imageManagerAllowFiles"));
                break;

            case "listfile":
                action = new ListFileManager(context, UeditorConfig.GetString("fileManagerListPath"), UeditorConfig.GetStringList("fileManagerAllowFiles"));
                break;
            }
            #region 用户通用方法
            //switch (Request["action"])//通用
            //{
            //    case "config":
            //        action = new ConfigHandler(context);
            //        break;
            //    case "uploadimage":
            //        action = new UploadHandler(context, new UploadConfig()
            //        {
            //            AllowExtensions = UeditorConfig.GetStringList("imageAllowFiles"),
            //            PathFormat = UeditorConfig.GetString("imagePathFormat"),
            //            SizeLimit = UeditorConfig.GetInt("imageMaxSize"),
            //            UploadFieldName = UeditorConfig.GetString("imageFieldName")
            //        });
            //        break;
            //    case "uploadscrawl":
            //        action = new UploadHandler(context, new UploadConfig()
            //        {
            //            AllowExtensions = new[] { ".png" },
            //            PathFormat = UeditorConfig.GetString("scrawlPathFormat"),
            //            SizeLimit = UeditorConfig.GetInt("scrawlMaxSize"),
            //            UploadFieldName = UeditorConfig.GetString("scrawlFieldName"),
            //            Base64 = true,
            //            Base64Filename = "scrawl.png"
            //        });
            //        break;
            //    case "catchimage":
            //        action = new CrawlerHandler(context);
            //        break;
            //}
            #endregion
            #region 管理员权限使用方法
            //UserInfoOutputDto user = HttpContext.Session.GetByRedis<UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();
            //if (user.IsAdmin)
            //{
            //    switch (Request["action"])//管理员用
            //    {
            //        case "uploadvideo":
            //            action = new UploadHandler(context, new UploadConfig()
            //            {
            //                AllowExtensions = UeditorConfig.GetStringList("videoAllowFiles"),
            //                PathFormat = UeditorConfig.GetString("videoPathFormat"),
            //                SizeLimit = UeditorConfig.GetInt("videoMaxSize"),
            //                UploadFieldName = UeditorConfig.GetString("videoFieldName")
            //            });
            //            break;
            //        case "uploadfile":
            //            action = new UploadHandler(context, new UploadConfig()
            //            {
            //                AllowExtensions = UeditorConfig.GetStringList("fileAllowFiles"),
            //                PathFormat = UeditorConfig.GetString("filePathFormat"),
            //                SizeLimit = UeditorConfig.GetInt("fileMaxSize"),
            //                UploadFieldName = UeditorConfig.GetString("fileFieldName")
            //            });
            //            break;
            //        case "listimage":
            //            action = new ListFileManager(context, UeditorConfig.GetString("imageManagerListPath"), UeditorConfig.GetStringList("imageManagerAllowFiles"));
            //            break;
            //        case "listfile":
            //            action = new ListFileManager(context, UeditorConfig.GetString("fileManagerListPath"), UeditorConfig.GetStringList("fileManagerAllowFiles"));
            //            break;
            //    }
            //}
            #endregion
            string result = action.Process();
            return(Content(result, ContentType.Json, Encoding.UTF8));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> UeditorFileUploader()
        {
            UserInfoDto user   = HttpContext.Session.Get <UserInfoDto>(SessionKey.UserInfo) ?? new UserInfoDto();
            var         action = Request.Query["action"].ToString() switch //通用
            {
                "config" => (Handler) new ConfigHandler(HttpContext),
                "uploadimage" => new UploadHandler(HttpContext, new UploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("imageAllowFiles"),
                    PathFormat      = "/" + CommonHelper.SystemSettings.GetOrAdd("UploadPath", "upload").Trim('/', '\\') + UeditorConfig.GetString("imagePathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("imageMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("imageFieldName")
                }),
                "uploadscrawl" => new UploadHandler(HttpContext, new UploadConfig()
                {
                    AllowExtensions = new[]
                    {
                        ".png"
                    },
                    PathFormat      = "/" + CommonHelper.SystemSettings.GetOrAdd("UploadPath", "upload").Trim('/', '\\') + UeditorConfig.GetString("scrawlPathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("scrawlMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("scrawlFieldName"),
                    Base64          = true,
                    Base64Filename  = "scrawl.png"
                }),
                "catchimage" => new CrawlerHandler(HttpContext),
                _ => new NotSupportedHandler(HttpContext)
            };

            if (user.IsAdmin)
            {
                switch (Request.Query["action"])//管理员用
                {
                //case "uploadvideo":
                //    action = new UploadHandler(context, new UploadConfig()
                //    {
                //        AllowExtensions = UeditorConfig.GetStringList("videoAllowFiles"),
                //        PathFormat =  "/" + CommonHelper.SystemSettings.GetOrAdd("UploadPath", "upload") + UeditorConfig.GetString("videoPathFormat"),
                //        SizeLimit = UeditorConfig.GetInt("videoMaxSize"),
                //        UploadFieldName = UeditorConfig.GetString("videoFieldName")
                //    });
                //    break;
                case "uploadfile":
                    action = new UploadHandler(HttpContext, new UploadConfig()
                    {
                        AllowExtensions = UeditorConfig.GetStringList("fileAllowFiles"),
                        PathFormat      = "/" + CommonHelper.SystemSettings.GetOrAdd("UploadPath", "upload").Trim('/', '\\') + UeditorConfig.GetString("filePathFormat"),
                        SizeLimit       = UeditorConfig.GetInt("fileMaxSize"),
                        UploadFieldName = UeditorConfig.GetString("fileFieldName")
                    });
                    break;
                    //case "listimage":
                    //    action = new ListFileManager(context, CommonHelper.SystemSettings.GetOrAdd("UploadPath", "/upload") + UeditorConfig.GetString("imageManagerListPath"), UeditorConfig.GetStringList("imageManagerAllowFiles"));
                    //    break;
                    //case "listfile":
                    //    action = new ListFileManager(context, CommonHelper.SystemSettings.GetOrAdd("UploadPath", "/upload") + UeditorConfig.GetString("fileManagerListPath"), UeditorConfig.GetStringList("fileManagerAllowFiles"));
                    //    break;
                }
            }

            string result = await action.Process();

            return(Content(result, ContentType.Json));
        }
Ejemplo n.º 7
0
        public ActionResult UeditorFileUploader()
        {
            //UserInfoOutputDto user = HttpContext.Session.GetByRedis<UserInfoOutputDto>(SessionKey.UserInfo) ?? new UserInfoOutputDto();
            bool    IsAdmin = false;
            Handler action  = new NotSupportedHandler(HttpContext);

            switch (Request.Query["action"])//通用
            {
            case "config":
                action = new ConfigHandler(HttpContext);
                break;

            case "uploadimage":
                action = new UploadHandler(HttpContext, new UploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("imageAllowFiles"),
                    PathFormat      = UeditorConfig.GetString("imagePathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("imageMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("imageFieldName")
                });
                break;

            case "uploadscrawl":
                action = new UploadHandler(HttpContext, new UploadConfig()
                {
                    AllowExtensions = new[] { ".png" },
                    PathFormat      = UeditorConfig.GetString("scrawlPathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("scrawlMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("scrawlFieldName"),
                    Base64          = true,
                    Base64Filename  = "scrawl.png"
                });
                break;

            case "catchimage":
                action = new CrawlerHandler(HttpContext);
                break;
            }

            if (IsAdmin)
            {
                switch (Request.Query["action"])//管理员用
                {
                //case "uploadvideo":
                //    action = new UploadHandler(context, new UploadConfig()
                //    {
                //        AllowExtensions = UeditorConfig.GetStringList("videoAllowFiles"),
                //        PathFormat = UeditorConfig.GetString("videoPathFormat"),
                //        SizeLimit = UeditorConfig.GetInt("videoMaxSize"),
                //        UploadFieldName = UeditorConfig.GetString("videoFieldName")
                //    });
                //    break;
                case "uploadfile":
                    action = new UploadHandler(HttpContext, new UploadConfig()
                    {
                        AllowExtensions = UeditorConfig.GetStringList("fileAllowFiles"),
                        PathFormat      = UeditorConfig.GetString("filePathFormat"),
                        SizeLimit       = UeditorConfig.GetInt("fileMaxSize"),
                        UploadFieldName = UeditorConfig.GetString("fileFieldName")
                    });
                    break;
                    //case "listimage":
                    //    action = new ListFileManager(context, UeditorConfig.GetString("imageManagerListPath"), UeditorConfig.GetStringList("imageManagerAllowFiles"));
                    //    break;
                    //case "listfile":
                    //    action = new ListFileManager(context, UeditorConfig.GetString("fileManagerListPath"), UeditorConfig.GetStringList("fileManagerAllowFiles"));
                    //    break;
                }
            }

            string result = action.Process();

            return(Content(result, ContentType.Json));
        }
Ejemplo n.º 8
0
        // GET: UEditor
        public void UeIndex()
        {
            UeHandler action  = null;
            var       context = System.Web.HttpContext.Current;

            switch (context.Request["action"])
            {
            case "config":
                action = new ConfigHandler(context);
                break;

            case "uploadimage":
                action = new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("imageAllowFiles"),
                    PathFormat      = UeditorConfig.GetString("imagePathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("imageMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("imageFieldName")
                });
                break;

            case "uploadscrawl":
                action = new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = new string[] { ".png" },
                    PathFormat      = UeditorConfig.GetString("scrawlPathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("scrawlMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("scrawlFieldName"),
                    Base64          = true,
                    Base64Filename  = "scrawl.png"
                });
                break;

            case "uploadvideo":
                action = new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("videoAllowFiles"),
                    PathFormat      = UeditorConfig.GetString("videoPathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("videoMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("videoFieldName")
                });
                break;

            case "uploadfile":
                action = new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = UeditorConfig.GetStringList("fileAllowFiles"),
                    PathFormat      = UeditorConfig.GetString("filePathFormat"),
                    SizeLimit       = UeditorConfig.GetInt("fileMaxSize"),
                    UploadFieldName = UeditorConfig.GetString("fileFieldName")
                });
                break;

            case "listimage":
                action = new ListFileManager(context, UeditorConfig.GetString("imageManagerListPath"), UeditorConfig.GetStringList("imageManagerAllowFiles"));
                break;

            case "listfile":
                action = new ListFileManager(context, UeditorConfig.GetString("fileManagerListPath"), UeditorConfig.GetStringList("fileManagerAllowFiles"));
                break;

            case "catchimage":
                action = new CrawlerHandler(context);
                break;

            default:
                action = new NotSupportedHandler(context);
                break;
            }
            action.Process();
        }