Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc authored Oct 24, 2023
1 parent 370c042 commit d8c0cac
Show file tree
Hide file tree
Showing 16 changed files with 675 additions and 25 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ base64 = { version = "0.21", optional = true }
bytes = { version = "1.4", optional = true }
c_fixed_string = { version = "0.2", optional = true }
cfg-if = "1"
chrono = "0.4"
chrono = { version = "0.4", features = ["serde"] }
dateparser = "0.2.0"
derive_more = "0.99"
fancy-regex = "0.11"
Expand Down Expand Up @@ -42,6 +42,7 @@ reqwest = { version = "0.11", features = ["brotli", "deflate", "gzip", "socks",
rusqlite = { version = "0.29", features = ["bundled", "chrono"], optional = true }
RustyXML = "0.3"
serde = "1"
serde_json = { version = "1", optional = true }
tokio = { version = "1.27", features = ["rt", "macros", "rt-multi-thread", "time"] }
url = "2.3"
urlparse = "0.7"
Expand All @@ -59,7 +60,7 @@ db_all = ["db", "db_sqlite"]
db_sqlite = ["rusqlite"]
docker = []
exif = ["bindgen", "c_fixed_string", "cmake", "link-cplusplus", "utf16string"]
server = ["async-trait", "base64", "db", "hex", "hyper", "multipart", "openssl"]
server = ["async-trait", "base64", "db", "hex", "hyper", "multipart", "openssl", "serde_json"]
ugoira = ["avdict", "bindgen", "cmake", "link-cplusplus"]

[patch.crates-io]
Expand Down
42 changes: 35 additions & 7 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod config;
pub mod pixiv_artworks;
#[cfg(feature = "server")]
pub mod push_task;
#[cfg(feature = "db_sqlite")]
pub mod sqlite;
#[cfg(feature = "server")]
Expand All @@ -13,6 +15,8 @@ pub use config::PixivDownloaderDbConfig;
#[cfg(feature = "db_sqlite")]
pub use config::PixivDownloaderSqliteConfig;
pub use pixiv_artworks::{PixivArtwork, PixivArtworkLock};
#[cfg(feature = "server")]
pub use push_task::{PushConfig, PushTask, PushTaskConfig};
#[cfg(feature = "db_sqlite")]
pub use sqlite::{PixivDownloaderSqlite, SqliteError};
#[cfg(feature = "server")]
Expand All @@ -22,15 +26,15 @@ pub use traits::PixivDownloaderDb;
pub use user::User;

#[derive(Debug, derive_more::Display)]
pub struct PixivDownloaderDbError {
e: anyhow::Error,
pub enum PixivDownloaderDbError {
AnyHow(anyhow::Error),
#[cfg(feature = "db_sqlite")]
Sqlite(SqliteError),
}

impl PixivDownloaderDbError {
pub fn msg<S: std::fmt::Display + std::fmt::Debug + Send + Sync + 'static>(msg: S) -> Self {
Self {
e: anyhow::Error::msg(msg),
}
Self::AnyHow(anyhow::Error::msg(msg))
}
}

Expand All @@ -39,7 +43,7 @@ where
T: Into<anyhow::Error>,
{
fn from(e: T) -> Self {
Self { e: e.into() }
Self::AnyHow(e.into())
}
}

Expand All @@ -48,7 +52,31 @@ use crate::gettext;
#[cfg(feature = "db_sqlite")]
impl From<SqliteError> for PixivDownloaderDbError {
fn from(e: SqliteError) -> Self {
PixivDownloaderDbError::msg(e)
PixivDownloaderDbError::Sqlite(e)
}
}

#[cfg(all(feature = "db_sqlite", feature = "server"))]
pub trait Optional2Extension<T> {
fn optional2(self) -> Result<Option<T>, PixivDownloaderDbError>;
}

#[cfg(all(feature = "db_sqlite", feature = "server"))]
impl<T> Optional2Extension<T> for Result<T, PixivDownloaderDbError> {
fn optional2(self) -> Result<Option<T>, PixivDownloaderDbError> {
match self {
Ok(v) => Ok(Some(v)),
Err(e) => match e {
PixivDownloaderDbError::Sqlite(e) => match e {
SqliteError::DbError(e) => match e {
rusqlite::Error::QueryReturnedNoRows => Ok(None),
_ => Err(PixivDownloaderDbError::Sqlite(SqliteError::DbError(e))),
},
_ => Err(PixivDownloaderDbError::Sqlite(e)),
},
_ => Err(e),
},
}
}
}

Expand Down
76 changes: 76 additions & 0 deletions src/db/push_task.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use crate::push::every_push::EveryPushTextType;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum PushTaskPixivRestrictType {
Public,
Private,
All,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum PushTaskPixivAction {
Follow {
restrict: PushTaskPixivRestrictType,
},
Bookmarks {
restrict: PushTaskPixivRestrictType,
uid: u64,
},
Illusts {
uid: u64,
},
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PushTaskPixivConfig {
pub act: PushTaskPixivAction,
/// Tag translation language
pub lang: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum PushTaskConfig {
Pixiv(PushTaskPixivConfig),
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EveryPushConfig {
/// Push server
pub push_server: String,
/// Push token
pub push_token: String,
#[serde(rename = "type")]
/// Push type
pub typ: EveryPushTextType,
/// Push topic ID
pub topic_id: Option<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum PushConfig {
EveryPush(EveryPushConfig),
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PushTask {
/// The task ID
pub id: u64,
/// Configurations of the task
pub config: PushTaskConfig,
/// Push configurations
pub push_configs: Vec<PushConfig>,
#[serde(with = "chrono::serde::ts_seconds")]
/// Last updated time
pub last_updated: DateTime<Utc>,
/// Update interval
pub ttl: u64,
}
Loading

0 comments on commit d8c0cac

Please sign in to comment.