WIP
This commit is contained in:
17 files changed
+672
-48
No files matched your search
@@ -0,0 +1,24 @@
|
||||
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))
|
||||
}
|
||||
Reference in new issue
Block a user