Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yuyiFileServer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node_server
yuyiFileServer
Commits
5df9ec53
Commit
5df9ec53
authored
Jan 01, 2026
by
chenjinjing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
1439523c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
69 additions
and
18 deletions
+69
-18
.gitignore
.gitignore
+2
-0
package-lock.json
package-lock.json
+0
-0
serverConfig.xml
serverConfig.xml
+3
-2
dbEnum.ts
src/config/enums/dbEnum.ts
+1
-1
errorEnum.ts
src/config/enums/errorEnum.ts
+1
-1
fromParam.ts
src/middleware/fromParam.ts
+8
-4
http_server.ts
src/net/http_server.ts
+53
-9
router.ts
src/routers/router.ts
+1
-1
No files found.
.gitignore
View file @
5df9ec53
...
...
@@ -7,3 +7,5 @@
/video
*.logs
*.zip
/res
/files
package-lock.json
View file @
5df9ec53
This diff is collapsed.
Click to expand it.
serverConfig.xml
View file @
5df9ec53
<config>
<port>
9097
</port>
<sign>
xxx90909082fsdahfjosadjfpoiwausjorip2hjklrhn1ioud0u124rx0qwejfokasjfolksaujfoas
</sign>
<dbServer>
http://192.168.0.189:9096
</dbServer>
<fileIP>
http://127.0.0.1:40004
</fileIP>
<dbServer>
http://192.168.0.71:40012
</dbServer>
<fileIP>
http://192.168.0.71:40004
</fileIP>
<SECRET_TOKEN>
Ngz86cuAKxblwXR9OiKSWbfkj7oZ8R0lMU8pTfpVYBDCkvtUb0ZwbaBvwWyfv2O9
</SECRET_TOKEN>
</config>
src/config/enums/dbEnum.ts
View file @
5df9ec53
...
...
@@ -10,6 +10,6 @@ export enum OPERATIONALDATATYPE {
*/
export
enum
TABLENAME
{
企业用户表
=
'enterprise_user'
,
管理后台用户
=
'admin
U
ser'
,
管理后台用户
=
'admin
u
ser'
,
企业基础信息表
=
'enterprise'
}
src/config/enums/errorEnum.ts
View file @
5df9ec53
...
...
@@ -5,7 +5,7 @@ export enum ERRORENUM {
身份验证过期
,
参数错误
,
文件上传失败
,
只能上传
doc
或
docx
或
png
或
jpg
图片
,
只能上传
doc
或
docx
或
excel
或
png
或
jpg
图片
,
上传时缺失关键参数
,
预检请求
,
空文件失败
...
...
src/middleware/fromParam.ts
View file @
5df9ec53
...
...
@@ -19,7 +19,6 @@ export async function parseFormParam(req, res, next) {
maxFildsSize
:
10
*
1024
*
1024
,
keepExtensions
:
true
});
form
.
parse
(
req
,
(
err
,
fields
,
files
)
=>
{
if
(
err
)
{
...
...
@@ -43,14 +42,16 @@ export async function parseFormParam(req, res, next) {
if
(
!
req
.
files
.
formData
||
!
req
.
files
.
formData
.
name
)
{
return
next
(
new
BizError
(
ERRORENUM
.
文件上传失败
)
);
}
console
.
log
(
req
.
files
.
formData
.
type
);
//获取文件扩展名
const
fileExtension
=
req
.
files
.
formData
.
name
.
split
(
'.'
).
pop
().
toLowerCase
();
if
(
req
.
files
.
formData
.
type
==
'image/png'
)
{
req
.
fileType
=
'.png'
;
return
next
();
}
else
if
(
req
.
files
.
formData
.
type
==
'image/jpg'
||
req
.
files
.
formData
.
type
==
'image/jpeg'
)
{
req
.
fileType
=
'.jpg'
;
return
next
();
}
else
if
(
req
.
files
.
formData
.
type
==
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
)
{
}
else
if
(
req
.
files
.
formData
.
type
==
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
||
fileExtension
==
'docx'
)
{
req
.
fileType
=
'.docx'
;
return
next
();
}
else
if
(
req
.
files
.
formData
.
type
==
"application/msword"
)
{
...
...
@@ -62,8 +63,11 @@ export async function parseFormParam(req, res, next) {
}
else
if
(
req
.
files
.
formData
.
type
==
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
){
req
.
fileType
=
'.xlsx'
;
return
next
();
}
else
if
(
req
.
files
.
formData
.
type
==
"application/vnd.ms-excel"
){
req
.
fileType
=
'.xls'
;
return
next
();
}
else
{
return
next
(
new
BizError
(
ERRORENUM
.
只能上传
doc
或
docx
或
png
或
jpg
图片
)
)
return
next
(
new
BizError
(
ERRORENUM
.
只能上传
doc
或
docx
或
excel
或
png
或
jpg
图片
)
)
}
}
})
...
...
src/net/http_server.ts
View file @
5df9ec53
...
...
@@ -5,30 +5,63 @@ import compression = require('compression');
import
{
watch
}
from
'../middleware/watch'
;
import
{
httpErrorHandler
}
from
'../middleware/httpErrorHandler'
;
import
{
authentication
}
from
'../middleware/user'
;
import
path
=
require
(
'path'
);
export
class
httpServer
{
static
createServer
(
port
:
number
)
{
var
httpServer
=
express
();
const
SECRET_TOKEN
=
"Ngz86cuAKxblwXR9OiKSWbfkj7oZ8R0lMU8pTfpVYBDCkvtUb0ZwbaBvwWyfv2O9"
;
const
FILES_BASE_PATH
=
'/yuyi/files'
;
// 全局 CORS 设置(处理 OPTIONS 预检请求)
httpServer
.
all
(
'*'
,
(
req
,
res
,
next
)
=>
{
res
.
header
(
'Access-Control-Allow-Origin'
,
req
.
headers
.
origin
);
res
.
header
(
"Access-Control-Allow-Headers"
,
"X-Requested-With"
);
res
.
header
(
'Access-Control-Allow-Headers'
,
'Content-Type,request-origin,userid,Userid,Token,token,uptype'
);
res
.
header
(
"Access-Control-Allow-Methods"
,
"PUT,POST,GET,DELETE,OPTIONS"
);
res
.
header
(
'Access-Control-Allow-Origin'
,
req
.
headers
.
origin
||
'*'
);
res
.
header
(
'Access-Control-Allow-Headers'
,
'Content-Type, Authorization, authorization, request-origin, userid, Userid, Token, token, uptype'
);
res
.
header
(
'Access-Control-Allow-Methods'
,
'GET, POST, PUT, DELETE, OPTIONS'
);
res
.
header
(
'Access-Control-Allow-Credentials'
,
'true'
);
res
.
header
(
"X-Powered-By"
,
' 3.2.1'
);
res
.
header
(
'X-Powered-By'
,
'3.2.1'
);
// 直接响应 OPTIONS 预检请求
if
(
req
.
method
===
'OPTIONS'
)
{
return
res
.
status
(
200
).
end
();
}
next
();
});
// httpServer.use(bodyParser.json({limit:'5mb'}));
// httpServer.use(bodyParser.urlencoded({limit:'5mb', extends:true}));
// 文件下载的授权验证中间件(跳过 OPTIONS 请求)
httpServer
.
use
(
FILES_BASE_PATH
,
(
req
,
res
,
next
)
=>
{
const
filePath
=
path
.
join
(
__dirname
,
'../../files'
,
req
.
url
.
replace
(
FILES_BASE_PATH
,
''
));
console
.
log
(
'请求文件路径:'
,
filePath
);
// 调试日志
console
.
log
(
'请求方法:'
,
req
.
method
);
// 添加日志
if
(
req
.
method
===
'OPTIONS'
||
req
.
method
===
'HEAD'
)
{
return
next
();
}
const
authHeader
=
req
.
headers
[
'token'
];
console
.
log
(
'认证token:'
,
authHeader
);
// 调试日志
if
(
authHeader
===
SECRET_TOKEN
)
{
next
();
}
else
{
res
.
status
(
401
).
json
({
code
:
401
,
message
:
'Unauthorized: Missing or invalid Authorization header'
});
}
});
// 设置静态文件服务,只对/yuyi/files路径生效
// httpServer.use(FILES_BASE_PATH, express.static(path.join(__dirname, '../../files')));
httpServer
.
use
(
FILES_BASE_PATH
,
express
.
static
(
path
.
join
(
__dirname
,
'../../files/yuyi/files'
)));
httpServer
.
use
(
watch
);
httpServer
.
use
(
authentication
);
httpServer
.
use
(
express
.
static
(
"./files"
)
);
//
httpServer.use( express.static("./files") );
httpServer
.
use
(
compression
());
...
...
@@ -39,4 +72,16 @@ export class httpServer {
httpServer
.
listen
(
port
);
console
.
log
(
'server listen on port:'
+
port
);
}
}
\ No newline at end of file
}
// // 验证函数
// function validateToken(Authorization: string): boolean {
// let result = false;
// if (Authorization == "Ngz86cuAKxblwXR9OiKSWbfkj7oZ8R0lMU8pTfpVYBDCkvtUb0ZwbaBvwWyfv2O9") {
// result = true;
// }
// return result; // 示例代码,实际使用时需要替换
// }
src/routers/router.ts
View file @
5df9ec53
/**
* 总路由入口
*/
import
*
as
asyncHandler
from
'express-async-handler'
import
asyncHandler
=
require
(
'express-async-handler'
);
import
{
parseFormParam
}
from
'../middleware/fromParam'
;
import
{
getFilesId
}
from
'../tools/systemTools'
;
const
fs
=
require
(
'fs'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment