Skip to content

Commit

Permalink
add static assets
Browse files Browse the repository at this point in the history
  • Loading branch information
avoonix committed Jun 29, 2024
1 parent c91f781 commit 90d4c6d
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 90 deletions.
227 changes: 146 additions & 81 deletions fuzzle/assets/fuzzle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Binary file added fuzzle/public-assets/fuzzle_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fuzzle/public-assets/fuzzle_happy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fuzzle/public-assets/fuzzle_info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 36 additions & 7 deletions fuzzle/src/web/server/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ use actix_web_lab::{
};
use itertools::Itertools;

use crate::{sticker::{
create_historgram_image, create_sticker_thumbnail, fetch_sticker_file, generate_merge_image
}, util::Required};
use crate::{
sticker::{
create_historgram_image, create_sticker_thumbnail, fetch_sticker_file, generate_merge_image,
},
util::Required,
};
use web::Data;

use crate::web::server::auth::AUTH_COOKIE_NAME;
Expand Down Expand Up @@ -76,8 +79,7 @@ async fn sticker_set_thumbnail(
.as_ref(),
)
.await?;
let buf = create_sticker_thumbnail(files, 400, data.bot.clone(), data.config.clone())
.await?;
let buf = create_sticker_thumbnail(files, 400, data.bot.clone(), data.config.clone()).await?;
Ok(HttpResponse::Ok()
.insert_header(thumbnail_cache_control_header())
.insert_header(header::ContentType::png())
Expand All @@ -99,8 +101,7 @@ async fn sticker_comparison_thumbnail(
.filter(|s| file_hashes.contains(s))
.collect_vec();
let files = data.database.get_sticker_files_by_ids(&common).await?;
let buf = create_sticker_thumbnail(files, 400, data.bot.clone(), data.config.clone())
.await?;
let buf = create_sticker_thumbnail(files, 400, data.bot.clone(), data.config.clone()).await?;
Ok(HttpResponse::Ok()
.insert_header(thumbnail_cache_control_header())
.insert_header(header::ContentType::png())
Expand Down Expand Up @@ -151,3 +152,31 @@ async fn login(
.status(actix_web::http::StatusCode::TEMPORARY_REDIRECT)
.finish())
}

use actix_web::{App, HttpServer};
use mime_guess::from_path;
use rust_embed::Embed;

#[derive(Embed)]
#[folder = "public-assets/"]
struct Asset;

fn handle_embedded_file(path: &str) -> HttpResponse {
match Asset::get(path) {
Some(content) => HttpResponse::Ok()
.content_type(from_path(path).first_or_octet_stream().as_ref())
.insert_header(thumbnail_cache_control_header())
.body(content.data.into_owned()),
None => HttpResponse::NotFound().body("404 Not Found"),
}
}

#[actix_web::get("/favicon.ico")]
pub async fn favicon() -> impl Responder {
handle_embedded_file("favicon.ico")
}

#[actix_web::get("/assets/{_:.*}")]
pub async fn asset_folder(path: web::Path<String>) -> impl Responder {
handle_embedded_file(path.as_str())
}
5 changes: 3 additions & 2 deletions fuzzle/src/web/server/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use actix_files::Files;
use actix_web::{middleware, web, App, HttpServer};

use crate::{
background_tasks::TaggingWorker, bot::Bot, database::Database, qdrant::VectorDatabase,
tags::TagManager, Config,
background_tasks::TaggingWorker, bot::Bot, database::Database, qdrant::VectorDatabase, tags::TagManager, Config
};

use super::service;
Expand Down Expand Up @@ -49,6 +48,8 @@ pub fn setup(
// .service(service::favicon)
.service(service::login)
.service(service::logout)
.service(service::favicon)
.service(service::asset_folder)
// .service(service::sticker_files)
// .service(service::merge_files)
.service(service::sticker_set_thumbnail)
Expand Down

0 comments on commit 90d4c6d

Please sign in to comment.