diff --git a/Cargo.lock b/Cargo.lock index 7fd809b..451fec0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -320,17 +320,6 @@ dependencies = [ "askama_shared", ] -[[package]] -name = "askama_actix" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52f74f8382a142ecfc052100b21abc33f2c069e20fe345808e7ed914b179449" -dependencies = [ - "actix-web", - "askama", - "askama_shared", -] - [[package]] name = "askama_derive" version = "0.11.2" @@ -1593,7 +1582,6 @@ dependencies = [ "actix-web", "actix-web-actors", "askama", - "askama_actix", "bytes", "bytesize", "crc32fast", diff --git a/Cargo.toml b/Cargo.toml index 5c71047..6d1940b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ actix-http = "3.0.4" actix-web = "4.0.1" actix-web-actors = "4.1.0" askama = "0.11.1" -askama_actix = "0.13" bytes = "1.1.0" bytesize = "1.1.0" crc32fast = "1.3.2" diff --git a/flake.lock b/flake.lock index 0fb77ae..d248f57 100644 --- a/flake.lock +++ b/flake.lock @@ -33,11 +33,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1655306633, - "narHash": "sha256-nv4FfWWV/dEelByjXJtJkoDPOHIsKfLq50RN3Hqq5Yk=", + "lastModified": 1653060744, + "narHash": "sha256-kfRusllRumpt33J1hPV+CeCCylCXEU7e0gn2/cIM7cY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b1957596ff1c7aa8c55c4512b7ad1c9672502e8e", + "rev": "dfd82985c273aac6eced03625f454b334daae2e8", "type": "github" }, "original": { @@ -77,11 +77,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1655347556, - "narHash": "sha256-JZ06EaeHi9sbbO3n8qYZ8KzDfSbDlPVRHI6Pw4sAxRE=", + "lastModified": 1653273659, + "narHash": "sha256-dHXYaNL1axhZZyiZXxt1WKhvZrYXq7bjCs3y5VjgyGI=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "1cc3dc5aec863c2f724a46f7086fb011004a4e6e", + "rev": "0fa3e01da1ce98e3b40063b8e2678095943402b1", "type": "github" }, "original": { @@ -92,11 +92,11 @@ }, "utils": { "locked": { - "lastModified": 1653893745, - "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "lastModified": 1652776076, + "narHash": "sha256-gzTw/v1vj4dOVbpBSJX4J0DwUR6LIyXo7/SuuTJp1kM=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "rev": "04c1b180862888302ddfb2e3ad9eaa63afc60cf8", "type": "github" }, "original": { diff --git a/src/main.rs b/src/main.rs index cf591ab..97b4876 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,13 +6,12 @@ mod zip; use std::{fmt::Debug, path::PathBuf, str::FromStr}; -use actix_http::StatusCode; use actix_web::{ error::InternalError, get, middleware::Logger, post, web, App, HttpRequest, HttpResponse, HttpServer, Responder, }; use actix_web_actors::ws; -use askama_actix::{Template, TemplateToResponse}; +use askama::Template; use bytesize::ByteSize; use log::{error, warn}; use serde::{Deserialize, Serialize}; @@ -56,15 +55,19 @@ pub fn log_auth_failure(ip_addr: &str) { #[derive(Template)] #[template(path = "index.html")] -struct IndexPage { - cachebuster: String, +struct IndexPage<'a> { + cachebuster: &'a str, } #[get("/")] async fn index(data: web::Data) -> impl Responder { - IndexPage { - cachebuster: data.config.cachebuster.clone(), - } + HttpResponse::Ok().body( + IndexPage { + cachebuster: &data.config.cachebuster, + } + .render() + .unwrap(), + ) } #[derive(Deserialize)] @@ -126,16 +129,19 @@ async fn handle_download( .into_response(&req)) } else { let offsets = info.contents.as_deref().map(zip::file_data_offsets); - Ok(DownloadPage { - info: DownloadInfo { - file: info, - code: code.clone(), - available: file.metadata().await?.len(), - offsets, - }, - cachebuster: &data.config.cachebuster, - } - .to_response()) + Ok(HttpResponse::Ok().body( + DownloadPage { + info: DownloadInfo { + file: info, + code: code.clone(), + available: file.metadata().await?.len(), + offsets, + }, + cachebuster: &data.config.cachebuster, + } + .render() + .unwrap(), + )) } } @@ -182,13 +188,17 @@ fn not_found(req: HttpRequest, data: web::Data, report: bool) -> ac let ip_addr = get_ip_addr(&req, data.config.reverse_proxy); log_auth_failure(&ip_addr); } - let mut resp = NotFoundPage { - cachebuster: &data.config.cachebuster, - } - .to_response(); - *resp.status_mut() = StatusCode::NOT_FOUND; - - Err(InternalError::from_response("Download not found", resp).into()) + Err(InternalError::from_response( + "Download not found", + HttpResponse::NotFound().body( + NotFoundPage { + cachebuster: &data.config.cachebuster, + } + .render() + .unwrap(), + ), + ) + .into()) } #[get("/upload")]