Fix theme caching (#647)
This commit is contained in:
parent
a6c84daa1a
commit
28fb50438e
|
@ -2084,7 +2084,6 @@ dependencies = [
|
|||
"serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"shrinkwraprs 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
"tantivy 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -13,7 +13,6 @@ use rocket::{
|
|||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::Hasher,
|
||||
io::Read,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use template_utils::Ructe;
|
||||
|
@ -177,14 +176,11 @@ pub struct CachedFile {
|
|||
pub struct ThemeFile(NamedFile);
|
||||
|
||||
impl<'r> Responder<'r> for ThemeFile {
|
||||
fn respond_to(mut self, r: &Request) -> response::Result<'r> {
|
||||
let mut contents = String::new();
|
||||
self.0
|
||||
.read_to_string(&mut contents)
|
||||
.map_err(|_| Status::InternalServerError)?;
|
||||
fn respond_to(self, r: &Request) -> response::Result<'r> {
|
||||
let contents = std::fs::read(self.0.path()).map_err(|_| Status::InternalServerError)?;
|
||||
|
||||
let mut hasher = DefaultHasher::new();
|
||||
hasher.write(&contents.as_bytes());
|
||||
hasher.write(&contents);
|
||||
let etag = format!("{:x}", hasher.finish());
|
||||
|
||||
if r.headers()
|
||||
|
@ -206,7 +202,7 @@ impl<'r> Responder<'r> for ThemeFile {
|
|||
|
||||
#[get("/static/cached/<_build_id>/css/<file..>", rank = 1)]
|
||||
pub fn theme_files(file: PathBuf, _build_id: &RawStr) -> Option<ThemeFile> {
|
||||
NamedFile::open(Path::new("static/").join(file))
|
||||
NamedFile::open(Path::new("static/css/").join(file))
|
||||
.ok()
|
||||
.map(ThemeFile)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue