Skip to content

Commit

Permalink
feat: update to a models-only public crate
Browse files Browse the repository at this point in the history
  • Loading branch information
EnokiUN committed Oct 7, 2023
1 parent 3066be4 commit f80a1c2
Show file tree
Hide file tree
Showing 30 changed files with 1,262 additions and 1,538 deletions.
34 changes: 1 addition & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { version = "1.0.66", optional = true }
ffprobe = { version = "0.3.3", optional = true }
image = { version = "0.24.5", optional = true }
imagesize = { version = "0.10.1", optional = true }
lazy_static = { version = "1.4.0", optional = true }
log = { version = "0.4.17", optional = true }
rocket = { version = "0.5.0-rc.2", optional = true, features = ["json"] }
serde = { version = "1.0.144", features = ["derive"] }
serde_with = "2.1.0"
sha256 = { version = "1.1.1", optional = true }
sqlx = { version = "^0.5.0", features = ["runtime-tokio-rustls", "macros", "mysql", "offline"], optional = true }
tokio = { version = "1.22.0", optional = true }
toml = { version = "0.5.9", optional = true }
tree_magic = { version = "0.2.3", optional = true }
serde_with = "3.0.0"
ubyte = { version = "0.10.3", features = ["serde"] }
url = "2.2.2"

[features]
logic = [
"dep:toml",
"dep:lazy_static",
"dep:anyhow",
"dep:sqlx",
"dep:log",
"dep:tokio",
]
http = [
"logic",
"dep:rocket",
"dep:tree_magic",
"dep:sha256",
"dep:imagesize",
"dep:ffprobe",
"dep:image",
]
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Todel

The Eludris models & shared logic crate.
The Eludris models crate.

## Usage

Expand All @@ -18,13 +18,3 @@ projects with mind, add it to your own project either by:
```toml
todel = { git = "https://github.com/eludris.todel" }
```

## Features

Todel comes with 2 main features, `logic` which provides the logic-related implementation
to the models and also some types which are not used directly by the Eludris API
and `http` which houses the rocket-reliant logic and models.

If you just need the models (which will be the case most of the time) then you
can add todel with no extra features, all the models derive the `Debug`, `serde::Serialize`
and `serde::Deserialize` traits.
11 changes: 0 additions & 11 deletions migrations/20221128214127_files.sql

This file was deleted.

206 changes: 0 additions & 206 deletions sqlx-data.json

This file was deleted.

80 changes: 80 additions & 0 deletions src/conf/effis.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use serde::{Deserialize, Deserializer, Serialize};
use ubyte::ByteUnit;

use super::RateLimitConf;

/// Effis configuration.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EffisConf {
pub url: String,
#[serde(deserialize_with = "deserialize_file_size")]
pub file_size: u64,
#[serde(deserialize_with = "deserialize_file_size")]
pub attachment_file_size: u64,
pub rate_limits: EffisRateLimits,
}

/// Rate limits that apply to Effis (The CDN).
///
/// -----
///
/// ### Example
///
/// ```json
/// {
/// "assets": {
/// "reset_after": 60,
/// "limit": 5,
/// "file_size_limit": 30000000
/// },
/// "attachments": {
/// "reset_after": 180,
/// "limit": 20,
/// "file_size_limit": 500000000
/// },
/// "fetch_file": {
/// "reset_after": 60,
/// "limit": 30
/// }
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EffisRateLimits {
/// Rate limits for the asset buckets.
pub assets: EffisRateLimitConf,
/// Rate limits for the attachment bucket.
pub attachments: EffisRateLimitConf,
/// Rate limits for the file fetching endpoints.
pub fetch_file: RateLimitConf,
}

/// Represents a single rate limit for Effis.
///
/// -----
///
/// ### Example
///
/// ```json
/// {
/// "reset_after": 60,
/// "limit": 5,
/// "file_size_limit": 30000000
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct EffisRateLimitConf {
/// The amount of seconds after which the rate limit resets.
pub reset_after: u32,
/// The amount of requests that can be made within the `reset_after` interval.
pub limit: u32,
/// The maximum amount of bytes that can be sent within the `reset_after` interval.
#[serde(deserialize_with = "deserialize_file_size")]
pub file_size_limit: u64,
}

pub(crate) fn deserialize_file_size<'de, D>(deserializer: D) -> Result<u64, D::Error>
where
D: Deserializer<'de>,
{
Ok(ByteUnit::deserialize(deserializer)?.as_u64())
}
Loading

0 comments on commit f80a1c2

Please sign in to comment.