Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
Ygopro Cdb Descgen
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 Cdb Descgen
Commits
b261aa18
Commit
b261aa18
authored
Dec 28, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add git ref things
parent
9f838a29
Pipeline
#24711
passed with stages
in 3 minutes and 40 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
3 deletions
+100
-3
Dockerfile
Dockerfile
+1
-1
index.ts
index.ts
+99
-2
No files found.
Dockerfile
View file @
b261aa18
FROM
node:lts-bookworm-slim as base
LABEL
Author="Nanahira <nanahira@momobako.com>"
RUN
apt update
&&
apt
-y
install
python3 build-essential
&&
rm
-rf
/var/lib/apt/lists/
*
/tmp/
*
/var/tmp/
*
/var/log/
*
RUN
apt update
&&
apt
-y
install
python3 build-essential
git
&&
rm
-rf
/var/lib/apt/lists/
*
/tmp/
*
/var/tmp/
*
/var/log/
*
WORKDIR
/usr/src/app
COPY
./package*.json ./
...
...
index.ts
View file @
b261aa18
import
fs
from
'
fs
'
;
import
initSqlJs
from
'
sql.js
'
;
import
SQL
from
'
sql.js
'
;
import
child_process
from
'
child_process
'
;
import
util
from
'
util
'
;
const
execFileAsync
=
util
.
promisify
(
child_process
.
execFile
);
const
systemStrings
=
new
Map
<
number
,
string
>
();
const
setcodeStrings
=
new
Map
<
number
,
string
>
();
...
...
@@ -122,6 +125,12 @@ interface YGOProCard extends YGOProCardLike {
sets
:
string
[];
overallString
:
string
;
picUrl
:
string
;
createTime
?:
number
;
createCommit
?:
string
;
updateTime
?:
number
;
updateCommit
?:
string
;
created
?:
boolean
;
updated
?:
boolean
;
}
const
ygoproConstants
=
{
...
...
@@ -202,7 +211,86 @@ function getMetaText(data: Partial<YGOProCard>) {
return
lines
.
join
(
'
'
);
}
function
formatCard
(
data
:
YGOProCardLike
):
YGOProCard
{
async
function
getCardHistory
(
data
:
YGOProCardLike
)
{
const
gitPath
=
process
.
env
.
GIT_PATH
;
if
(
!
gitPath
)
return
;
const
filename
=
data
.
type
===
(
ygoproConstants
.
TYPES
.
TYPE_MONSTER
|
ygoproConstants
.
TYPES
.
TYPE_NORMAL
)
?
`pics/
${
data
.
id
}
.jpg`
:
`script/c
${
data
.
id
}
.lua`
;
const
{
stdout
}
=
await
execFileAsync
(
'
git
'
,
[
'
log
'
,
'
--follow
'
,
'
--format=%ct,%H
'
,
'
--
'
,
filename
],
{
cwd
:
gitPath
,
},
);
if
(
!
stdout
?.
length
)
return
;
const
stdoutLines
=
stdout
.
trim
().
split
(
'
\n
'
);
const
commits
=
stdoutLines
.
map
((
line
)
=>
{
const
[
timestamp
,
commit
]
=
line
.
split
(
'
,
'
);
return
{
timestamp
:
parseInt
(
timestamp
),
commit
,
};
});
const
createCommit
=
commits
[
commits
.
length
-
1
];
const
updateCommit
=
commits
[
0
];
const
refCommitHash
=
process
.
env
.
REF_COMMIT
;
const
res
:
{
createTime
:
number
;
createCommit
:
string
;
updateTime
:
number
;
updateCommit
:
string
;
created
?:
boolean
;
updated
?:
boolean
;
}
=
{
createTime
:
createCommit
.
timestamp
,
createCommit
:
createCommit
.
commit
,
updateTime
:
updateCommit
.
timestamp
,
updateCommit
:
updateCommit
.
commit
,
};
if
(
refCommitHash
)
{
// diff against ref commit to see if the card is created/updated
const
{
stdout
:
createdStdout
}
=
await
execFileAsync
(
'
git
'
,
[
'
diff
'
,
'
--name-only
'
,
'
--diff-filter=A
'
,
refCommitHash
,
'
--
'
,
filename
],
{
cwd
:
gitPath
,
},
);
if
(
createdStdout
?.
trim
()?.
length
)
{
res
.
created
=
true
;
res
.
updated
=
false
;
}
else
{
res
.
created
=
false
;
// diff against ref commit to see if the card is updated
const
{
stdout
:
updatedStdout
}
=
await
execFileAsync
(
'
git
'
,
[
'
diff
'
,
'
--name-only
'
,
'
--diff-filter=M
'
,
refCommitHash
,
'
--
'
,
filename
,
],
{
cwd
:
gitPath
,
},
);
if
(
updatedStdout
?.
trim
()?.
length
)
{
res
.
updated
=
true
;
}
else
{
res
.
updated
=
false
;
}
}
}
return
res
;
}
async
function
formatCard
(
data
:
YGOProCardLike
):
Promise
<
YGOProCard
>
{
const
result
:
Partial
<
YGOProCard
>
=
{
...
data
,
displayLevel
:
data
.
level
&
0xff
,
...
...
@@ -247,6 +335,15 @@ function formatCard(data: YGOProCardLike): YGOProCard {
'
https://cdn02.moecube.com:444/images/ygopro-images-zh-CN/
'
)
+
data
.
id
.
toString
()
+
(
process
.
env
.
YGOPRO_PIC_URL_SUFFIX
||
'
.jpg
'
);
const
history
=
(
await
getCardHistory
(
data
))
||
{
createTime
:
0
,
createCommit
:
''
,
updateTime
:
0
,
updateCommit
:
''
,
};
Object
.
assign
(
result
,
history
);
if
(
process
.
env
.
FIELDS
)
{
const
fields
=
new
Set
(
process
.
env
.
FIELDS
.
split
(
'
,
'
));
// keep only the fields specified
...
...
@@ -269,7 +366,7 @@ async function main() {
db
,
'
select datas.*,texts.name,texts.desc from datas,texts where datas.id = texts.id and datas.type & 0x4000 = 0 and (datas.alias = 0 or datas.id - datas.alias > 10 or datas.id - datas.alias < -10)
'
,
);
const
formattedCards
=
cards
.
map
(
formatCard
);
const
formattedCards
=
await
Promise
.
all
(
cards
.
map
(
formatCard
)
);
console
.
log
(
JSON
.
stringify
(
formattedCards
,
null
,
2
));
process
.
exit
(
0
);
}
...
...
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