Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix some URLs with args.public_path_as_str() #194

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/endpoints/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct AdminTemplate<'a> {
#[get("/admin")]
pub async fn get_admin() -> Result<HttpResponse, Error> {
return Ok(HttpResponse::Found()
.append_header(("Location", "/auth_admin"))
.append_header(("Location", format!("{}/auth_admin", ARGS.public_path_as_str())))
.finish());
}

Expand All @@ -48,7 +48,7 @@ pub async fn post_admin(

if username != ARGS.auth_admin_username || password != ARGS.auth_admin_password {
return Ok(HttpResponse::Found()
.append_header(("Location", "/auth_admin/incorrect"))
.append_header(("Location", format!("{}/auth_admin/incorrect", ARGS.public_path_as_str())))
.finish());
}

Expand Down
2 changes: 1 addition & 1 deletion src/endpoints/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub async fn create(
if ARGS.readonly && ARGS.uploader_password.is_some() {
if uploader_password != ARGS.uploader_password.as_ref().unwrap().to_owned() {
return Ok(HttpResponse::Found()
.append_header(("Location", "/incorrect"))
.append_header(("Location", format!("{}/incorrect", ARGS.public_path_as_str())))
.finish());
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/endpoints/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn get_edit(data: web::Data<AppState>, id: web::Path<String>) -> HttpR
return HttpResponse::Found()
.append_header((
"Location",
format!("/auth_edit_private/{}", pasta.id_as_animals()),
format!("{}/auth_edit_private/{}", ARGS.public_path_as_str(), pasta.id_as_animals()),
))
.finish();
}
Expand Down Expand Up @@ -95,7 +95,7 @@ pub async fn get_edit_with_status(
return HttpResponse::Found()
.append_header((
"Location",
format!("/auth_edit_private/{}", pasta.id_as_animals()),
format!("{}/auth_edit_private/{}", ARGS.public_path_as_str(), pasta.id_as_animals()),
))
.finish();
}
Expand Down Expand Up @@ -174,7 +174,8 @@ pub async fn post_edit_private(
.append_header((
"Location",
format!(
"/auth_edit_private/{}/incorrect",
"{}/auth_edit_private/{}/incorrect",
ARGS.public_path_as_str(),
pastas[index].id_as_animals()
),
))
Expand Down Expand Up @@ -261,7 +262,7 @@ pub async fn post_submit_edit_private(
return Ok(HttpResponse::Found()
.append_header((
"Location",
format!("/edit/{}/incorrect", pastas[index].id_as_animals()),
format!("{}/edit/{}/incorrect", ARGS.public_path_as_str(), pastas[index].id_as_animals()),
))
.finish());
}
Expand All @@ -278,7 +279,8 @@ pub async fn post_submit_edit_private(
.append_header((
"Location",
format!(
"/auth_edit_private/{}/incorrect",
"{}/auth_edit_private/{}/incorrect",
ARGS.public_path_as_str(),
pastas[index].id_as_animals()
),
))
Expand All @@ -289,7 +291,7 @@ pub async fn post_submit_edit_private(
return Ok(HttpResponse::Found()
.append_header((
"Location",
format!("/auth/{}/success", pastas[index].id_as_animals()),
format!("{}/auth/{}/success", ARGS.public_path_as_str(), pastas[index].id_as_animals()),
))
.finish());
}
Expand Down Expand Up @@ -344,15 +346,15 @@ pub async fn post_edit(
return Ok(HttpResponse::Found()
.append_header((
"Location",
format!("/edit/{}/incorrect", pasta.id_as_animals()),
format!("{}/edit/{}/incorrect", ARGS.public_path_as_str(), pasta.id_as_animals()),
))
.finish());
}
} else {
return Ok(HttpResponse::Found()
.append_header((
"Location",
format!("/edit/{}/incorrect", pasta.id_as_animals()),
format!("{}/edit/{}/incorrect", ARGS.public_path_as_str(), pasta.id_as_animals()),
))
.finish());
}
Expand Down
10 changes: 5 additions & 5 deletions src/endpoints/pasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn pastaresponse(
return HttpResponse::Found()
.append_header((
"Location",
format!("/auth/{}", pastas[index].id_as_animals()),
format!("{}/auth/{}", ARGS.public_path_as_str(), pastas[index].id_as_animals()),
))
.finish();
}
Expand All @@ -77,7 +77,7 @@ fn pastaresponse(
return HttpResponse::Found()
.append_header((
"Location",
format!("/auth/{}/incorrect", pastas[index].id_as_animals()),
format!("{}/auth/{}/incorrect", ARGS.public_path_as_str(), pastas[index].id_as_animals()),
))
.finish();
}
Expand Down Expand Up @@ -280,7 +280,7 @@ pub async fn getrawpasta(
return Ok(HttpResponse::Found()
.append_header((
"Location",
format!("/auth_raw/{}", pastas[index].id_as_animals()),
format!("{}/auth_raw/{}", ARGS.public_path_as_str(), pastas[index].id_as_animals()),
))
.finish());
}
Expand Down Expand Up @@ -361,7 +361,7 @@ pub async fn postrawpasta(
return Ok(HttpResponse::Found()
.append_header((
"Location",
format!("/auth/{}", pastas[index].id_as_animals()),
format!("{}/auth/{}", ARGS.public_path_as_str(), pastas[index].id_as_animals()),
))
.finish());
}
Expand All @@ -385,7 +385,7 @@ pub async fn postrawpasta(
return Ok(HttpResponse::Found()
.append_header((
"Location",
format!("/auth/{}/incorrect", pastas[index].id_as_animals()),
format!("{}/auth/{}/incorrect", ARGS.public_path_as_str(), pastas[index].id_as_animals()),
))
.finish());
}
Expand Down
6 changes: 3 additions & 3 deletions src/endpoints/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub async fn remove(data: web::Data<AppState>, id: web::Path<String>) -> HttpRes
return HttpResponse::Found()
.append_header((
"Location",
format!("/auth_remove_private/{}", pasta.id_as_animals()),
format!("{}/auth_remove_private/{}", ARGS.public_path_as_str(), pasta.id_as_animals()),
))
.finish();
}
Expand Down Expand Up @@ -150,15 +150,15 @@ pub async fn post_remove(
return Ok(HttpResponse::Found()
.append_header((
"Location",
format!("/auth_remove_private/{}/incorrect", pasta.id_as_animals()),
format!("{}/auth_remove_private/{}/incorrect", ARGS.public_path_as_str(), pasta.id_as_animals()),
))
.finish());
}
} else {
return Ok(HttpResponse::Found()
.append_header((
"Location",
format!("/auth_remove_private/{}/incorrect", pasta.id_as_animals()),
format!("{}/auth_remove_private/{}/incorrect", ARGS.public_path_as_str(), pasta.id_as_animals()),
))
.finish());
}
Expand Down
2 changes: 1 addition & 1 deletion templates/auth_admin.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% include "header.html" %}

<form id="auth-form" method="POST" action="/admin/" enctype="multipart/form-data">
<form id="auth-form" method="POST" action="{{ args.public_path_as_str() }}/admin/" enctype="multipart/form-data">
<label for="username"> Administrator username</label>
<input id="username-field" placeholder="Username" type="username" autocomplete="off" name="username">
<label for="password"> Administrator password.</label>
Expand Down
8 changes: 4 additions & 4 deletions templates/auth_upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

{% if encrypt_client %}

<form id="auth-form" method="POST" action="/{{path}}/{{id}}" enctype="multipart/form-data">
<form id="auth-form" method="POST" action="{{ args.public_path_as_str() }}/{{path}}/{{id}}" enctype="multipart/form-data">
{% if status == "success" %}
<b>
Success!
</b> <br>
{% endif %}
<label for="password"> Please enter the
password to access or modify this upload. <sup>
<a href="/guide#encryption">﹖</a></sup></label>
<a href="{{ args.public_path_as_str() }}/guide#encryption">﹖</a></sup></label>
<input id="password-field" required placeholder="Password" type="password" autocomplete="off">
<input id="password-hidden" name="password" type="hidden">
<button>Okay</button>
Expand Down Expand Up @@ -60,15 +60,15 @@

{% else %}

<form id="auth-form" method="POST" action="/{{path}}/{{id}}" enctype="multipart/form-data">
<form id="auth-form" method="POST" action="{{ args.public_path_as_str() }}/{{path}}/{{id}}" enctype="multipart/form-data">
{% if status == "success" %}
<b>
Success!
</b> <br>
{% endif %}
<label for="password" style="margin-bottom: 0.5rem;"> Please enter the
password to access or modify this upload. <sup>
<a href="/guide#encryption">﹖</a></sup></label>
<a href="{{ args.public_path_as_str() }}/guide#encryption">﹖</a></sup></label>
<input id="password-field" placeholder="Password" name="password" type="password" autocomplete="off" />
<button>Okay</button>

Expand Down
4 changes: 2 additions & 2 deletions templates/edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% include "header.html" %}
<form action="/{{ path }}/{{ pasta.id_as_animals() }}" method="POST" enctype="multipart/form-data">
<form action="{{ args.public_path_as_str() }}/{{ path }}/{{ pasta.id_as_animals() }}" method="POST" enctype="multipart/form-data">
<h4>
Editing upload '{{ pasta.id_as_animals() }}'
</h4>
Expand All @@ -11,7 +11,7 @@ <h4>
<div>
{% if pasta.readonly || pasta.encrypt_server %}
<div style="float: left; height: 90px;">
<label for="password">Re-enter Password <sup><a href="/guide#password">﹖</a></sup></label><br>
<label for="password">Re-enter Password <sup><a href="{{ args.public_path_as_str() }}/guide#password">﹖</a></sup></label><br>
<input {% if status=="incorrect" %} autofocus {% endif %} style="width: 130px; height: 28px;"
type="password" id="password" name="password" autocomplete="off" />
{% if status == "incorrect" %}
Expand Down
2 changes: 1 addition & 1 deletion templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{% if !args.hide_logo %}
<!-- <i><span style="font-size:2.2rem;
margin-right:1rem">μ</span></i> -->
<a href="/"><img width=100 style="margin-bottom: -6px; margin-right:
<a href="{{ args.public_path_as_str() }}"><img width=100 style="margin-bottom: -6px; margin-right:
0.5rem;" src="{{ args.public_path_as_str() }}/static/logo.png"></a>
{%- endif %} {% if args.title.as_ref().is_none() %} {%- else %} {{
args.title.as_ref().unwrap() }} {%- endif %}
Expand Down
14 changes: 7 additions & 7 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% include "header.html" %}
<form id="pasta-form" action="upload" method="POST" enctype="multipart/form-data">
<form id="pasta-form" action="{{ args.public_path_as_str() }}/upload" method="POST" enctype="multipart/form-data">
<br>
<div id="settings">
<div>
<label for="expiration">Expiration <sup> <a href="/guide#expiration">﹖</a></sup></label><br>
<label for="expiration">Expiration <sup> <a href="{{ args.public_path_as_str() }}/guide#expiration">﹖</a></sup></label><br>
<select style="width: 100%;" name="expiration" id="expiration">
<optgroup label="Expire after">
{% if args.default_expiry == "1min" %}
Expand Down Expand Up @@ -54,7 +54,7 @@
</div>
{% if args.enable_burn_after %}
<div>
<label for="burn_after">Burn After <sup> <a href="/guide#burn-after">﹖</a></sup></label><br>
<label for="burn_after">Burn After <sup> <a href="{{ args.public_path_as_str() }}/guide#burn-after">﹖</a></sup></label><br>
<select style="width: 100%;" name="burn_after" id="burn_after">
{% if args.default_burn_after == 0 %}
<option selected value="0">
Expand Down Expand Up @@ -100,7 +100,7 @@

{% if args.highlightsyntax %}
<div>
<label for="syntax_highlight">Syntax <sup> <a href="/guide#syntax">﹖</a></sup></label><br>
<label for="syntax_highlight">Syntax <sup> <a href="{{ args.public_path_as_str() }}/guide#syntax">﹖</a></sup></label><br>
<select style="width: 100%;" name="syntax_highlight" id="syntax_highlight">
<option value="none">None</option>
<optgroup label="Client-Rendered">
Expand Down Expand Up @@ -142,7 +142,7 @@
{%- endif %}

<div>
<label for="syntax_highlight">Privacy <sup> <a href="/guide#privacy">﹖</a></sup></label><br>
<label for="syntax_highlight">Privacy <sup> <a href="{{ args.public_path_as_str() }}/guide#privacy">﹖</a></sup></label><br>
<select style="width: 100%;" name="privacy" id="privacy">
<optgroup label="Unencrypted (no password)">
<option value="public">Public</option>
Expand Down Expand Up @@ -170,7 +170,7 @@

{% if args.encryption_client_side || args.encryption_server_side || args.enable_readonly %}
<div>
<label for="password_field">Password <sup><a href="/guide#password">﹖</a></sup></label><br>
<label for="password_field">Password <sup><a href="{{ args.public_path_as_str() }}/guide#password">﹖</a></sup></label><br>
<input style="width: 130px; height: 28px;" type="password" id="password_field" autocomplete="off" />
</div>
{%- endif %}
Expand Down Expand Up @@ -281,7 +281,7 @@
submitButton.textContent = 'Uploading...';

const xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.open('POST', '{{ args.public_path_as_str() }}/upload', true);

xhr.upload.onprogress = function (event) {
if (showProgress) {
Expand Down
4 changes: 2 additions & 2 deletions templates/upload.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<div id="decryption">
{% if pasta.encrypt_client %}
<label for="password-field" style="margin-bottom: 0.5em;">
Please enter your key to decrypt this upload. <sup> <a href="/guide#encryption">﹖</a></sup>
Please enter your key to decrypt this upload. <sup> <a href="{{ args.public_path_as_str() }}/guide#encryption">﹖</a></sup>
</label>
<input class="small-button" placeholder="Key" style="margin-right: 0.5rem" type="password" id="password-field"
autocomplete="off" />
Expand Down Expand Up @@ -241,7 +241,7 @@
// {%- endif %}
formData.append('password', key);

const response = await fetch('/secure_file/{{ pasta.id_as_animals() }}', {
const response = await fetch('{{ args.public_path_as_str() }}/secure_file/{{ pasta.id_as_animals() }}', {
method: 'POST',
body: formData,
})
Expand Down