mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-25 21:11:01 +00:00
Fix theme caching (#647)
This commit is contained in:
parent
a6c84daa1a
commit
28fb50438e
2 changed files with 4 additions and 9 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2084,7 +2084,6 @@ dependencies = [
|
||||||
"serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -13,7 +13,6 @@ use rocket::{
|
||||||
use std::{
|
use std::{
|
||||||
collections::hash_map::DefaultHasher,
|
collections::hash_map::DefaultHasher,
|
||||||
hash::Hasher,
|
hash::Hasher,
|
||||||
io::Read,
|
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
use template_utils::Ructe;
|
use template_utils::Ructe;
|
||||||
|
@ -177,14 +176,11 @@ pub struct CachedFile {
|
||||||
pub struct ThemeFile(NamedFile);
|
pub struct ThemeFile(NamedFile);
|
||||||
|
|
||||||
impl<'r> Responder<'r> for ThemeFile {
|
impl<'r> Responder<'r> for ThemeFile {
|
||||||
fn respond_to(mut self, r: &Request) -> response::Result<'r> {
|
fn respond_to(self, r: &Request) -> response::Result<'r> {
|
||||||
let mut contents = String::new();
|
let contents = std::fs::read(self.0.path()).map_err(|_| Status::InternalServerError)?;
|
||||||
self.0
|
|
||||||
.read_to_string(&mut contents)
|
|
||||||
.map_err(|_| Status::InternalServerError)?;
|
|
||||||
|
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
hasher.write(&contents.as_bytes());
|
hasher.write(&contents);
|
||||||
let etag = format!("{:x}", hasher.finish());
|
let etag = format!("{:x}", hasher.finish());
|
||||||
|
|
||||||
if r.headers()
|
if r.headers()
|
||||||
|
@ -206,7 +202,7 @@ impl<'r> Responder<'r> for ThemeFile {
|
||||||
|
|
||||||
#[get("/static/cached/<_build_id>/css/<file..>", rank = 1)]
|
#[get("/static/cached/<_build_id>/css/<file..>", rank = 1)]
|
||||||
pub fn theme_files(file: PathBuf, _build_id: &RawStr) -> Option<ThemeFile> {
|
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()
|
.ok()
|
||||||
.map(ThemeFile)
|
.map(ThemeFile)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue