-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
173 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod auth_routes; | ||
pub mod link_routes; | ||
pub mod qrcode_routes; | ||
pub mod user_routes; | ||
pub mod web_routes; | ||
pub mod link_routes; | ||
pub mod auth_routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use axum::{http::StatusCode, routing::post, Form, Router}; | ||
use qrcode::render::svg; | ||
use qrcode::QrCode; | ||
use serde::Deserialize; | ||
#[derive(sqlx::FromRow, Debug, Deserialize)] // Add this line | ||
struct QRCodeRequest { | ||
original_url: String, | ||
} | ||
#[derive(sqlx::FromRow, Debug, Deserialize)] // Add this line | ||
struct QRCodeResponse { | ||
_short_url: String, | ||
} | ||
pub fn get_routes() -> Router { | ||
Router::new().route("/", post(add_qrcode)) | ||
} | ||
|
||
async fn add_qrcode( | ||
// ctx: Extension<ApiContext>, | ||
Form(payload): Form<QRCodeRequest>, | ||
) -> Result<String, StatusCode> { | ||
Ok(generate_qr_from_qrcode(&payload.original_url)) | ||
} | ||
fn generate_qr_from_qrcode(url: &str) -> String { | ||
if let Ok(qr) = QrCode::with_error_correction_level(&url, qrcode::EcLevel::L) { | ||
let svg = qr | ||
.render() | ||
.min_dimensions(100, 100) | ||
.dark_color(svg::Color("#000000")) | ||
.light_color(svg::Color("#ffffff")) | ||
.build(); | ||
|
||
svg | ||
} else { | ||
// should never (only on very huge codes) happen. | ||
"".to_string() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters