cleanup, sync
parent
43e5d473b7
commit
6822b5eab5
36
css/base.css
36
css/base.css
|
@ -1,36 +0,0 @@
|
|||
body {
|
||||
background-color: #92a8d1;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
height: 100vh;
|
||||
}
|
||||
@media(max-width: 500px) {
|
||||
body {
|
||||
padding: 1px;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@media(min-width: 501px) and (max-width: 550px) {
|
||||
body {
|
||||
padding: 1px;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 5fr 1fr;
|
||||
}
|
||||
.mainContainer {grid-column-start: 2;}
|
||||
}
|
||||
@media(min-width: 551px) and (max-width: 1000px) {
|
||||
body {
|
||||
padding: 1px;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 3fr 1fr;
|
||||
}
|
||||
.mainContainer {grid-column-start: 2;}
|
||||
}
|
||||
@media(min-width: 1001px) {
|
||||
body {
|
||||
padding: 1px;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
.mainContainer {grid-column-start: 2;}
|
||||
}
|
37
css/main.css
37
css/main.css
|
@ -1,37 +0,0 @@
|
|||
.itemContainer {
|
||||
background: #034f84;
|
||||
margin: 0.3rem;
|
||||
}
|
||||
.itemContainer:hover {
|
||||
background: #034f99;
|
||||
}
|
||||
.itemContainer p {
|
||||
color: white;
|
||||
display: inline-block;
|
||||
margin: 0.5rem;
|
||||
margin-right: 0.4rem;
|
||||
margin-left: 0.4rem;
|
||||
}
|
||||
.actionButton {
|
||||
display: inline-block;
|
||||
float: right;
|
||||
background: #f7786b;
|
||||
border: none;
|
||||
padding: 0.5rem;
|
||||
padding-left: 2rem;
|
||||
padding-right: 2rem;
|
||||
color: white;
|
||||
}
|
||||
.actionButton:hover {
|
||||
background: #f7686b;
|
||||
color: black;
|
||||
}
|
||||
.inputContainer {
|
||||
background: #034f84;
|
||||
margin: 0.3rem;
|
||||
margin-top: 2rem;
|
||||
}
|
||||
.inputContainer input {
|
||||
display: inline-block;
|
||||
margin: 0.3rem
|
||||
}
|
|
@ -2,7 +2,7 @@ use super::super::user::rss_user::User;
|
|||
use crate::schema::feed;
|
||||
use diesel::{Associations, Identifiable, Queryable};
|
||||
|
||||
#[derive(Queryable, Identifiable, Associations)]
|
||||
#[derive(Clone, Queryable, Identifiable, Associations)]
|
||||
#[diesel(belongs_to(User))]
|
||||
#[diesel(table_name=feed)]
|
||||
pub struct Feed {
|
||||
|
|
|
@ -6,11 +6,11 @@ pub struct Article {
|
|||
pub content: String,
|
||||
}
|
||||
|
||||
impl Article {
|
||||
pub fn new(title: &str, content: &str) -> Article {
|
||||
Article {
|
||||
title: title.to_string(),
|
||||
content: content.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl Article {
|
||||
// pub fn new(title: &str, content: &str) -> Article {
|
||||
// Article {
|
||||
// title: title.to_string(),
|
||||
// content: content.to_string(),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -1,12 +1,71 @@
|
|||
use actix_web::{HttpRequest, Responder};
|
||||
use super::feeds;
|
||||
use crate::{database::establish_connection, models::feed::rss_feed::Feed, schema::feed};
|
||||
use actix_web::{HttpRequest, HttpResponse, Responder};
|
||||
use diesel::prelude::*;
|
||||
|
||||
use crate::{database::establish_connection, schema::feed};
|
||||
|
||||
use super::structs::feed::Feed;
|
||||
use futures::StreamExt;
|
||||
|
||||
pub async fn sync(req: HttpRequest) -> impl Responder {
|
||||
let mut connection: diesel::PgConnection = establish_connection();
|
||||
|
||||
let users = feed::table.load::<Feed>(&mut connection).unwrap();
|
||||
let feed: Vec<Feed> = feed::table.load::<Feed>(&mut connection).unwrap();
|
||||
|
||||
// Create an asynchronous stream of Feed items
|
||||
let feed_stream = futures::stream::iter(feed.clone().into_iter()).map(|feed| {
|
||||
// Asynchronously fetch the feed_list for each feed
|
||||
async move {
|
||||
let feed_list = feeds::get_feed(&feed.url).await.unwrap();
|
||||
// Process feed_list here
|
||||
}
|
||||
});
|
||||
|
||||
// Execute the asynchronous stream
|
||||
tokio::spawn(feed_stream.for_each(|_| async {}));
|
||||
|
||||
HttpResponse::Ok()
|
||||
}
|
||||
// pub async fn sync(req: HttpRequest) -> impl Responder {
|
||||
// let request = req.clone();
|
||||
// let mut connection: diesel::PgConnection = establish_connection();
|
||||
//
|
||||
// let feed: Vec<Feed> = feed::table.load::<Feed>(&mut connection).unwrap();
|
||||
|
||||
// let feed = feeds::get_feed("https://www.heise.de/rss/heise-Rubrik-Wissen.rdf").await.unwrap();
|
||||
|
||||
// let feed_title: String = feed.title.clone();
|
||||
// let feed_items: Vec<Article> = feed
|
||||
// .into_items()
|
||||
// .into_iter()
|
||||
// .map(|item| {
|
||||
// let title = item.title.unwrap();
|
||||
// let frag = Html::parse_fragment(&item.content.unwrap());
|
||||
// let mut content = "".to_string();
|
||||
// let frag_clone = frag.clone();
|
||||
// frag.tree.into_iter().for_each(|node| {
|
||||
// let selector_img = Selector::parse("img").unwrap();
|
||||
//
|
||||
// for element in frag_clone.select(&selector_img) {
|
||||
// if !content.starts_with("<img") {
|
||||
// content.push_str(&element.html());
|
||||
// content.push_str("<br>")
|
||||
// }
|
||||
// }
|
||||
// if let scraper::node::Node::Text(text) = node {
|
||||
// content.push_str(&text.text);
|
||||
// }
|
||||
// });
|
||||
// Article { title, content }
|
||||
// })
|
||||
// .collect();
|
||||
|
||||
// let feed_stream = stream::iter(feed.iter().cloned()).map(|feed: Feed| {
|
||||
// let feed_list = feeds::get_feed(&feed.url).await.unwrap();
|
||||
// // Process feed_list here
|
||||
// });
|
||||
//
|
||||
// tokio::spawn(feed_stream.for_each(|_| async {}));
|
||||
// // let feed_list = feeds::get_feed(&feed.url).await.unwrap();
|
||||
// // feed.iter().for_each(|feed: &Feed| {
|
||||
// // });
|
||||
//
|
||||
// HttpResponse::Ok()
|
||||
// }
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn read_file(file_path: &str) -> String {
|
||||
let data: String = fs::read_to_string(file_path)
|
||||
.expect(format!("Unable to read file {}", file_path).as_str());
|
||||
return data;
|
||||
}
|
||||
|
||||
pub fn add_component(component_tag: String, html_data: String) -> String {
|
||||
let css_tag: String = component_tag.to_uppercase() + &String::from("_CSS");
|
||||
let html_tag: String = component_tag.to_uppercase() + &String::from("_HTML");
|
||||
let css_path = String::from("./templates/components/")
|
||||
+ &component_tag.to_lowercase()
|
||||
+ &String::from(".css");
|
||||
let css_loaded = read_file(&css_path);
|
||||
let html_path = String::from("./templates/components/")
|
||||
+ &component_tag.to_lowercase()
|
||||
+ &String::from(".html");
|
||||
let html_loaded = read_file(&html_path);
|
||||
let html_data = html_data.replace(html_tag.as_str(), &html_loaded);
|
||||
let html_data = html_data.replace(css_tag.as_str(),&css_loaded);
|
||||
return html_data
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
use super::content_loader::read_file;
|
||||
use actix_web::HttpResponse;
|
||||
|
||||
pub async fn login() -> HttpResponse {
|
||||
let mut html_data = read_file(&String::from("./templates/login.html"));
|
||||
let javascript_data = read_file(&String::from("./javascript/login.js"));
|
||||
let css_data = read_file(&String::from("./css/main.css"));
|
||||
let base_css_data = read_file(&String::from("./css/base.css"));
|
||||
|
||||
html_data = html_data.replace("{{JAVASCRIPT}}", &javascript_data);
|
||||
html_data = html_data.replace("{{CSS}}", &css_data);
|
||||
html_data = html_data.replace("{{BASE_CSS}}", &base_css_data);
|
||||
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(html_data)
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
use actix_web::HttpResponse;
|
||||
|
||||
pub async fn logout() -> HttpResponse {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(
|
||||
"<html>\
|
||||
<script>\
|
||||
localStorage.removeItem('user-token'); \
|
||||
window.location.replace(document.location.origin);\
|
||||
</script>\
|
||||
</html>
|
||||
",
|
||||
)
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
use actix_web::web;
|
||||
mod content_loader;
|
||||
mod login;
|
||||
mod logout;
|
||||
mod reader;
|
||||
use super::path::Path;
|
||||
|
||||
/// This function adds the app views to the web server serving HTML.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * (&mut web::ServiceConfig): reference to the app for configuration
|
||||
///
|
||||
/// # Returns
|
||||
/// None
|
||||
pub fn app_factory(app: &mut web::ServiceConfig) {
|
||||
// define the path struct
|
||||
let base_path: Path = Path {
|
||||
prefix: String::from("/"),
|
||||
backend: false,
|
||||
};
|
||||
// define the routes for the app
|
||||
|
||||
app.route(
|
||||
&base_path.define(String::from("")),
|
||||
web::get().to(reader::reader),
|
||||
);
|
||||
app.route(
|
||||
&base_path.define(String::from("login")),
|
||||
web::get().to(login::login),
|
||||
);
|
||||
app.route(
|
||||
&base_path.define(String::from("logout")),
|
||||
web::get().to(logout::logout),
|
||||
);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
use super::content_loader::read_file;
|
||||
use actix_web::HttpResponse;
|
||||
|
||||
pub async fn reader() -> HttpResponse {
|
||||
let mut html_data = read_file("./templates/reader.html");
|
||||
let javascript = read_file("./javascript/main.js");
|
||||
let css = read_file("./css/main.css");
|
||||
let base_css = read_file("./css/base.css");
|
||||
|
||||
html_data = html_data.replace("JAVASCRIPT", &javascript);
|
||||
html_data = html_data.replace("CSS", &css);
|
||||
html_data = html_data.replace("BASE_CSS", &base_css);
|
||||
// html_data = add_component(String::from("header"), html_data);
|
||||
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html; charset=utf-8")
|
||||
.body(html_data)
|
||||
}
|
|
@ -1,14 +1,12 @@
|
|||
use actix_web::web;
|
||||
|
||||
use crate::reader;
|
||||
mod app;
|
||||
mod auth;
|
||||
pub(crate) mod path;
|
||||
mod users;
|
||||
|
||||
pub fn views_factory(app: &mut web::ServiceConfig) {
|
||||
auth::auth_factory(app);
|
||||
app::app_factory(app);
|
||||
users::user_factory(app);
|
||||
reader::feed_factory(app);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue