mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
feat(blog::components::check_update) add apply.rs
This commit is contained in:
7 files changed
+61
-18
No files matched your search
@@ -8,7 +8,7 @@ use crate::{
|
|||||||
utils::front_matter::{parse_front_matter, split_md_front_matter},
|
utils::front_matter::{parse_front_matter, split_md_front_matter},
|
||||||
};
|
};
|
||||||
|
|
||||||
use base64::{engine::general_purpose, Engine};
|
use base64::{Engine, engine::general_purpose};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|||||||
@@ -7,28 +7,29 @@ use axum::{
|
|||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
const GET_POST_BY_I64_ID: &str = include_str!("get_post_by_i64_id.sql");
|
const GET_POST_BY_UUID: &str = include_str!("get_post_by_uuid.sql");
|
||||||
const GET_POST_BY_STR_ID: &str = include_str!("get_post_by_str_id.sql");
|
const GET_POST_BY_STR_ID: &str = include_str!("get_post_by_str_id.sql");
|
||||||
|
|
||||||
pub async fn handler(
|
pub async fn handler(
|
||||||
State(db_connection): State<PgPool>,
|
State(db_connection): State<PgPool>,
|
||||||
Path(identifier): Path<String>,
|
Path(identifier): Path<String>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
if let Ok(id) = identifier.parse::<i64>() {
|
if let Ok(id) = identifier.parse::<Uuid>() {
|
||||||
select_post_with_i64_id(&db_connection, id).await
|
select_post_by_uuid(&db_connection, id).await
|
||||||
} else {
|
} else {
|
||||||
select_post_with_str_id(&db_connection, &identifier).await
|
select_post_by_str_id(&db_connection, &identifier).await
|
||||||
};
|
};
|
||||||
Json::from(json!({"res": "ok"})).into_response()
|
Json::from(json!({"res": "ok"})).into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn select_post_with_i64_id(db: &PgPool, id: i64) {
|
async fn select_post_by_uuid(db: &PgPool, id: Uuid) {
|
||||||
dev_consume!(db, id);
|
dev_consume!(db, id);
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn select_post_with_str_id(db: &PgPool, id: &str) {
|
async fn select_post_by_str_id(db: &PgPool, id: &str) {
|
||||||
dev_consume!(db, id);
|
dev_consume!(db, id);
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
use crate::modules::blog::components::check_update::changes::{
|
||||||
|
Change, Create, Delete, Move, Update,
|
||||||
|
};
|
||||||
|
|
||||||
|
use futures::{
|
||||||
|
FutureExt,
|
||||||
|
future::{BoxFuture, join_all},
|
||||||
|
};
|
||||||
|
use sqlx::PgPool;
|
||||||
|
|
||||||
|
pub async fn apply_deltas(db_conn: &PgPool, changes: Vec<Change>) {
|
||||||
|
let handlers = changes
|
||||||
|
.into_iter()
|
||||||
|
.map(|change| match change {
|
||||||
|
Change::Delete(del) => handle_delete(db_conn, del).boxed(),
|
||||||
|
Change::Move(mv) => handle_move(db_conn, mv).boxed(),
|
||||||
|
Change::Update(update) => handle_update(db_conn, update).boxed(),
|
||||||
|
Change::Create(create) => handle_create(db_conn, create).boxed(),
|
||||||
|
})
|
||||||
|
.collect::<Vec<BoxFuture<'_, ()>>>();
|
||||||
|
|
||||||
|
join_all(handlers).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_delete(db: &PgPool, del: Delete) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_move(db: &PgPool, mv: Move) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_update(db: &PgPool, update: Update) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_create(db: &PgPool, create: Create) {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
@@ -11,11 +11,14 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use macros::panic_with_log;
|
use macros::panic_with_log;
|
||||||
|
|
||||||
|
use crate::modules::blog::components::check_update::apply::apply_deltas;
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
use tracing::{trace, warn, Level};
|
use tracing::log::error;
|
||||||
|
use tracing::{Level, trace, warn};
|
||||||
|
|
||||||
// mod error;
|
// mod error;
|
||||||
// mod index;
|
// mod index;
|
||||||
|
mod apply;
|
||||||
mod changes;
|
mod changes;
|
||||||
mod error;
|
mod error;
|
||||||
mod pull;
|
mod pull;
|
||||||
@@ -85,7 +88,10 @@ async fn workflow(args: Arc<Args>) {
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(updates) => updates,
|
Ok(updates) => updates,
|
||||||
Err(_) => return,
|
Err(e) => {
|
||||||
|
error!("delta parsing error: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if deltas.is_empty() {
|
if deltas.is_empty() {
|
||||||
@@ -93,5 +99,5 @@ async fn workflow(args: Arc<Args>) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: load delta to database
|
apply_deltas(&args.db_connection, deltas).await;
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, path::PathBuf};
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
modules::blog::components::check_update::{
|
modules::blog::components::check_update::{
|
||||||
changes::{Change, Create, Delete, Update},
|
changes::{Change, Create, CreateDelete2UpdateSlot, Delete, Update},
|
||||||
error::Error,
|
error::Error,
|
||||||
},
|
},
|
||||||
utils::{git, git::FileDelta},
|
utils::{git, git::FileDelta},
|
||||||
};
|
};
|
||||||
use markdown::MdFile;
|
use markdown::MdFile;
|
||||||
|
|
||||||
use crate::modules::blog::components::check_update::changes::CreateDelete2UpdateSlot;
|
|
||||||
use git2::{Delta, Repository};
|
use git2::{Delta, Repository};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::modules::blog::components::check_update;
|
|||||||
use crate::scheduler::tasks::async_basic::AsyncBasic;
|
use crate::scheduler::tasks::async_basic::AsyncBasic;
|
||||||
use crate::{
|
use crate::{
|
||||||
modules::{
|
modules::{
|
||||||
|
Module,
|
||||||
blog::{
|
blog::{
|
||||||
api::{
|
api::{
|
||||||
get_page_count,
|
get_page_count,
|
||||||
@@ -13,12 +14,11 @@ use crate::{
|
|||||||
},
|
},
|
||||||
// cron::check_update,
|
// cron::check_update,
|
||||||
},
|
},
|
||||||
Module,
|
|
||||||
},
|
},
|
||||||
scheduler::tasks::CronTask,
|
scheduler::tasks::CronTask,
|
||||||
};
|
};
|
||||||
|
|
||||||
use axum::{routing::get, Router};
|
use axum::{Router, routing::get};
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
const MOUNT_POINT: &str = "/blog";
|
const MOUNT_POINT: &str = "/blog";
|
||||||
|
|||||||
@@ -3,12 +3,11 @@
|
|||||||
/// https://github.com/rust-lang/git2-rs/commit/f3b87baed1e33d6c2d94fe1fa6aa6503a071d837
|
/// https://github.com/rust-lang/git2-rs/commit/f3b87baed1e33d6c2d94fe1fa6aa6503a071d837
|
||||||
///
|
///
|
||||||
use git2::{
|
use git2::{
|
||||||
build, AnnotatedCommit, AutotagOption, Delta, FetchOptions, Reference, Remote, Repository,
|
AnnotatedCommit, AutotagOption, Delta, FetchOptions, Reference, Remote, Repository, build,
|
||||||
};
|
};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub struct FileDelta {
|
pub struct FileDelta {
|
||||||
pub old_path: Option<PathBuf>,
|
pub old_path: Option<PathBuf>,
|
||||||
|
|||||||
Reference in new issue
Block a user