feature: Single view pastes work on the backend

This commit is contained in:
Dominic Harris 2022-03-26 08:37:07 -04:00
parent c179f8bf90
commit 871dcc5c38
No known key found for this signature in database
GPG Key ID: 93CCF85F3E2A4F65
2 changed files with 10 additions and 5 deletions

View File

@ -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,

View File

@ -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: {