Skip to content

Commit ff19a24

Browse files
author
starlying
committed
content preview
1 parent c55a46f commit ff19a24

19 files changed

Lines changed: 331 additions & 342 deletions

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,30 @@ SiteServer CMS 是.NET平台CMS系统的创始者,能够以最低的成本、
1717
└─SiteServer.Web API 源文件及aspx页面
1818
```
1919

20+
## 生成安装包
21+
22+
```code
23+
一、Visual Studio 切换解决方案配置到Release,编译
24+
二、安装NodeJs
25+
三、打开命令行,运行 npm install gulp -g
26+
四、命令行,转到根目录,运行 npm install
27+
五、命令行,运行 gulp release
28+
六、命令行,运行 gulp zip
29+
```
30+
31+
结束后会在根目录看到siteserver_install.zip,这就是安装包了。
32+
以上步骤是第一次生成安装包所需要执行的操作,如果已经生成过安装包:
33+
34+
```code
35+
一、命令行,转到根目录,运行 gulp release
36+
二、命令行,运行 gulp zip
37+
```
38+
2039
## 贡献代码
2140

2241
代码贡献有很多形式,从提交问题,撰写文档,到提交代码,我们欢迎任何形式的贡献!
2342

24-
项目编译需要使用 Visual Studio 2017,你可以从这里下载[Visual Studio Community 2017](https://www.visualstudio.com/downloads/)
43+
项目编译需要使用 Visual Studio 2017,你可以从这里下载 [Visual Studio Community 2017](https://www.visualstudio.com/downloads/)
2544

2645
- 1、Fork
2746
- 2、创建您的特性分支 (`git checkout -b my-new-feature`)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Web;
2+
using SiteServer.Utils;
3+
using SiteServer.CMS.Plugin;
4+
5+
namespace SiteServer.BackgroundPages
6+
{
7+
public abstract class BaseHandler : IHttpHandler
8+
{
9+
protected AuthRequest AuthRequest { get; private set; }
10+
11+
public void ProcessRequest(HttpContext context)
12+
{
13+
AuthRequest = new AuthRequest(context.Request);
14+
15+
if (!AuthRequest.IsAdminLoggin) return;
16+
17+
Finish(Process());
18+
}
19+
20+
protected abstract object Process();
21+
22+
protected void Finish(object retval)
23+
{
24+
var response = HttpContext.Current.Response;
25+
26+
response.ContentType = "application/json";
27+
response.Write(TranslateUtils.JsonSerialize(retval));
28+
response.End();
29+
}
30+
31+
public bool IsReusable => false;
32+
}
33+
}
Lines changed: 30 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,65 @@
1-
using System;
2-
using System.IO;
3-
using System.Web;
1+
using System.IO;
42
using SiteServer.CMS.Core;
5-
using SiteServer.CMS.Core.Office;
6-
using SiteServer.CMS.Plugin;
73
using SiteServer.Utils;
84

95
namespace SiteServer.BackgroundPages.Cms
106
{
11-
public class ModalTextEditorInsertImageHandler : IHttpHandler
7+
public class ModalTextEditorInsertImageHandler : BaseHandler
128
{
139
public static string GetRedirectUrl(int siteId)
1410
{
1511
return PageUtils.GetCmsWebHandlerUrl(siteId, nameof(ModalTextEditorInsertImageHandler), null);
1612
}
1713

18-
public void ProcessRequest(HttpContext context)
14+
protected override object Process()
1915
{
20-
var body = new AuthRequest();
16+
var fileName = AuthRequest.HttpRequest["fileName"];
2117

22-
if (!body.IsAdminLoggin) return;
23-
24-
var request = context.Request;
25-
26-
var action = request["action"];
27-
var hash = request["hash"];
28-
var fileName = request["fileName"];
29-
30-
var fileCount = request.Files.Count;
18+
var fileCount = AuthRequest.HttpRequest.Files.Count;
3119

3220
string filePath = null;
3321
string errorMessage = null;
3422

35-
var siteInfo = SiteManager.GetSiteInfo(body.SiteId);
23+
var siteInfo = SiteManager.GetSiteInfo(AuthRequest.SiteId);
3624

37-
if (string.IsNullOrEmpty(hash))
25+
if (fileCount > 0)
3826
{
39-
//普通上传
40-
if (fileCount > 0)
41-
{
42-
var file = request.Files[0];
43-
44-
//var fileName = Path.GetFileName(file.FileName);
45-
//var path = context.Server.MapPath("~/upload/" + fileName);
27+
var file = AuthRequest.HttpRequest.Files[0];
4628

47-
if (string.IsNullOrEmpty(fileName)) fileName = Path.GetFileName(file.FileName);
29+
//var fileName = Path.GetFileName(file.FileName);
30+
//var path = context.Server.MapPath("~/upload/" + fileName);
4831

49-
filePath = file.FileName;
50-
var fileExtName = PathUtils.GetExtension(filePath).ToLower();
32+
if (string.IsNullOrEmpty(fileName)) fileName = Path.GetFileName(file.FileName);
5133

52-
if (!PathUtility.IsImageExtenstionAllowed(siteInfo, fileExtName))
53-
{
54-
errorMessage = "上传失败,上传图片格式不正确!";
55-
}
56-
if (!PathUtility.IsImageSizeAllowed(siteInfo, file.ContentLength))
57-
{
58-
errorMessage = "上传失败,上传图片超出规定文件大小!";
59-
}
34+
filePath = file.FileName;
35+
var fileExtName = PathUtils.GetExtension(filePath).ToLower();
6036

61-
if (string.IsNullOrEmpty(errorMessage))
62-
{
63-
var localDirectoryPath = PathUtility.GetUploadDirectoryPath(siteInfo, fileExtName);
64-
var localFileName = PathUtility.GetUploadFileName(siteInfo, filePath);
65-
filePath = PathUtils.Combine(localDirectoryPath, localFileName);
66-
file.SaveAs(filePath);
67-
}
68-
}
69-
}
70-
else
71-
{
72-
//秒传或断点续传
73-
//var path = context.Server.MapPath("~/upload/" + hash);
74-
var path = PathUtils.GetTemporaryFilesPath(hash);
75-
76-
var fileExtName = PathUtils.GetExtension(fileName).ToLower();
77-
var localDirectoryPath = PathUtility.GetUploadDirectoryPath(siteInfo, fileExtName);
78-
var localFileName = PathUtility.GetUploadFileName(siteInfo, localDirectoryPath);
79-
var pathOk = PathUtils.Combine(localDirectoryPath, localFileName);
80-
81-
//状态查询
82-
if (action == "query")
37+
if (!PathUtility.IsImageExtenstionAllowed(siteInfo, fileExtName))
8338
{
84-
if (File.Exists(pathOk))
85-
{
86-
Finish(GetResponseJson(fileName, pathOk, string.Empty));
87-
}
88-
else if (File.Exists(path))
89-
{
90-
Finish(new FileInfo(path).Length.ToString());
91-
}
92-
else
93-
{
94-
Finish("0");
95-
}
39+
errorMessage = "上传失败,上传图片格式不正确!";
9640
}
97-
else
41+
if (!PathUtility.IsImageSizeAllowed(siteInfo, file.ContentLength))
9842
{
99-
if (fileCount > 0)
100-
{
101-
var file = request.Files[0];
102-
using (var fs = File.Open(path, FileMode.Append))
103-
{
104-
byte[] buffer = new byte[file.ContentLength];
105-
file.InputStream.Read(buffer, 0, file.ContentLength);
106-
107-
fs.Write(buffer, 0, buffer.Length);
108-
}
109-
}
110-
111-
var isOk = request["ok"] == "1";
112-
if (!isOk) Finish("1");
43+
errorMessage = "上传失败,上传图片超出规定文件大小!";
44+
}
11345

114-
if (File.Exists(path)) File.Move(path, pathOk);
46+
if (string.IsNullOrEmpty(errorMessage))
47+
{
48+
var localDirectoryPath = PathUtility.GetUploadDirectoryPath(siteInfo, fileExtName);
49+
var localFileName = PathUtility.GetUploadFileName(siteInfo, filePath);
50+
filePath = PathUtils.Combine(localDirectoryPath, localFileName);
51+
file.SaveAs(filePath);
11552
}
11653
}
11754

118-
Finish(GetResponseJson(fileName, filePath, errorMessage));
55+
return GetResponseObject(fileName, filePath, errorMessage);
11956
}
12057

12158
/// <summary>
12259
/// 获取返回的json字符串
12360
/// </summary>
12461
/// <returns></returns>
125-
private static string GetResponseJson(string fileName, string filePath, string errorMessage)
62+
private static object GetResponseObject(string fileName, string filePath, string errorMessage)
12663
{
12764
FileInfo file = null;
12865
if (!string.IsNullOrEmpty(filePath))
@@ -131,34 +68,20 @@ private static string GetResponseJson(string fileName, string filePath, string e
13168
}
13269
if (file != null)
13370
{
134-
return TranslateUtils.JsonSerialize(new
71+
return new
13572
{
13673
fileName,
13774
filePath,
13875
length = file?.Length,
13976
ret = 1
140-
});
77+
};
14178
}
14279

143-
return TranslateUtils.JsonSerialize(new
80+
return new
14481
{
14582
ret = 0,
14683
errorMessage
147-
});
148-
}
149-
150-
/// <summary>
151-
/// 完成上传
152-
/// </summary>
153-
/// <param name="json">回调函数参数</param>
154-
private static void Finish(string json)
155-
{
156-
var response = HttpContext.Current.Response;
157-
158-
response.Write(json);
159-
response.End();
84+
};
16085
}
161-
162-
public bool IsReusable => false;
16386
}
16487
}

0 commit comments

Comments
 (0)