mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Update
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
use super::cors::CorsContext;
|
||||
use crate::db::{open_database, PixivDownloaderDb};
|
||||
use crate::db::{open_and_init_database, PixivDownloaderDb};
|
||||
use crate::gettext;
|
||||
use std::default::Default;
|
||||
|
||||
pub struct ServerContext {
|
||||
pub cors: CorsContext,
|
||||
pub db: Box<dyn PixivDownloaderDb + Send + Sync>,
|
||||
}
|
||||
|
||||
impl Default for ServerContext {
|
||||
fn default() -> Self {
|
||||
impl ServerContext {
|
||||
pub async fn default() -> Self {
|
||||
Self {
|
||||
cors: CorsContext::default(),
|
||||
db: match open_database() {
|
||||
db: match open_and_init_database().await {
|
||||
Ok(db) => db,
|
||||
Err(e) => panic!("{} {}", gettext("Failed to open database:"), e),
|
||||
},
|
||||
|
||||
@@ -64,9 +64,9 @@ pub struct PixivDownloaderMakeSvc {
|
||||
}
|
||||
|
||||
impl PixivDownloaderMakeSvc {
|
||||
pub fn new() -> Self {
|
||||
pub async fn new() -> Self {
|
||||
Self {
|
||||
context: Arc::new(ServerContext::default()),
|
||||
context: Arc::new(ServerContext::default().await),
|
||||
routes: Arc::new(ServerRoutes::new()),
|
||||
}
|
||||
}
|
||||
@@ -90,8 +90,8 @@ impl<T> Service<T> for PixivDownloaderMakeSvc {
|
||||
}
|
||||
|
||||
/// Start the server
|
||||
pub fn start_server(
|
||||
pub async fn start_server(
|
||||
addr: &SocketAddr,
|
||||
) -> Result<Server<AddrIncoming, PixivDownloaderMakeSvc>, hyper::Error> {
|
||||
Ok(Server::try_bind(addr)?.serve(PixivDownloaderMakeSvc::new()))
|
||||
Ok(Server::try_bind(addr)?.serve(PixivDownloaderMakeSvc::new().await))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user