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
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
nanahira
srvpro
Commits
56f15b58
Commit
56f15b58
authored
Nov 15, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'database' into databasen
parents
7138f267
a7efecc1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
11 deletions
+87
-11
data-manager/DataManager.js
data-manager/DataManager.js
+85
-9
ygopro-server.coffee
ygopro-server.coffee
+1
-1
ygopro-server.js
ygopro-server.js
+1
-1
No files found.
data-manager/DataManager.js
View file @
56f15b58
...
...
@@ -335,11 +335,11 @@ class DataManager {
user
.
chatColor
=
color
;
return
await
this
.
saveUser
(
user
);
}
async
getUserDialogue
s
(
key
,
cardCode
)
{
async
getUserDialogue
Text
(
key
,
cardCode
)
{
try
{
const
dialogue
=
await
this
.
db
.
getRepository
(
UserDialog_1
.
UserDialog
)
.
createQueryBuilder
(
"
dialog
"
)
.
where
(
"
dialog.cardCode = :cardCode and
"
,
{
cardCode
,
key
})
.
where
(
"
cardCode = :cardCode and userKey = :key
"
,
{
cardCode
,
key
})
.
getOne
();
if
(
dialogue
)
{
return
dialogue
.
text
;
...
...
@@ -361,14 +361,39 @@ class DataManager {
const
user
=
await
this
.
getUser
(
key
);
return
user
?
user
.
victory
:
null
;
}
async
setUser
Dialogues
(
key
,
cardCode
)
{
async
setUser
Words
(
key
,
word
)
{
const
user
=
await
this
.
getOrCreateUser
(
key
);
user
.
words
=
word
;
return
await
this
.
saveUser
(
user
);
}
async
setUserVictoryWords
(
key
,
word
)
{
const
user
=
await
this
.
getOrCreateUser
(
key
);
user
.
victory
=
word
;
return
await
this
.
saveUser
(
user
);
}
async
setUserDialogues
(
key
,
cardCode
,
text
)
{
const
user
=
await
this
.
getOrCreateUser
(
key
);
await
this
.
transaction
(
async
(
mdb
)
=>
{
try
{
let
dialogue
=
await
mdb
.
getRepository
(
UserDialog_1
.
UserDialog
)
.
createQueryBuilder
(
"
dialog
"
)
.
where
(
"
cardCode = :cardCode and userKey = :key
"
,
{
cardCode
,
key
})
.
innerJoinAndSelect
(
"
dialog.user
"
,
"
user
"
)
.
getOne
();
if
(
!
dialogue
)
{
dialogue
=
new
UserDialog_1
.
UserDialog
();
dialogue
.
user
=
user
;
dialogue
.
cardCode
=
cardCode
;
}
dialogue
.
text
=
text
;
await
mdb
.
save
(
dialogue
);
return
true
;
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to save dialogue:
${
e
.
toString
()}
`
);
return
user
;
return
false
;
}
});
}
async
migrateChatColors
(
data
)
{
await
this
.
transaction
(
async
(
mdb
)
=>
{
...
...
@@ -455,6 +480,57 @@ class DataManager {
});
return
result
;
}
async
migrateFromOldVipInfo
(
vipInfo
)
{
await
this
.
transaction
(
async
(
mdb
)
=>
{
try
{
const
vipKeyList
=
vipInfo
.
cdkeys
;
const
newKeys
=
[];
for
(
let
keyTypeString
in
vipKeyList
)
{
const
keyType
=
parseInt
(
keyTypeString
);
const
keysTexts
=
vipKeyList
[
keyTypeString
];
for
(
let
keyText
of
keysTexts
)
{
const
newKey
=
new
VipKey_1
.
VipKey
();
newKey
.
type
=
keyType
;
newKey
.
key
=
keyText
;
newKeys
.
push
(
newKey
);
}
}
await
mdb
.
save
(
newKeys
);
for
(
let
vipUserName
in
vipInfo
.
players
)
{
const
oldVipUserInfo
=
vipInfo
.
players
[
vipUserName
];
const
userKey
=
vipUserName
+
'
$
'
+
oldVipUserInfo
.
password
;
let
user
=
await
mdb
.
findOne
(
User_1
.
User
,
userKey
);
if
(
user
&&
user
.
isVip
())
{
continue
;
}
if
(
!
user
)
{
user
=
new
User_1
.
User
();
user
.
key
=
userKey
;
}
user
.
vipExpireDate
=
moment_1
.
default
(
oldVipUserInfo
.
expire_date
).
toDate
();
user
.
victory
=
oldVipUserInfo
.
victory
||
null
;
user
.
words
=
oldVipUserInfo
.
words
||
null
;
user
=
await
mdb
.
save
(
user
);
const
newDialogues
=
[];
for
(
let
dialogueCardCodeText
in
oldVipUserInfo
.
dialogues
)
{
const
cardCode
=
parseInt
(
dialogueCardCodeText
);
const
dialogueText
=
oldVipUserInfo
.
dialogues
[
dialogueCardCodeText
];
const
dialogue
=
new
UserDialog_1
.
UserDialog
();
dialogue
.
text
=
dialogueText
;
dialogue
.
cardCode
=
cardCode
;
dialogue
.
user
=
user
;
newDialogues
.
push
(
dialogue
);
}
await
mdb
.
save
(
newDialogues
);
}
return
true
;
}
catch
(
e
)
{
this
.
log
.
warn
(
`Failed to migrate vip info from previous one:
${
e
.
toString
()}
`
);
return
false
;
}
});
}
}
exports
.
DataManager
=
DataManager
;
//# sourceMappingURL=DataManager.js.map
\ No newline at end of file
ygopro-server.coffee
View file @
56f15b58
...
...
@@ -434,7 +434,7 @@ init = () ->
chat_color
=
await
loadJSONAsync
(
'./config/chat_color.json'
)
if
chat_color
await
dataManager
.
migrateChatColors
(
chat_color
.
save_list
);
await
fs
.
promises
.
unlink
(
'./config/chat_color.json
'
)
await
fs
.
promises
.
rename
(
'./config/chat_color.json'
,
'./config/chat_color.json.bak
'
)
log
.
info
(
"Chat color migrated."
)
catch
try
...
...
ygopro-server.js
View file @
56f15b58
...
...
@@ -577,7 +577,7 @@
chat_color
=
(
await
loadJSONAsync
(
'
./config/chat_color.json
'
));
if
(
chat_color
)
{
await
dataManager
.
migrateChatColors
(
chat_color
.
save_list
);
await
fs
.
promises
.
unlink
(
'
./config/chat_color.json
'
);
await
fs
.
promises
.
rename
(
'
./config/chat_color.json
'
,
'
./config/chat_color.json.bak
'
);
log
.
info
(
"
Chat color migrated.
"
);
}
}
catch
(
error1
)
{
...
...
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