25 lines
628 B
Rust
25 lines
628 B
Rust
use axum::{
|
|
extract::{Path, State},
|
|
http::StatusCode,
|
|
response::Redirect,
|
|
};
|
|
use sqlx::SqlitePool;
|
|
|
|
use crate::paste::PasteType;
|
|
|
|
pub async fn get_redirect(
|
|
State(db): State<SqlitePool>,
|
|
Path(id): Path<String>,
|
|
) -> Result<Redirect, StatusCode> {
|
|
let url =
|
|
sqlx::query_scalar::<_, String>("SELECT content FROM notes WHERE type = ? AND id = ?")
|
|
.bind(PasteType::UrlV1)
|
|
.bind(id)
|
|
.fetch_optional(&db)
|
|
.await
|
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
|
.ok_or(StatusCode::NOT_FOUND)?;
|
|
|
|
Ok(Redirect::temporary(&url))
|
|
}
|