I THINK THIS IS IT
This commit is contained in:
		
							parent
							
								
									6b7fd18171
								
							
						
					
					
						commit
						953eb9dabb
					
				| 
						 | 
				
			
			@ -1,4 +1,3 @@
 | 
			
		|||
use serde_json::Value;
 | 
			
		||||
use uuid::Uuid;
 | 
			
		||||
use sqlx::Row;
 | 
			
		||||
use crate::database::Database;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,17 +2,16 @@ use std::{borrow::BorrowMut, sync::Mutex};
 | 
			
		|||
 | 
			
		||||
use actix_web::{web::Data, HttpResponse, HttpResponseBuilder, Result};
 | 
			
		||||
 | 
			
		||||
use crate::database::{models::{self, tokens::Token}, Database};
 | 
			
		||||
use crate::database::{models, Database};
 | 
			
		||||
 | 
			
		||||
use super::types::ReleaseEvent;
 | 
			
		||||
 | 
			
		||||
pub async fn release_handler(db: Data<Mutex<Database>>, token: Token, body: ReleaseEvent, raw_body: String) -> Result<HttpResponseBuilder> {
 | 
			
		||||
pub async fn release_handler(db: Data<Mutex<Database>>, body: ReleaseEvent, raw_body: String) -> Result<HttpResponseBuilder> {
 | 
			
		||||
 | 
			
		||||
    if body.action != "released" {
 | 
			
		||||
        return Ok(HttpResponse::Ok());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    let title = format!("(New release {}:{}) {}", body.repository.full_name, body.release.tag_name, body.release.name.unwrap_or("No title provided".into()));
 | 
			
		||||
    let origin_url = body.repository.html_url.clone();
 | 
			
		||||
    let descr = body.release.body.unwrap_or("No body provided".into());
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,9 +3,9 @@ pub mod events;
 | 
			
		|||
 | 
			
		||||
use std::{borrow::BorrowMut, sync::Mutex};
 | 
			
		||||
 | 
			
		||||
use actix_web::{http::header, post, web::{self, Bytes, Data}, HttpRequest, HttpResponse, Responder, Result, Scope};
 | 
			
		||||
use actix_web::{web::{self, Bytes, Data}, HttpRequest, HttpResponse, Responder, Result};
 | 
			
		||||
 | 
			
		||||
use crate::database::{models, Database};
 | 
			
		||||
use crate::database::{models::{self, Permissions}, Database};
 | 
			
		||||
 | 
			
		||||
pub async fn handler(req: HttpRequest, token: web::Path<String>, body: Bytes, db: Data<Mutex<Database>>) -> Result<impl Responder> {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -23,6 +23,10 @@ pub async fn handler(req: HttpRequest, token: web::Path<String>, body: Bytes, db
 | 
			
		|||
        return Ok(HttpResponse::Unauthorized());
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    if !token.permissions.contains(Permissions::MAKE_POST) {
 | 
			
		||||
        return Ok(HttpResponse::Unauthorized());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let Some(event_type) = req.headers().get("X-GitHub-Event") else {
 | 
			
		||||
        log::debug!("No X-GitHub-Event header");
 | 
			
		||||
        return Ok(HttpResponse::BadRequest());
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +52,7 @@ pub async fn handler(req: HttpRequest, token: web::Path<String>, body: Bytes, db
 | 
			
		|||
    };
 | 
			
		||||
 | 
			
		||||
    match event {
 | 
			
		||||
        types::Event::Release(body) => events::release_handler(db, token, body, json).await,
 | 
			
		||||
        types::Event::Release(body) => events::release_handler(db, body, json).await,
 | 
			
		||||
        _ => {
 | 
			
		||||
            // dbg!(json);
 | 
			
		||||
            Ok(HttpResponse::Ok())
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,20 +8,20 @@ use askama::Template;
 | 
			
		|||
 | 
			
		||||
use crate::{database::Database, web::templates::IndexTemplate};
 | 
			
		||||
 | 
			
		||||
use super::templates::IndexTemplatePost;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// NOTE: Not usefull to have database here but just so u know how
 | 
			
		||||
pub async fn index(_: Data<Mutex<Database>>) -> Result<impl Responder> {
 | 
			
		||||
pub async fn index(db: Data<Mutex<Database>>) -> Result<impl Responder> {
 | 
			
		||||
 | 
			
		||||
    let posts = match crate::database::models::posts::Post::get_last_n(&mut db.lock().unwrap(), 10).await {
 | 
			
		||||
        Ok(p) => p,
 | 
			
		||||
        _ => {
 | 
			
		||||
            vec![]
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let html = IndexTemplate {
 | 
			
		||||
        posts: vec![
 | 
			
		||||
            IndexTemplatePost {
 | 
			
		||||
                image: String::from("/static/assets/uwu.jpg"),
 | 
			
		||||
                title: String::from("Cutie"),
 | 
			
		||||
                description: String::from("Yes you are ;3"),
 | 
			
		||||
                url: String::from("https://djc.github.io/askama/template_expansion.html")
 | 
			
		||||
            }
 | 
			
		||||
        ],
 | 
			
		||||
        posts,
 | 
			
		||||
        title: String::from("Very cool mcoranges website :3"),
 | 
			
		||||
    }.render().expect("Failed to render index.html");
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,16 +1,12 @@
 | 
			
		|||
use askama::Template;
 | 
			
		||||
 | 
			
		||||
use crate::database::models::posts::Post;
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Clone, Template)]
 | 
			
		||||
#[template(path = "index.html")]
 | 
			
		||||
pub struct IndexTemplate{
 | 
			
		||||
    pub title: String,
 | 
			
		||||
    pub posts: Vec<IndexTemplatePost>
 | 
			
		||||
    pub posts: Vec<Post>
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Clone)]
 | 
			
		||||
pub struct IndexTemplatePost {
 | 
			
		||||
    pub image: String,
 | 
			
		||||
    pub title: String,
 | 
			
		||||
    pub description: String,
 | 
			
		||||
    pub url: String
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,10 +23,10 @@
 | 
			
		|||
                <div class="box" id="content-pane">
 | 
			
		||||
                    {% for post in posts %}
 | 
			
		||||
                        <div class="post">
 | 
			
		||||
                            <a href="{{post.url}}"><img src="{{post.image}}" alt="post img"></a>
 | 
			
		||||
                            <a href="{{post.origin_url}}"><img src="{{post.img_url}}" alt="post img"></a>
 | 
			
		||||
                            <span>
 | 
			
		||||
                                <a href="{{post.url}}"><h3>{{post.title}}</h3></a>
 | 
			
		||||
                                <p>{{post.description}}</p>
 | 
			
		||||
                                <a href="{{post.origin_url}}"><h3>{{post.title}}</h3></a>
 | 
			
		||||
                                <p>{{post.descr}}</p>
 | 
			
		||||
                            </span>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    {% endfor %}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user