Skip to content

Commit

Permalink
优化更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Jul 14, 2023
1 parent 2814a82 commit c03ca2a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion assert/templates/blog/nako/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% if art.cover %}
<header>
<div class="lead-image">
<img src="{{ art.cover }}" alt="{{ art.title }}" class="img-responsive">
<img src="{{ art.cover | safe }}" alt="{{ art.title }}" class="img-responsive">
</div>
</header>
{% endif %}
Expand Down
9 changes: 5 additions & 4 deletions src/app/controller/blog/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ pub async fn index(
let art_tags = tags_string.split(",").collect::<Vec<&str>>();
ctx.insert("art_tags", &art_tags);
}


// 添加阅读量
art::ArtModel::view_add(db, art.id, 1).await.unwrap_or_default();

// 右侧数据
let hot_arts = art::ArtModel::find_one_year_hot(db, 6).await.unwrap_or_default();
let cates = cate::CateModel::find_open_cate(db).await.unwrap_or_default();
let tags = tag::TagModel::find_open_tags(db, 6).await.unwrap_or_default();
Expand All @@ -74,9 +78,6 @@ pub async fn index(
ctx.insert("cates", &cates);
ctx.insert("tags", &tags);

// 添加阅读量
art::ArtModel::view_add(db, art.id, 1).await.unwrap_or_default();

let mut tpl = cate_data.view_tpl.as_str();
if tpl == "" {
tpl = "view.html";
Expand Down
10 changes: 2 additions & 8 deletions src/app/middleware/admin_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,8 @@ pub async fn auth(

let session = req.get_session();

let mut check = false;

let login_id = session.get::<u32>("login_id").unwrap_or_default().unwrap_or_default();
if login_id > 0 {
check = true;
}

if !check {
if login_id <= 0 {
let message = "请先登陆";

let url: String = utils::url_for_static(req.request().clone(), "admin.auth-login");
Expand All @@ -72,7 +66,7 @@ pub async fn auth(

return Ok(req.into_response(res_body_data));
}
}
}

return to_next(req, next).await;
}
13 changes: 6 additions & 7 deletions src/boot/app.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
use actix_session::{
SessionMiddleware,
storage::RedisSessionStore,
config::PersistentSession,
};
use actix_web::{
web,
App,
Expand All @@ -23,6 +18,11 @@ use actix_web::{
},
HttpResponse,
};
use actix_session::{
SessionMiddleware,
storage::RedisSessionStore,
config::PersistentSession,
};
use actix_files::Files as Fs;

use tera::Tera;
Expand All @@ -38,7 +38,6 @@ use crate::nako::{
log as nako_log,
global::AppState,
};

use crate::boot::{
error,
};
Expand All @@ -47,7 +46,7 @@ use crate::route::{
blog,
};

/// app 运行
// app 运行
pub async fn start() -> std::io::Result<()> {
let rust_log = config::section::<String>("app", "rust_log", "error".to_string());
std::env::set_var("RUST_LOG", rust_log.as_str());
Expand Down
18 changes: 9 additions & 9 deletions src/route/blog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ pub fn route(cfg: &mut web::ServiceConfig) {
.name("blog.tag-index"),
)
)
.service(
// 页面
web::scope("/p")
.service(
web::resource("/{slug}")
.route(web::get().to(page::index))
.name("blog.page-index"),
)
)
.service(
// 评论
web::scope("/guestbook")
Expand All @@ -88,6 +79,15 @@ pub fn route(cfg: &mut web::ServiceConfig) {
.name("blog.guestbook-create"),
),
)
.service(
// 页面
web::scope("")
.service(
web::resource("/{slug}")
.route(web::get().to(page::index))
.name("blog.page-index"),
)
)
.default_service(web::to(error::index))
.wrap(from_fn(blog_settings::settings))
.wrap(from_fn(blog_open::check)),
Expand Down

0 comments on commit c03ca2a

Please sign in to comment.