Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-arena-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
ygopro-arena-api
Commits
2f640781
Commit
2f640781
authored
Jun 03, 2017
by
ganjingcun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件上传
parent
ceed3e79
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
0 deletions
+51
-0
.gitignore
.gitignore
+1
-0
app.js
app.js
+1
-0
package.json
package.json
+1
-0
routes/api.js
routes/api.js
+9
-0
routes/file.js
routes/file.js
+39
-0
No files found.
.gitignore
View file @
2f640781
...
...
@@ -8,3 +8,4 @@ test/e2e/reports
db.config.js
test.js
db.sql
upload/
app.js
View file @
2f640781
...
...
@@ -35,6 +35,7 @@ app.use(bodyParser.json());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
cookieParser
());
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'
public
'
)));
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
'
upload
'
)));
app
.
use
(
'
/
'
,
index
);
app
.
use
(
'
/users
'
,
users
);
...
...
package.json
View file @
2f640781
...
...
@@ -13,6 +13,7 @@
"
debug
"
:
"
~2.2.0
"
,
"
eventproxy
"
:
"
^0.3.5
"
,
"
express
"
:
"
~4.14.0
"
,
"
formidable
"
:
"
^1.1.1
"
,
"
jade
"
:
"
~1.11.0
"
,
"
moment
"
:
"
^2.18.1
"
,
"
morgan
"
:
"
~1.7.0
"
,
...
...
routes/api.js
View file @
2f640781
...
...
@@ -483,6 +483,13 @@ router.get('/deckinfo', function (req, res) {
});
});
var
file
=
require
(
"
./file.js
"
);
router
.
post
(
'
/upload
'
,
file
.
upload
);
router
.
get
(
'
/download/:id
'
,
file
.
download
);
router
.
post
(
'
/deckinfo
'
,
function
(
req
,
res
)
{
let
author
=
req
.
body
.
user
;
...
...
@@ -641,6 +648,7 @@ router.get('/user', function (req, res) {
// to run a query we can acquire a client from the pool,
// run a query on the client, and then return the client to the pool
pool
.
connect
(
function
(
err
,
client
,
done
)
{
if
(
err
)
{
return
console
.
error
(
'
error fetching client from pool
'
,
err
);
}
...
...
@@ -666,6 +674,7 @@ router.get('/user', function (req, res) {
if
(
!
username
)
{
// return res.status(404).send('username can not be null')
done
();
return
res
.
json
(
resultData
)
}
...
...
routes/file.js
0 → 100644
View file @
2f640781
var
formidable
=
require
(
'
formidable
'
);
var
fs
=
require
(
'
fs
'
);
//node.js核心的文件处理模块
exports
.
upload
=
function
(
req
,
res
,
next
)
{
var
message
=
''
;
var
form
=
new
formidable
.
IncomingForm
();
form
.
encoding
=
'
utf-8
'
;
form
.
uploadDir
=
'
upload/
'
;
form
.
keepExtensions
=
true
;
form
.
maxFieldsSize
=
2
*
1024
*
1024
;
form
.
parse
(
req
,
function
(
err
,
fields
,
files
)
{
if
(
err
)
{
console
.
log
(
err
);
return
res
.
status
(
500
).
send
(
'
upload image fail!
'
)
}
console
.
log
(
files
)
console
.
log
(
files
.
file
.
path
)
var
response
=
{};
if
(
err
)
{
response
.
code
=
500
;
}
else
{
response
.
code
=
200
;
response
.
path
=
files
.
file
.
path
;
}
res
.
json
(
response
);
});
};
exports
.
download
=
function
(
req
,
res
)
{
var
filename
=
req
.
params
.
id
var
filepath
=
'
upload/
'
+
filename
// filename:设置下载时文件的文件名,可不填,则为原名称
res
.
download
(
filepath
,
filename
);
};
\ No newline at end of file
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