1
0
mirror of https://github.com/spikecodes/libreddit synced 2024-12-28 03:25:30 +01:00

Use std::fs over actix-files

This commit is contained in:
spikecodes 2020-11-18 16:31:46 -08:00
parent 4f379754f7
commit f455e2095d
8 changed files with 11 additions and 74 deletions

62
Cargo.lock generated
View File

@ -35,26 +35,6 @@ dependencies = [
"trust-dns-resolver",
]
[[package]]
name = "actix-files"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fc0a9181e93c91dc7eb401a0debaed5c8294e12019c307c72fd7a1731b672fc"
dependencies = [
"actix-service",
"actix-web",
"bitflags",
"bytes",
"derive_more",
"futures-core",
"futures-util",
"log",
"mime",
"mime_guess",
"percent-encoding",
"v_htmlescape",
]
[[package]]
name = "actix-http"
version = "2.1.0"
@ -457,15 +437,6 @@ dependencies = [
"libc",
]
[[package]]
name = "buf-min"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6ae7069aad07c7cdefe6a22a671f00650728bd2331a4cc62e1e5d0becdf9ca4"
dependencies = [
"bytes",
]
[[package]]
name = "bumpalo"
version = "3.4.0"
@ -1068,7 +1039,6 @@ checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
name = "libreddit"
version = "0.1.3"
dependencies = [
"actix-files",
"actix-web",
"askama",
"chrono",
@ -2169,38 +2139,6 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "v_escape"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "039a44473286eb84e4e74f90165feff67c802dbeced7ee4c5b00d719b0d0475e"
dependencies = [
"buf-min",
"v_escape_derive",
]
[[package]]
name = "v_escape_derive"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c860ad1273f4eee7006cee05db20c9e60e5d24cba024a32e1094aa8e574f3668"
dependencies = [
"nom",
"proc-macro2 1.0.24",
"quote 1.0.7",
"syn 1.0.48",
]
[[package]]
name = "v_htmlescape"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11d7c2a33ed7cf0dc1b42bcf39e01b6512f9df08f09e1cd8a49d9dc49a6a9482"
dependencies = [
"cfg-if 1.0.0",
"v_escape",
]
[[package]]
name = "vcpkg"
version = "0.2.10"

View File

@ -9,7 +9,6 @@ edition = "2018"
[dependencies]
actix-web = "3.2.0"
actix-files = "0.4.0"
askama = "0.8.0"
serde = "1.0.117"
serde_json = "1.0"

View File

@ -1,6 +1,6 @@
// Import Crates
use actix_files::NamedFile;
use actix_web::{get, App, HttpResponse, HttpServer, Result};
use actix_web::{get, App, HttpResponse, HttpServer};
use std::fs;
// Reference local files
mod popular;
@ -10,9 +10,9 @@ mod user;
// Create Services
#[get("/style.css")]
async fn style() -> Result<NamedFile> {
let file = NamedFile::open("static/style.css");
Ok(file?)
async fn style() -> HttpResponse {
let file = fs::read_to_string("static/style.css").expect("ERROR: Could not read style.css");
HttpResponse::Ok().body(file)
}
#[get("/favicon.ico")]

View File

@ -8,7 +8,7 @@ use subreddit::{posts, Post};
#[path = "utils.rs"]
mod utils;
use utils::{Params};
use utils::Params;
// STRUCTS
#[derive(Template)]

View File

@ -6,7 +6,7 @@ use pulldown_cmark::{html, Options, Parser};
#[path = "utils.rs"]
mod utils;
use utils::{Params, Comment, Flair, Post, val};
use utils::{val, Comment, Flair, Params, Post};
// STRUCTS
#[derive(Template)]

View File

@ -5,7 +5,7 @@ use chrono::{TimeZone, Utc};
#[path = "utils.rs"]
mod utils;
pub use utils::{Params, Flair, Post, Subreddit, val};
pub use utils::{val, Flair, Params, Post, Subreddit};
// STRUCTS
#[derive(Template)]

View File

@ -5,7 +5,7 @@ use chrono::{TimeZone, Utc};
#[path = "utils.rs"]
mod utils;
use utils::{Params, Flair, Post, User, val, nested_val};
use utils::{nested_val, val, Flair, Params, Post, User};
// STRUCTS
#[derive(Template)]
@ -70,7 +70,7 @@ async fn posts(sub: String, sort: &String) -> Vec<Post> {
let title = val(post, "title").await;
posts.push(Post {
title: if title.is_empty() {"Comment".to_string()} else {title},
title: if title.is_empty() { "Comment".to_string() } else { title },
community: val(post, "subreddit").await,
body: String::new(),
author: val(post, "author").await,

View File

@ -60,4 +60,4 @@ pub async fn nested_val(j: &serde_json::Value, n: &str, k: &str) -> String {
#[derive(serde::Deserialize)]
pub struct Params {
pub sort: Option<String>,
}
}