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
b88e5275
Commit
b88e5275
authored
Apr 14, 2017
by
ganjingcun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deckinfo
parent
3caa8a15
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
12 deletions
+106
-12
app.js
app.js
+11
-11
package.json
package.json
+1
-0
routes/api.js
routes/api.js
+94
-1
No files found.
app.js
View file @
b88e5275
...
...
@@ -16,17 +16,17 @@ app.set('views', path.join(__dirname, 'views'));
app
.
set
(
'
view engine
'
,
'
jade
'
);
//allow custom header and CORS
//
app.all('*', function (req, res, next) {
//
res.header('Access-Control-Allow-Origin', '*');
//
// res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
//
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
//
if (req.method == 'OPTIONS') {
// res.send
(200);
//
}
//
else {
//
next();
//
}
//
});
app
.
all
(
'
*
'
,
function
(
req
,
res
,
next
)
{
res
.
header
(
'
Access-Control-Allow-Origin
'
,
'
*
'
);
// res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
res
.
header
(
'
Access-Control-Allow-Methods
'
,
'
PUT, POST, GET, DELETE, OPTIONS
'
);
if
(
req
.
method
==
'
OPTIONS
'
)
{
res
.
sendStatus
(
200
);
}
else
{
next
();
}
});
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
...
...
package.json
View file @
b88e5275
...
...
@@ -13,6 +13,7 @@
"
eventproxy
"
:
"
^0.3.5
"
,
"
express
"
:
"
~4.14.0
"
,
"
jade
"
:
"
~1.11.0
"
,
"
moment
"
:
"
^2.18.1
"
,
"
morgan
"
:
"
~1.7.0
"
,
"
pg
"
:
"
^6.1.0
"
,
"
serve-favicon
"
:
"
~2.3.0
"
,
...
...
routes/api.js
View file @
b88e5275
...
...
@@ -7,6 +7,7 @@ var pg = require('pg')
var
eventproxy
=
require
(
'
eventproxy
'
)
var
utils
=
require
(
'
../utils/utils
'
)
var
sqlite3
=
require
(
'
sqlite3
'
).
verbose
();
var
moment
=
require
(
'
moment
'
)
var
config
=
require
(
'
../db.config
'
)
var
cardinfo
=
require
(
'
../cardinfo
'
)
...
...
@@ -325,7 +326,7 @@ router.get('/cardinfo', function (req, res) {
if
(
row
.
level
<=
12
)
{
result
.
level
=
row
.
level
}
else
{
}
else
{
//转化为16位,0x01010004,前2位是左刻度,2-4是右刻度,末2位是等级
var
levelHex
=
parseInt
(
row
.
level
,
10
).
toString
(
16
);
cardLevel
=
parseInt
(
levelHex
.
slice
(
-
2
),
16
);
...
...
@@ -349,6 +350,98 @@ router.get('/cardinfo', function (req, res) {
});
});
router
.
get
(
'
/deckinfo
'
,
function
(
req
,
res
)
{
var
name
=
req
.
query
.
name
if
(
!
name
)
{
return
res
.
status
(
404
).
send
(
'
deck name is required!
'
)
}
// 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
);
}
var
sql
=
`SELECT * from deck_info where name = '
${
name
}
'`
console
.
log
(
sql
);
client
.
query
(
sql
,
function
(
err
,
result
)
{
done
()
var
response
=
{};
if
(
!
result
||
result
.
rowCount
===
0
)
{
response
.
code
=
404
}
else
{
response
.
code
=
200
response
.
data
=
result
.
rows
[
0
]
}
res
.
json
(
response
);
});
});
});
router
.
post
(
'
/deckinfo
'
,
function
(
req
,
res
)
{
let
user
=
req
.
body
.
user
;
let
name
=
req
.
body
.
name
;
let
desc
=
req
.
body
.
desc
;
let
img_url
=
req
.
body
.
url
;
let
isNew
=
req
.
body
.
isNew
;
console
.
log
(
"
user is
"
,
user
)
console
.
log
(
"
name is
"
,
name
)
console
.
log
(
"
desc is
"
,
desc
)
console
.
log
(
"
img_url is
"
,
img_url
)
console
.
log
(
"
isNew is
"
,
isNew
)
console
.
log
(
"
isNew is
"
,
typeof
isNew
)
if
(
!
name
)
{
return
res
.
status
(
404
).
send
(
'
deck name is required!
'
)
}
// 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
);
}
var
sql
;
if
(
isNew
===
"
true
"
)
{
var
start_time
=
moment
().
format
(
'
YYYY-MM-DD HH:mm
'
)
sql
=
`insert into deck_info (name, content, url, start_time) values (
'
${
name
}
',
'
${
desc
}
',
'
${
img_url
}
',
'
${
start_time
}
'
)`
;
}
else
{
var
end_time
=
moment
().
format
(
'
YYYY-MM-DD HH:mm
'
)
sql
=
`update deck_info set
content = '
${
desc
}
',
url = '
${
img_url
}
',
end_time = '
${
end_time
}
'
where name = '
${
name
}
'`
;
}
console
.
log
(
sql
);
client
.
query
(
sql
,
function
(
err
,
result
)
{
var
response
=
{};
if
(
err
)
{
response
.
code
=
500
;
}
else
{
response
.
code
=
200
;
}
res
.
json
(
response
);
});
});
});
router
.
get
(
'
/history
'
,
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
...
...
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