mirror of https://github.com/zer0bin-dev/zer0bin
✨ feature: Single view pastes work on the backend
This commit is contained in:
parent
c179f8bf90
commit
871dcc5c38
|
@ -34,7 +34,7 @@ pub async fn get_paste(state: web::Data<AppState>, id: web::Path<String>) -> imp
|
|||
Ok(p) => {
|
||||
// Only increment views if its not a single view paste
|
||||
if p.single_view {
|
||||
let _ = sqlx::query(r#"DELETE FORM pastes WHERE "id" = $1"#)
|
||||
let _ = sqlx::query(r#"DELETE FROM pastes WHERE "id" = $1"#)
|
||||
.bind(id.clone())
|
||||
.execute(&state.pool)
|
||||
.await;
|
||||
|
@ -46,7 +46,7 @@ pub async fn get_paste(state: web::Data<AppState>, id: web::Path<String>) -> imp
|
|||
}
|
||||
|
||||
if state.config.logging.on_get_paste {
|
||||
println!("[GET] id={} views={}", id, p.views + 1);
|
||||
println!("[GET] id={} views={} single_view={}", id, p.views + 1, p.single_view);
|
||||
}
|
||||
|
||||
HttpResponse::Ok().json(ApiResponse {
|
||||
|
@ -96,7 +96,7 @@ pub async fn get_raw_paste(state: web::Data<AppState>, id: web::Path<String>) ->
|
|||
match res {
|
||||
Ok(p) => {
|
||||
if p.single_view {
|
||||
let _ = sqlx::query(r#"DELETE FORM pastes WHERE "id" = $1"#)
|
||||
let _ = sqlx::query(r#"DELETE FROM pastes WHERE "id" = $1"#)
|
||||
.bind(id.clone())
|
||||
.execute(&state.pool)
|
||||
.await;
|
||||
|
@ -107,6 +107,10 @@ pub async fn get_raw_paste(state: web::Data<AppState>, id: web::Path<String>) ->
|
|||
.await;
|
||||
}
|
||||
|
||||
if state.config.logging.on_get_paste {
|
||||
println!("[GET] raw id={} views={} single_view={}", id, p.views + 1, p.single_view);
|
||||
}
|
||||
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/plain")
|
||||
.body(p.content)
|
||||
|
@ -174,7 +178,7 @@ pub async fn new_paste(
|
|||
match res {
|
||||
Ok(_) => {
|
||||
if state.config.logging.on_post_paste {
|
||||
println!("[POST] id={} length={}", id, content.len());
|
||||
println!("[POST] id={} length={} single_view={}", id, content.len(), single_view);
|
||||
}
|
||||
HttpResponse::Ok().json(ApiResponse {
|
||||
success: true,
|
||||
|
|
|
@ -51,7 +51,8 @@ function enable(element: HTMLButtonElement) {
|
|||
}
|
||||
|
||||
async function postPaste(content: string, callback: Function) {
|
||||
const payload = { content }
|
||||
let single_view = true;
|
||||
const payload = { content, single_view }
|
||||
await fetch(`${apiUrl}/p/n`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
Loading…
Reference in New Issue