Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/helloworlde/microbin into…
Browse files Browse the repository at this point in the history
… helloworlde-master
  • Loading branch information
zhaobenny committed Jan 17, 2024
2 parents 7973ca0 + 997586b commit d05858b
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/endpoints/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub async fn post_admin(
update = None;
}

Ok(HttpResponse::Ok().content_type("text/html").body(
Ok(HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AdminTemplate {
pastas: &pastas,
args: &ARGS,
Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/auth_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct AuthAdmin<'a> {

#[get("/auth_admin")]
pub async fn auth_admin() -> HttpResponse {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthAdmin {
args: &ARGS,
status: String::from(""),
Expand All @@ -25,7 +25,7 @@ pub async fn auth_admin() -> HttpResponse {
pub async fn auth_admin_with_status(param: web::Path<String>) -> HttpResponse {
let status = param.into_inner();

return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthAdmin {
args: &ARGS,
status,
Expand Down
40 changes: 20 additions & 20 deletions src/endpoints/auth_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub async fn auth_upload(data: web::Data<AppState>, id: web::Path<String>) -> Ht

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -49,7 +49,7 @@ pub async fn auth_upload(data: web::Data<AppState>, id: web::Path<String>) -> Ht
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -73,7 +73,7 @@ pub async fn auth_upload_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -89,7 +89,7 @@ pub async fn auth_upload_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -108,7 +108,7 @@ pub async fn auth_raw_pasta(data: web::Data<AppState>, id: web::Path<String>) ->

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -124,7 +124,7 @@ pub async fn auth_raw_pasta(data: web::Data<AppState>, id: web::Path<String>) ->
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -148,7 +148,7 @@ pub async fn auth_raw_pasta_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -164,7 +164,7 @@ pub async fn auth_raw_pasta_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -183,7 +183,7 @@ pub async fn auth_edit_private(data: web::Data<AppState>, id: web::Path<String>)

for (_, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -199,7 +199,7 @@ pub async fn auth_edit_private(data: web::Data<AppState>, id: web::Path<String>)
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -223,7 +223,7 @@ pub async fn auth_edit_private_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -239,7 +239,7 @@ pub async fn auth_edit_private_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -258,7 +258,7 @@ pub async fn auth_file(data: web::Data<AppState>, id: web::Path<String>) -> Http

for (_, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -274,7 +274,7 @@ pub async fn auth_file(data: web::Data<AppState>, id: web::Path<String>) -> Http
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -298,7 +298,7 @@ pub async fn auth_file_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -314,7 +314,7 @@ pub async fn auth_file_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -333,7 +333,7 @@ pub async fn auth_remove_private(data: web::Data<AppState>, id: web::Path<String

for (_, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id: id.into_inner(),
Expand All @@ -349,7 +349,7 @@ pub async fn auth_remove_private(data: web::Data<AppState>, id: web::Path<String
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand All @@ -373,7 +373,7 @@ pub async fn auth_remove_private_with_status(

for (_i, pasta) in pastas.iter().enumerate() {
if pasta.id == intern_id {
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
AuthPasta {
args: &ARGS,
id,
Expand All @@ -389,6 +389,6 @@ pub async fn auth_remove_private_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}
4 changes: 2 additions & 2 deletions src/endpoints/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct IndexTemplate<'a> {

#[get("/")]
pub async fn index() -> impl Responder {
HttpResponse::Ok().content_type("text/html").body(
HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
IndexTemplate {
args: &ARGS,
status: String::from(""),
Expand All @@ -38,7 +38,7 @@ pub async fn index() -> impl Responder {
pub async fn index_with_status(param: web::Path<String>) -> HttpResponse {
let status = param.into_inner();

return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
IndexTemplate {
args: &ARGS,
status,
Expand Down
16 changes: 8 additions & 8 deletions src/endpoints/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
.finish();
}

return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
EditTemplate {
pasta,
args: &ARGS,
Expand All @@ -63,7 +63,7 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand Down Expand Up @@ -101,7 +101,7 @@ pub async fn get_edit_with_status(
.finish();
}

return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
EditTemplate {
pasta,
args: &ARGS,
Expand All @@ -115,7 +115,7 @@ pub async fn get_edit_with_status(
}

HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}

Expand Down Expand Up @@ -188,7 +188,7 @@ pub async fn post_edit_private(
}

// serve pasta in template
let response = HttpResponse::Ok().content_type("text/html").body(
let response = HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
EditTemplate {
pasta: &pastas[index],
args: &ARGS,
Expand All @@ -206,7 +206,7 @@ pub async fn post_edit_private(
return Ok(response);
}
Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}

Expand Down Expand Up @@ -303,7 +303,7 @@ pub async fn post_submit_edit_private(
.finish());
}
Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}

Expand Down Expand Up @@ -394,6 +394,6 @@ pub async fn post_edit(
}

Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}
2 changes: 1 addition & 1 deletion src/endpoints/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ pub struct ErrorTemplate<'a> {

pub async fn not_found() -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}
2 changes: 1 addition & 1 deletion src/endpoints/guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ struct Guide<'a> {
#[get("/guide")]
pub async fn guide() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(Guide { args: &ARGS }.render().unwrap())
}
2 changes: 1 addition & 1 deletion src/endpoints/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub async fn list(data: web::Data<AppState>) -> HttpResponse {
// sort pastas in reverse-chronological order of creation time
pastas.sort_by(|a, b| b.created.cmp(&a.created));

HttpResponse::Ok().content_type("text/html").body(
HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
ListTemplate {
pastas: &pastas,
args: &ARGS,
Expand Down
14 changes: 7 additions & 7 deletions src/endpoints/pasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn pastaresponse(
}

// serve pasta in template
let response = HttpResponse::Ok().content_type("text/html").body(
let response = HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
PastaTemplate {
pasta: &pastas[index],
args: &ARGS,
Expand Down Expand Up @@ -123,7 +123,7 @@ fn pastaresponse(

// otherwise send pasta not found error
Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}

Expand Down Expand Up @@ -236,14 +236,14 @@ fn urlresponse(data: web::Data<AppState>, id: web::Path<String>) -> Result<HttpR
// send error if we're trying to open a non-url pasta as a redirect
} else {
HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap());
}
}

// otherwise send pasta not found error
Ok(HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap()))
}

Expand Down Expand Up @@ -326,7 +326,7 @@ pub async fn getrawpasta(

// otherwise send pasta not found error as raw text
Ok(HttpResponse::NotFound()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(String::from("Upload not found! :-(")))
}

Expand Down Expand Up @@ -427,7 +427,7 @@ pub async fn postrawpasta(

// send raw content of pasta
let response = Ok(HttpResponse::NotFound()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(pastas[index].content.to_owned()));

if pastas[index].content != original_content {
Expand All @@ -439,7 +439,7 @@ pub async fn postrawpasta(

// otherwise send pasta not found error as raw text
Ok(HttpResponse::NotFound()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(String::from("Upload not found! :-(")))
}

Expand Down
4 changes: 2 additions & 2 deletions src/endpoints/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub async fn getqr(data: web::Data<AppState>, id: web::Path<String>) -> HttpResp
};

// serve qr code in template
return HttpResponse::Ok().content_type("text/html").body(
return HttpResponse::Ok().content_type("text/html; charset=utf-8").body(
QRTemplate {
qr: &svg,
pasta: &pastas[index],
Expand All @@ -67,6 +67,6 @@ pub async fn getqr(data: web::Data<AppState>, id: web::Path<String>) -> HttpResp
// otherwise
// send pasta not found error
HttpResponse::Ok()
.content_type("text/html")
.content_type("text/html; charset=utf-8")
.body(ErrorTemplate { args: &ARGS }.render().unwrap())
}
Loading

0 comments on commit d05858b

Please sign in to comment.