Add helper, updaet TODO, add app.db to gitignore

This commit is contained in:
willem640 2023-05-24 14:48:15 +00:00
parent f6797049af
commit ac52322b2b
4 changed files with 27 additions and 3 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target
app.db

3
TODO
View File

@ -6,6 +6,7 @@
- ip blacklist
- clear/delete hits
- move db operations out of db_delegate
- email notification on hit
- ORM?
- async?
- pipelining?
- pipelining?

18
src/helpers.rs Normal file
View File

@ -0,0 +1,18 @@
use rouille::Response;
pub fn javascript_redirect(path: &str) -> Response {
Response::html(format!("
<!DOCTYPE html>
<html>
<head>
<title>Redirecting...</title>
<meta http-equiv=\"refresh\" content=\"0;URL='{path}'\">
<script>
window.location.href = \"{path}\";
</script>
</head>
<body>
<h1>Redirecting...</h1>
</body>
</html>"))
}

View File

@ -8,6 +8,7 @@ use pixel::{Hit, PixelManager, PixelManagerDelegate, TrackingPixel, User};
mod db;
mod pixel;
mod helpers;
fn main() {
@ -162,7 +163,8 @@ fn create_pixel(request: &Request, manager_delegate: &PixelManagerDelegate) -> R
Ok(pixel) => pixel,
Err(_) => return Response::empty_400()
};
Response::redirect_303("/manage")
// Response::redirect_303("/manage")
helpers::javascript_redirect("/manage")
}
fn delete_pixel(request: &Request, manager_delegate: &PixelManagerDelegate) -> Response {
@ -186,7 +188,9 @@ fn delete_pixel(request: &Request, manager_delegate: &PixelManagerDelegate) -> R
} else {
return Response::empty_400(); // could not find pixel
}
Response::redirect_303("/manage")
// Response::redirect_303("/manage")
helpers::javascript_redirect("/manage")
}
fn register_hit(pixel_id: &str, request: &Request, manager_delegate: &PixelManagerDelegate) {