Skip to content

Commit

Permalink
give error page for non-existing shortlink
Browse files Browse the repository at this point in the history
probably more UX then just a redirect home
  • Loading branch information
glendc committed Oct 24, 2023
1 parent bbcceec commit f5c48c9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
19 changes: 13 additions & 6 deletions src/router/redirect.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
use std::sync::Arc;

use askama_axum::{IntoResponse, Response};
use axum::{
extract::{Path, State},
http::StatusCode,
response::Redirect,
};

pub async fn get(
State(state): State<Arc<crate::router::State>>,
Path(hash): Path<String>,
) -> Redirect {
) -> Response {
match hash.as_str() {
"code" => Redirect::permanent("https://github.com/plabayo/bucket"),
"author" => Redirect::permanent("https://plabayo.tech"),
"code" => Redirect::permanent("https://github.com/plabayo/bucket").into_response(),
"author" => Redirect::permanent("https://plabayo.tech").into_response(),
"og-image" => Redirect::permanent(
"https://upload.wikimedia.org/wikipedia/commons/3/3b/Sand_bucket.jpg",
),
)
.into_response(),
hash => {
if let Some(link) = state.storage.get_shortlink(hash).await {
Redirect::temporary(link.long_url())
Redirect::temporary(link.long_url()).into_response()
} else {
Redirect::temporary("/")
(StatusCode::NOT_FOUND, crate::router::shared::ErrorTemplate {
title: "Not Found".to_string(),
message: "The requested shortlink does not exist. It might have been deleted or perhaps it never existed to begin with. Please try with another one.".to_string(),
back_path: "/".to_string(),
}).into_response()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ button:hover, .\<button\>:hover, input[type=submit]:hover {
cursor: pointer;
}

.table div p {
.table > div > p {
padding: calc(var(--gap)*0.2);
}

Expand Down
4 changes: 2 additions & 2 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<script type="module" src="/static/js/bckt.js?v=0.1.0"></script>

<link rel="stylesheet" href="/static/css/missing.min.css?v=1.1.1" />
<link rel="stylesheet" href="/static/css/style.css?t=bucket&v=0.1.4" />
<link rel="stylesheet" href="/static/css/style.css?t=bucket&v=0.1.5" />
</head>

<body>
Expand All @@ -39,7 +39,7 @@ <h1 style="margin: 0;">
<p style="margin: 0; padding-bottom: 10px;">
<a href="/code">Made with</a>
❤️ by
<a href="/author">plabayo</a>
<a href="/author">Plabayo</a>
.
</p>
</header>
Expand Down
2 changes: 1 addition & 1 deletion templates/content/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</p>
</form>
</div>
<div class="box info">
<div class="box info" style="margin: 0;">
<strong class="block titlebar">🔒 Private Platform</strong>
<p>
Only authorized email addreses can login using magic links.
Expand Down
2 changes: 1 addition & 1 deletion templates/content/shared/link_nav.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="container crowded">
<div class="container crowded margin-block">
<h3>shortlinks by <code>{{ email }}</code></h1>
<section class="tool-bar">
<a href="/logout" class="<button> bad">👋 Logout</a>
Expand Down
16 changes: 15 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
{% extends "base.html" %}
{% block content %}
<div class="container crowded">
<div class="container crowded margin-block">
<h3>welcome <code>{{ email }}</code></h1>
<section class="tool-bar">
<a href="/logout" class="<button> bad">👋 Logout</a>
</section>
</div>
<div class="table rows spacious">
<div>
<p>
On this page you can click through to create and manage shortlinks and secrets.
Shortlinks and secrets can be shared with anyone, and require no login to this platform.
</p>
</div>
<div>
<p>
Secrets are a way to share sensitive information, and are encrypted client-side,
can expire and even be one-time use.
</p>
</div>
</div>
<div class="box card">
<strong class="block titlebar">🔗 Shortlinks</strong>
<p>
Expand Down

0 comments on commit f5c48c9

Please sign in to comment.