editorSrv.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using SiteCore.ueditor;
  2. using System.Web;
  3. using System.Web.SessionState;
  4. namespace SiteCore.Handler
  5. {
  6. public class editorSrv : BaseHandler, IHttpHandler, IRequiresSessionState
  7. {
  8. public void ProcessRequest(HttpContext context)
  9. {
  10. con = context;
  11. ueditor.Handler action = null;
  12. switch (context.Request["action"])
  13. {
  14. case "config":
  15. action = new ConfigHandler(context);
  16. break;
  17. case "uploadimage":
  18. action = new UploadHandler(context, new UploadConfig()
  19. {
  20. AllowExtensions = Config.GetStringList("imageAllowFiles"),
  21. PathFormat = Config.GetString("imagePathFormat"),
  22. SizeLimit = Config.GetInt("imageMaxSize"),
  23. UploadFieldName = Config.GetString("imageFieldName")
  24. });
  25. //string err = "{\"originalName\":\"\",\"name\":\"\",\"url\":\"\",\"size\":\"0\",\"state\":\"没有上传文件\",\"type\":\"jpg\"}";
  26. //if (context.Request.Files.Count < 1)
  27. //{
  28. // context.Response.Write(err);
  29. // return;
  30. //}
  31. //string fn = CurrentUser.UserID + "_" + DateTime.Now.ToString("yyMMddHHmmss");
  32. //try
  33. //{
  34. // HttpPostedFile postFile = context.Request.Files[0];
  35. // if (postFile != null)
  36. // {
  37. // string errMsg = "";
  38. // if (!ImageHandler.CheckImage(postFile, out errMsg)) return;
  39. // string saveFile = Path.Combine(webConfig.umPicPath, fn + ".jpg");
  40. // string result = "";
  41. // using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(postFile.InputStream))
  42. // {
  43. // result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 800, "", 9, 3);
  44. // }
  45. // context.Response.Write("{\"originalName\":\"" + postFile.FileName + "\",\"name\":\"" + fn + ".jpg\",\"url\":\"" + fn + ".jpg\",\"size\":\"0\",\"state\":\"SUCCESS\",\"type\":\"jpg\"}");
  46. // return;
  47. // }
  48. //}
  49. //catch
  50. //{
  51. // context.Response.Write("{\"originalName\":\"\",\"name\":\"\",\"url\":\"上传成功!\",\"size\":\"0\",\"state\":\"图片上专失败\",\"type\":\"jpg\"}");
  52. // return;
  53. //}
  54. break;
  55. case "uploadscrawl":
  56. action = new UploadHandler(context, new UploadConfig()
  57. {
  58. AllowExtensions = new string[] { ".png" },
  59. PathFormat = Config.GetString("scrawlPathFormat"),
  60. SizeLimit = Config.GetInt("scrawlMaxSize"),
  61. UploadFieldName = Config.GetString("scrawlFieldName"),
  62. Base64 = true,
  63. Base64Filename = "scrawl.png"
  64. });
  65. break;
  66. case "uploadvideo":
  67. action = new UploadHandler(context, new UploadConfig()
  68. {
  69. AllowExtensions = Config.GetStringList("videoAllowFiles"),
  70. PathFormat = Config.GetString("videoPathFormat"),
  71. SizeLimit = Config.GetInt("videoMaxSize"),
  72. UploadFieldName = Config.GetString("videoFieldName")
  73. });
  74. break;
  75. case "uploadfile":
  76. action = new UploadHandler(context, new UploadConfig()
  77. {
  78. AllowExtensions = Config.GetStringList("fileAllowFiles"),
  79. PathFormat = Config.GetString("filePathFormat"),
  80. SizeLimit = Config.GetInt("fileMaxSize"),
  81. UploadFieldName = Config.GetString("fileFieldName")
  82. });
  83. break;
  84. case "listimage":
  85. action = new ListFileManager(context, Config.GetString("imageManagerListPath"), Config.GetStringList("imageManagerAllowFiles"));
  86. break;
  87. case "listfile":
  88. action = new ListFileManager(context, Config.GetString("fileManagerListPath"), Config.GetStringList("fileManagerAllowFiles"));
  89. break;
  90. case "catchimage":
  91. action = new CrawlerHandler(context);
  92. break;
  93. default:
  94. action = new NotSupportedHandler(context);
  95. break;
  96. }
  97. action.Process();
  98. }
  99. }
  100. }