Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
srvpro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
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
srvpro
Commits
de0fb898
Commit
de0fb898
authored
Mar 18, 2018
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update the update util
parent
775e712a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
30 deletions
+75
-30
data/default_config.json
data/default_config.json
+2
-0
ygopro-update.js
ygopro-update.js
+73
-30
No files found.
data/default_config.json
View file @
de0fb898
...
...
@@ -207,6 +207,8 @@
"password"
:
"123456"
,
"git_html_path"
:
"../ygo233-web/"
,
"html_path"
:
"../ygo233-web/"
,
"cdb_path"
:
"./ygopro/cards.cdb"
,
"script_path"
:
"./ygopro/script"
,
"changelog_filename"
:
"changelog.json"
,
"html_gits"
:
[
{
...
...
ygopro-update.js
View file @
de0fb898
...
...
@@ -63,8 +63,9 @@ var loadDb = function(db_file) {
}
});
}
var
loadChangelog
=
function
(
json_file
)
{
changelog
=
JSON
.
parse
(
fs
.
readFileSync
(
json_file
,
'
utf8
'
)
).
changelog
;
changelog
=
loadJSON
(
json_file
).
changelog
;
sendResponse
(
"
已加载更新记录
"
+
json_file
+
"
,共
"
+
changelog
.
length
+
"
条,最后更新于
"
+
changelog
[
0
].
date
+
"
。
"
);
}
...
...
@@ -114,21 +115,28 @@ var makeChangelogs = function(dir, since) {
}
}
sendResponse
(
"
新增卡片:
"
);
var
fullLog
=
[];
fullLog
.
push
(
"
新增卡片:
"
);
for
(
var
i
in
addedCards
)
{
sendResponse
(
"
-
"
+
addedCards
[
i
]);
fullLog
.
push
(
"
-
"
+
addedCards
[
i
]);
}
if
(
addedCards
.
length
==
0
)
{
sendResponse
(
"
-
无
"
);
fullLog
.
push
(
"
-
无
"
);
}
sendResponse
(
"
\n
"
);
sendResponse
(
"
卡片更改:
"
);
fullLog
.
push
(
"
"
);
fullLog
.
push
(
"
卡片更改:
"
);
for
(
var
i
in
changedCards
)
{
sendResponse
(
"
-
"
+
changedCards
[
i
]);
fullLog
.
push
(
"
-
"
+
changedCards
[
i
]);
}
if
(
changedCards
.
length
==
0
)
{
sendResponse
(
"
-
无
"
);
fullLog
.
push
(
"
-
无
"
);
}
fullLog
.
push
(
"
\n
"
);
var
resJSON
=
{};
resJSON
.
type
=
"
changelog
"
;
resJSON
.
changelog
=
fullLog
;
sendResponse
(
JSON
.
stringify
(
resJSON
));
}
else
{
sendResponse
(
"
获取更新记录失败:
"
+
prc_git_log
.
stderr
.
toString
());
}
...
...
@@ -136,7 +144,7 @@ var makeChangelogs = function(dir, since) {
//从远程更新数据库,异步
var
fetchDatas
=
function
()
{
var
proc
=
spawn
(
"
git
"
,
[
"
pull
"
,
"
origin
"
,
"
master
"
],
{
cwd
:
config
.
git_
db
_path
,
env
:
process
.
env
});
var
proc
=
spawn
(
"
git
"
,
[
"
pull
"
,
"
origin
"
,
"
master
"
],
{
cwd
:
config
.
git_
html
_path
,
env
:
process
.
env
});
proc
.
stdout
.
setEncoding
(
'
utf8
'
);
proc
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
sendResponse
(
"
git pull:
"
+
data
);
...
...
@@ -146,22 +154,52 @@ var fetchDatas = function() {
sendResponse
(
"
git pull:
"
+
data
);
});
proc
.
on
(
'
close
'
,
function
(
code
)
{
sendResponse
(
"
数据更新完成。
"
);
});
var
proc2
=
spawn
(
"
git
"
,
[
"
pull
"
,
"
origin
"
,
"
master
"
],
{
cwd
:
config
.
git_html_path
,
env
:
process
.
env
});
proc2
.
stdout
.
setEncoding
(
'
utf8
'
);
proc2
.
stdout
.
on
(
'
data
'
,
function
(
data
)
{
sendResponse
(
"
git pull:
"
+
data
);
});
proc2
.
stderr
.
setEncoding
(
'
utf8
'
);
proc2
.
stderr
.
on
(
'
data
'
,
function
(
data
)
{
sendResponse
(
"
git pull:
"
+
data
);
});
proc2
.
on
(
'
close
'
,
function
(
code
)
{
sendResponse
(
"
网页同步完成。
"
);
});
}
var
updateChangelogs
=
function
(
message
)
{
message
=
message
.
split
(
"
!换行符!
"
).
join
(
"
\n
"
);
change_log
=
{};
change_log
.
title
=
"
服务器更新
"
;
change_log
.
date
=
moment
().
format
(
"
YYYY-MM-DD
"
);
change_log
.
text
=
message
;
changelog
.
unshift
(
change_log
);
fileContent
=
JSON
.
stringify
({
changelog
:
changelog
},
null
,
2
);
fs
.
writeFileSync
(
config
.
html_path
+
config
.
changelog_filename
,
fileContent
);
sendResponse
(
"
更新完成,共有
"
+
changelog
.
length
+
"
条记录。
"
);
}
var
pushHTMLs
=
function
()
{
try
{
execSync
(
'
git add
'
+
config
.
changelog_filename
,
{
cwd
:
config
.
git_html_path
,
env
:
process
.
env
});
//execSync('git commit -m update-auto', { cwd: config.git_html_path, env: process.env });
}
catch
(
error
)
{
sendResponse
(
"
git error:
"
+
error
.
stdout
);
}
for
(
var
i
in
config
.
html_gits
)
{
var
git
=
config
.
html_gits
[
i
];
var
proc
=
spawn
(
"
git
"
,
git
.
push
,
{
cwd
:
config
.
git_html_path
,
env
:
process
.
env
});
proc
.
stdout
.
setEncoding
(
'
utf8
'
);
proc
.
stdout
.
on
(
'
data
'
,
(
function
(
git
)
{
return
function
(
data
)
{
sendResponse
(
git
.
name
+
"
git push:
"
+
data
);
}
})(
git
));
proc
.
stderr
.
setEncoding
(
'
utf8
'
);
proc
.
stderr
.
on
(
'
data
'
,
(
function
(
git
)
{
return
function
(
data
)
{
sendResponse
(
git
.
name
+
"
git push:
"
+
data
);
}
})(
git
));
proc
.
on
(
'
close
'
,
(
function
(
git
)
{
return
function
(
code
)
{
sendResponse
(
git
.
name
+
"
上传完成。
"
);
}
})(
git
));
}
}
//建立一个http服务器,接收API操作
http
.
createServer
(
function
(
req
,
res
)
{
...
...
@@ -189,32 +227,37 @@ http.createServer(function (req, res) {
sendResponse
(
"
已连接。
"
);
}
else
if
(
u
.
pathname
===
'
/api/fetch_datas
'
)
{
res
.
writeHead
(
200
);
res
.
end
(
u
.
query
.
callback
+
'
({"message":"开始更新网页。"});
'
);
fetchDatas
();
}
else
if
(
u
.
pathname
===
'
/api/load_db
'
)
{
res
.
writeHead
(
200
);
res
.
end
(
u
.
query
.
callback
+
'
({"message":"开始加载数据库。"});
'
);
loadDb
(
"
./ygopro/cards.cdb
"
);
loadDb
(
config
.
cdb_path
);
loadChangelog
(
config
.
html_path
+
config
.
changelog_filename
);
}
else
if
(
u
.
pathname
===
'
/api/make_changelog
'
)
{
res
.
writeHead
(
200
);
var
date
=
moment
(
changelog
[
0
].
date
).
add
(
1
,
'
days
'
).
format
(
"
YYYY-MM-DD
"
);
res
.
end
(
u
.
query
.
callback
+
'
({"message":"开始生成
'
+
date
+
'
以来的更新记录:"});
'
);
makeChangelogs
(
"
./ygopro/script
"
,
"
--since=
"
+
date
);
makeChangelogs
(
config
.
script_path
,
"
--since=
"
+
date
);
}
else
if
(
u
.
pathname
===
'
/api/make_more_changelog
'
)
{
res
.
writeHead
(
200
);
res
.
end
(
u
.
query
.
callback
+
'
({"message":"开始生成最近20次的更新记录:"});
'
);
makeChangelogs
(
"
./ygopro/script
"
,
"
-20
"
);
makeChangelogs
(
config
.
script_path
,
"
-20
"
);
}
else
if
(
u
.
pathname
===
'
/api/
push_datas
'
)
{
else
if
(
u
.
pathname
===
'
/api/
update_changelog
'
)
{
res
.
writeHead
(
200
);
res
.
end
(
u
.
query
.
callback
+
'
({"message":"开始
上传到网页
。"});
'
);
pushDatas
(
);
res
.
end
(
u
.
query
.
callback
+
'
({"message":"开始
写入更新记录
。"});
'
);
updateChangelogs
(
u
.
query
.
message
);
}
else
if
(
u
.
pathname
===
'
/api/
write_to_file
'
)
{
else
if
(
u
.
pathname
===
'
/api/
push_datas
'
)
{
res
.
writeHead
(
200
);
res
.
end
(
u
.
query
.
callback
+
'
({"message":"开始
写列表
页。"});
'
);
writeToFile
(
u
.
query
.
message
);
res
.
end
(
u
.
query
.
callback
+
'
({"message":"开始
上传到网
页。"});
'
);
pushHTMLs
(
);
}
else
{
res
.
writeHead
(
400
);
...
...
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