Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos-rs
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
deft
Neos-rs
Commits
a0b01b0c
Commit
a0b01b0c
authored
Dec 22, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add strings service
parent
9986628a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
2 deletions
+27
-2
src/main.rs
src/main.rs
+8
-2
src/service/mod.rs
src/service/mod.rs
+2
-0
src/service/strings.rs
src/service/strings.rs
+17
-0
No files found.
src/main.rs
View file @
a0b01b0c
use
std
::{
net
::
SocketAddr
,
str
::
FromStr
};
use
std
::{
collections
::
HashMap
,
net
::
SocketAddr
,
str
::
FromStr
};
use
warp
::
Filter
;
use
warp
::
Filter
;
mod
infra
;
mod
infra
;
...
@@ -11,6 +11,8 @@ const SERVE_ADDR: &str = "127.0.0.1:3030";
...
@@ -11,6 +11,8 @@ const SERVE_ADDR: &str = "127.0.0.1:3030";
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
pretty_env_logger
::
try_init
()
?
;
pretty_env_logger
::
try_init
()
?
;
let
strings_manager
=
HashMap
::
new
();
// TODO: use CORS correctly
// TODO: use CORS correctly
let
cors
=
warp
::
cors
()
let
cors
=
warp
::
cors
()
.allow_any_origin
()
.allow_any_origin
()
...
@@ -27,12 +29,16 @@ async fn main() -> anyhow::Result<()> {
...
@@ -27,12 +29,16 @@ async fn main() -> anyhow::Result<()> {
.map
(
service
::
cards_service
)
.map
(
service
::
cards_service
)
.with
(
cors
.clone
());
.with
(
cors
.clone
());
let
strings
=
warp
::
path!
(
"strings"
/
String
)
.map
(
service
::
strings_service
(
strings_manager
))
.with
(
cors
.clone
());
// TODO: 模块化
// TODO: 模块化
let
images
=
warp
::
path
(
"images"
)
let
images
=
warp
::
path
(
"images"
)
.and
(
warp
::
fs
::
dir
(
"./images/"
))
.and
(
warp
::
fs
::
dir
(
"./images/"
))
.with
(
cors
);
.with
(
cors
);
warp
::
serve
(
deck
.or
(
cards
)
.or
(
images
))
warp
::
serve
(
deck
.or
(
cards
)
.or
(
images
)
.or
(
strings
)
)
.run
(
SocketAddr
::
from_str
(
SERVE_ADDR
)
?
)
.run
(
SocketAddr
::
from_str
(
SERVE_ADDR
)
?
)
.await
;
.await
;
...
...
src/service/mod.rs
View file @
a0b01b0c
mod
cards
;
mod
cards
;
mod
deck
;
mod
deck
;
mod
strings
;
pub
use
cards
::
service
as
cards_service
;
pub
use
cards
::
service
as
cards_service
;
pub
use
deck
::
service
as
deck_service
;
pub
use
deck
::
service
as
deck_service
;
pub
use
strings
::
service_maker
as
strings_service
;
src/service/strings.rs
0 → 100644
View file @
a0b01b0c
use
std
::
collections
::
HashMap
;
// TODO: `strings_manager`应该做好持久化存储
pub
fn
service_maker
(
strings_manager
:
HashMap
<
String
,
HashMap
<
i64
,
String
>>
,
)
->
impl
Fn
(
String
)
->
String
+
Clone
{
move
|
param
|
{
// TODO:应该做好错误处理
let
(
r
#
type
,
code
)
=
param
.split_once
(
'_'
)
.unwrap_or_default
();
let
code
=
code
.parse
::
<
i64
>
()
.unwrap_or_default
();
strings_manager
.get
(
r
#
type
)
.map_or
(
Some
(
""
.to_string
()),
|
hash
|
hash
.get
(
&
code
)
.cloned
())
.unwrap_or_default
()
}
}
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