Beispiel #1
0
        public static Handler GetHandler(string action, HttpContext context)
        {
            switch (action)
            {
            case AppConsts.Action.UploadImage:
                return(new UploadHandler(context, new UploadConfig
                {
                    AllowExtensions = EditorConfig.GetStringList("imageAllowFiles"),
                    UrlPrefix = EditorConfig.GetString("imageUrlPrefix"),
                    PathFormat = EditorConfig.GetString("imagePathFormat"),
                    SizeLimit = EditorConfig.GetInt("imageMaxSize"),
                    UploadFieldName = EditorConfig.GetString("imageFieldName")
                }));

            case AppConsts.Action.UploadScrawl:
                return(new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = new string[] { ".png" },
                    UrlPrefix = EditorConfig.GetString("scrawlUrlPrefix"),
                    PathFormat = EditorConfig.GetString("scrawlPathFormat"),
                    SizeLimit = EditorConfig.GetInt("scrawlMaxSize"),
                    UploadFieldName = EditorConfig.GetString("scrawlFieldName"),
                    Base64 = true,
                    Base64Filename = "scrawl.png"
                }));

            case AppConsts.Action.UploadVideo:
                return(new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = EditorConfig.GetStringList("videoAllowFiles"),
                    UrlPrefix = EditorConfig.GetString("videoUrlPrefix"),
                    PathFormat = EditorConfig.GetString("videoPathFormat"),
                    SizeLimit = EditorConfig.GetInt("videoMaxSize"),
                    UploadFieldName = EditorConfig.GetString("videoFieldName")
                }));

            case AppConsts.Action.UploadFile:
                return(new UploadHandler(context, new UploadConfig()
                {
                    AllowExtensions = EditorConfig.GetStringList("fileAllowFiles"),
                    UrlPrefix = EditorConfig.GetString("fileUrlPrefix"),
                    PathFormat = EditorConfig.GetString("filePathFormat"),
                    SizeLimit = EditorConfig.GetInt("fileMaxSize"),
                    UploadFieldName = EditorConfig.GetString("fileFieldName")
                }));

            case AppConsts.Action.ListImage:
                return(new ListFileManager(context, EditorConfig.GetString("imageManagerListPath"), EditorConfig.GetStringList("imageManagerAllowFiles")));

            case AppConsts.Action.ListFile:
                return(new ListFileManager(context, EditorConfig.GetString("fileManagerListPath"), EditorConfig.GetStringList("fileManagerAllowFiles")));

            case AppConsts.Action.CatchImage:
                return(new CrawlerHandler(context));

            default:
                return(new NotSupportedHandler(context));
            }
        }
Beispiel #2
0
        public override async Task <UEditorResult> Process()
        {
            try
            {
                Start = string.IsNullOrWhiteSpace(Request.Query["start"]) ? 0 : Convert.ToInt32(Request.Query["start"]);
                Size  = string.IsNullOrWhiteSpace(Request.Query["size"]) ? EditorConfig.GetInt("imageManagerListSize") : Convert.ToInt32(Request.Query["size"]);
            }
            catch (FormatException)
            {
                State = ResultState.InvalidParam;
                return(WriteResult());
            }
            UEditorResult result;
            var           buildingList = new List <String>();

            try
            {
                var localPath = Path.Combine(EditorConfig.WebRootPath, 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
            {
                result = WriteResult();
            }

            return(await Task.FromResult(result));
        }
Beispiel #3
0
        public void Index()
        {
            string  action  = Request.Params["action"];
            Handler hand    = null;
            var     context = HttpContext;

            switch (action)
            {
            case "config":
                hand = new ConfigHandler(context);
                break;

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

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

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

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

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

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

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

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