Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
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
2
Merge Requests
2
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
Neos
Commits
b0857ffd
Commit
b0857ffd
authored
Oct 09, 2024
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add env 408 cdb
parent
4d3a42d2
Pipeline
#30286
failed with stages
in 9 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
114 deletions
+99
-114
neos.config.json
neos.config.json
+4
-0
neos.config.prod.json
neos.config.prod.json
+4
-0
src/container/impl.ts
src/container/impl.ts
+4
-1
src/middleware/sqlite/index.ts
src/middleware/sqlite/index.ts
+87
-113
No files found.
neos.config.json
View file @
b0857ffd
...
@@ -39,6 +39,10 @@
...
@@ -39,6 +39,10 @@
"lflist"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/lflist.conf"
,
"lflist"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/lflist.conf"
,
"config"
:
"https://cdn02.moecube.com:444/ygopro-super-pre/data/test-release-v2.json"
"config"
:
"https://cdn02.moecube.com:444/ygopro-super-pre/data/test-release-v2.json"
},
},
"env408Resource"
:
{
"cdb"
:
"https://cdn02.moecube.com:444/cn-database/env408-zh-CN/expansions/env408.cdb"
,
"lflist"
:
"https://cdn02.moecube.com:444/cn-database/env408-zh-CN/expansions/lflist.conf"
},
"stringsUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf"
,
"stringsUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf"
,
"replayUrl"
:
"replay.neos.moe"
,
"replayUrl"
:
"replay.neos.moe"
,
"loginUrl"
:
"https://accounts.moecube.com/signin"
,
"loginUrl"
:
"https://accounts.moecube.com/signin"
,
...
...
neos.config.prod.json
View file @
b0857ffd
...
@@ -39,6 +39,10 @@
...
@@ -39,6 +39,10 @@
"lflist"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/lflist.conf"
,
"lflist"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/lflist.conf"
,
"config"
:
"https://cdn02.moecube.com:444/ygopro-super-pre/data/test-release-v2.json"
"config"
:
"https://cdn02.moecube.com:444/ygopro-super-pre/data/test-release-v2.json"
},
},
"env408Resource"
:
{
"cdb"
:
"https://cdn02.moecube.com:444/cn-database/env408-zh-CN/expansions/env408.cdb"
,
"lflist"
:
"https://cdn02.moecube.com:444/cn-database/env408-zh-CN/expansions/lflist.conf"
},
"stringsUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf"
,
"stringsUrl"
:
"https://cdn02.moecube.com:444/ygopro-database/zh-CN/strings.conf"
,
"replayUrl"
:
"replay.neos.moe"
,
"replayUrl"
:
"replay.neos.moe"
,
"loginUrl"
:
"https://accounts.moecube.com/signin"
,
"loginUrl"
:
"https://accounts.moecube.com/signin"
,
...
...
src/container/impl.ts
View file @
b0857ffd
import
{
WebSocketStream
}
from
"
@/infra
"
;
import
{
WebSocketStream
}
from
"
@/infra
"
;
import
{
Context
}
from
"
./context
"
;
import
{
Context
}
from
"
./context
"
;
import
{
YgoCdb
}
from
"
@/middleware/sqlite
"
;
export
class
Container
{
export
class
Container
{
public
context
:
Context
;
public
context
:
Context
;
public
conn
:
WebSocketStream
;
public
conn
:
WebSocketStream
;
public
cdb
:
YgoCdb
;
// ref: https://yugioh.fandom.com/wiki/Kuriboh
// ref: https://yugioh.fandom.com/wiki/Kuriboh
private
enableKuriboh
:
boolean
=
false
;
private
enableKuriboh
:
boolean
=
false
;
constructor
(
context
:
Context
,
conn
:
WebSocketStream
)
{
constructor
(
context
:
Context
,
conn
:
WebSocketStream
,
cdb
:
YgoCdb
)
{
this
.
context
=
context
;
this
.
context
=
context
;
this
.
conn
=
conn
;
this
.
conn
=
conn
;
this
.
cdb
=
cdb
;
}
}
public
setEnableKuriboh
(
value
:
boolean
)
{
public
setEnableKuriboh
(
value
:
boolean
)
{
...
...
src/middleware/sqlite/index.ts
View file @
b0857ffd
...
@@ -39,6 +39,13 @@ export interface sqliteAction<T extends sqliteCmd> {
...
@@ -39,6 +39,13 @@ export interface sqliteAction<T extends sqliteCmd> {
};
};
}
}
interface
CdbInitInfo
{
main
:
string
;
sub
?:
string
;
i18n
:
boolean
;
progressCallback
?:
(
progress
:
number
)
=>
void
;
// 用于获取读取进度
}
export
interface
sqliteResult
{
export
interface
sqliteResult
{
selectResult
?:
CardMeta
;
selectResult
?:
CardMeta
;
ftsResult
?:
CardMeta
[];
ftsResult
?:
CardMeta
[];
...
@@ -48,84 +55,48 @@ const sqlPromise = initSqlJs({
...
@@ -48,84 +55,48 @@ const sqlPromise = initSqlJs({
locateFile
:
(
file
)
=>
`
${
NeosConfig
.
assetsPath
}
/
${
file
}
`
,
locateFile
:
(
file
)
=>
`
${
NeosConfig
.
assetsPath
}
/
${
file
}
`
,
});
});
export
default
function
<
T
extends
sqliteCmd
>
(
export
class
YgoCdb
{
action
:
sqliteAction
<
T
>
,
private
main
?:
Database
;
):
T
extends
sqliteCmd
.
INIT
?
Promise
<
void
>
:
sqliteResult
{
private
sub
?:
Database
;
return
helper
(
action
)
as
any
;
}
// TODO: may defining a class be better?
constructor
()
{}
interface
YgoDbs
{
release
:
Database
|
null
;
preRelease
:
Database
|
null
;
}
let
YGODBS
:
YgoDbs
=
{
release
:
null
,
preRelease
:
null
};
public
async
init
(
info
:
CdbInitInfo
):
Promise
<
void
>
{
if
(
info
.
i18n
)
{
const
language
=
localStorage
.
getItem
(
"
language
"
)
??
"
cn
"
;
// Update URLs based on the language
updateDbUrls
(
info
,
language
);
}
//It currently only supports en-US, es-ES, ja-JP, ko-KR, zh-CN
const
promises
=
[
pfetch
(
info
.
main
,
{
// Function to update URLs based on the language
progressCallback
:
info
.
progressCallback
,
function
updateDbUrls
(
info
:
any
,
language
:
string
):
void
{
}).
then
((
res
)
=>
res
.
arrayBuffer
())];
const
languageMap
:
{
[
key
:
string
]:
string
}
=
{
en
:
"
en-US
"
,
br
:
"
en-US
"
,
pt
:
"
en-US
"
,
fr
:
"
en-US
"
,
ja
:
"
ja-JP
"
,
ko
:
"
ko-KR
"
,
es
:
"
es-ES
"
,
};
const
locale
=
languageMap
[
language
]
||
"
zh-CN
"
;
if
(
info
.
sub
!==
undefined
)
{
info
.
releaseDbUrl
=
info
.
releaseDbUrl
.
replace
(
"
zh-CN
"
,
locale
);
promises
.
push
(
pfetch
(
info
.
sub
,
{
info
.
preReleaseDbUrl
=
info
.
preReleaseDbUrl
.
replace
(
"
zh-CN
"
,
locale
);
progressCallback
:
info
.
progressCallback
,
}
}).
then
((
res
)
=>
res
.
arrayBuffer
()));
}
// FIXME: 应该有个返回值,告诉业务方本次请求的结果,比如初始化DB失败
const
sql
=
await
sqlPromise
;
function
helper
<
T
extends
sqliteCmd
>
(
action
:
sqliteAction
<
T
>
)
{
switch
(
action
.
cmd
)
{
case
sqliteCmd
.
INIT
:
{
const
info
=
action
.
initInfo
;
if
(
info
)
{
const
language
=
localStorage
.
getItem
(
"
language
"
)
||
"
cn
"
;
// Update URLs based on the language
updateDbUrls
(
info
,
language
);
const
releasePromise
=
pfetch
(
info
.
releaseDbUrl
,
{
return
Promise
.
all
(
promises
).
then
(([
mainBuffer
,
subBuffer
])
=>
{
progressCallback
:
action
.
initInfo
?.
progressCallback
,
this
.
main
=
new
sql
.
Database
(
new
Uint8Array
(
mainBuffer
));
}).
then
((
res
)
=>
res
.
arrayBuffer
());
// TODO: i18n
this
.
sub
=
new
sql
.
Database
(
const
preReleasePromise
=
pfetch
(
info
.
preReleaseDbUrl
,
{
new
Uint8Array
(
subBuffer
),
progressCallback
:
action
.
initInfo
?.
progressCallback
,
}).
then
((
res
)
=>
res
.
arrayBuffer
());
return
Promise
.
all
([
sqlPromise
,
releasePromise
,
preReleasePromise
,
]).
then
(([
SQL
,
releaseBuffer
,
preReleaseBuffer
])
=>
{
YGODBS
.
release
=
new
SQL
.
Database
(
new
Uint8Array
(
releaseBuffer
));
YGODBS
.
preRelease
=
new
SQL
.
Database
(
new
Uint8Array
(
preReleaseBuffer
),
);
);
console
.
log
(
"
YGODB inited!
"
);
console
.
log
(
"
YGODB inited!
"
);
});
});
}
else
{
console
.
warn
(
"
init YGODB action without initInfo
"
);
return
{};
}
}
}
case
sqliteCmd
.
SELECT
:
{
public
select
(
code
:
number
):
sqliteResult
{
if
(
if
(
YGODBS
.
release
&&
this
.
main
YGODBS
.
preRelease
&&
action
.
payload
&&
action
.
payload
.
id
)
{
)
{
const
code
=
action
.
payload
.
id
;
const
db
=
isSuperReleaseCard
(
code
)
const
db
=
isSuperReleaseCard
(
code
)
?
YGODBS
.
preReleas
e
?
this
.
sub
!
// must be initialized when `isSuperReleaseCard` return tru
e
:
YGODBS
.
release
;
:
this
.
main
;
const
dataStmt
=
db
.
prepare
(
"
SELECT * FROM datas WHERE ID = $id
"
);
const
dataStmt
=
db
.
prepare
(
"
SELECT * FROM datas WHERE ID = $id
"
);
const
dataResult
=
dataStmt
.
getAsObject
({
$id
:
code
});
const
dataResult
=
dataStmt
.
getAsObject
({
$id
:
code
});
...
@@ -136,47 +107,50 @@ function helper<T extends sqliteCmd>(action: sqliteAction<T>) {
...
@@ -136,47 +107,50 @@ function helper<T extends sqliteCmd>(action: sqliteAction<T>) {
selectResult
:
constructCardMeta
(
code
,
dataResult
,
textResult
),
selectResult
:
constructCardMeta
(
code
,
dataResult
,
textResult
),
};
};
}
else
{
}
else
{
if
(
action
.
payload
?.
id
!==
0
)
{
console
.
warn
(
"
ygo cdb not init!
"
);
// 0是无效的卡片ID,不需要报错,返回空即可
return
{};
console
.
warn
(
"
ygo db not init or id not provied!
"
);
}
}
}
}
return
{};
public
fts
(
params
:
FtsParams
):
sqliteResult
{
}
case
sqliteCmd
.
FTS
:
{
if
(
if
(
YGODBS
.
release
&&
this
.
main
YGODBS
.
preRelease
&&
action
.
payload
&&
action
.
payload
.
ftsParams
)
{
)
{
const
releaseMetas
=
invokeFts
(
let
metas
=
invokeFts
(
YGODBS
.
release
,
this
.
main
,
action
.
payload
.
ftsParams
,
params
,
);
const
preReleaseMetas
=
invokeFts
(
YGODBS
.
preRelease
,
action
.
payload
.
ftsParams
,
);
);
const
metas
=
releaseMetas
.
concat
(
preReleaseMetas
);
if
(
this
.
sub
!==
undefined
)
{
metas
=
metas
.
concat
(
invokeFts
(
this
.
sub
,
params
));
}
return
{
ftsResult
:
metas
};
return
{
ftsResult
:
metas
};
}
else
{
}
else
{
console
.
warn
(
"
ygo db not init or query not provied!
"
);
console
.
warn
(
"
ygo db not init!
"
);
}
return
{};
}
default
:
{
console
.
warn
(
`Unhandled sqlite command:
${
action
.
cmd
}
`
);
return
{};
return
{};
}
}
}
}
}
}
// Function to update URLs based on the language
//
// Note: it currently only supports en-US, es-ES, ja-JP, ko-KR, zh-CN for main cdb
function
updateDbUrls
(
info
:
CdbInitInfo
,
language
:
string
):
void
{
const
languageMap
:
{
[
key
:
string
]:
string
}
=
{
en
:
"
en-US
"
,
br
:
"
en-US
"
,
pt
:
"
en-US
"
,
fr
:
"
en-US
"
,
ja
:
"
ja-JP
"
,
ko
:
"
ko-KR
"
,
es
:
"
es-ES
"
,
};
const
locale
=
languageMap
[
language
]
??
"
zh-CN
"
;
info
.
main
=
info
.
main
.
replace
(
"
zh-CN
"
,
locale
);
}
export
function
constructCardMeta
(
export
function
constructCardMeta
(
id
:
number
,
id
:
number
,
data
:
CardData
,
data
:
CardData
,
...
...
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