Skip to content

Commit

Permalink
fix page view
Browse files Browse the repository at this point in the history
  • Loading branch information
holmofy committed Sep 26, 2024
1 parent 1b94c9f commit 33c02ce
Show file tree
Hide file tree
Showing 7 changed files with 885 additions and 1,192 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raline/api",
"version": "0.0.6",
"version": "0.0.7",
"description": "Client API for raline comment system",
"keywords": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/articleCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface GetArticleCounterOptions extends BaseAPIOptions {
}

export interface CounterFields {
time?: number;
times?: number;
reaction0?: number;
reaction1?: number;
reaction2?: number;
Expand Down
2,030 changes: 854 additions & 1,176 deletions packages/client/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/client/src/pageview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const renderVisitorCount = (
countElements: HTMLElement[],
): void => {
countElements.forEach((element, index) => {
const count = counts[index].time;
const count = counts[index].times;

if (typeof count !== 'number') {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/dto/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ pub struct ListCommentQuery {
pub offset: i64,
}

#[serde_as]
#[derive(Debug, Validate, Deserialize)]
pub struct RecentCommentQuery {
#[validate(range(max = 100, message = "查询数据过多"))]
#[serde_as(as = "DisplayFromStr")]
pub count: u16,
}

Expand Down
16 changes: 14 additions & 2 deletions src/http/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::config::comrak::ComrakConfig;
use crate::config::RalineConfig;
use crate::dto::comment::{
AddCommentReq, AdminCommentQuery, AdminListResp, CommentQueryResp, CommentResp,
CountCommentQuery, ListCommentQuery, ListResp, Owner,
CountCommentQuery, ListCommentQuery, ListResp, Owner, RecentCommentQuery,
};
use crate::model::sea_orm_active_enums::UserType;
use crate::model::{prelude::*, users};
Expand Down Expand Up @@ -53,10 +53,22 @@ async fn get_comment(
CommentQueryReq::Admin(q) => get_admin_comment_list(&q, &db, &claims, &config, &comrak)
.await
.map(|r| Json(r.into())),
_ => todo!(),
CommentQueryReq::Recent(q) => get_recent_comment_list(&q, &db, &claims, &config, &comrak)
.await
.map(|r| Json(r.into())),
}
}

async fn get_recent_comment_list(
q: &RecentCommentQuery,
db: &DbConn,
optional_claims: &OptionalClaims,
config: &RalineConfig,
comrak: &ComrakConfig,
) -> Result<impl IntoResponse> {
Ok("")
}

async fn get_admin_comment_list(
q: &AdminCommentQuery,
db: &DbConn,
Expand Down
23 changes: 12 additions & 11 deletions src/http/view_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::model::prelude::ViewCounter;
use crate::{dto::view_counter::ViewCountQuery, model::view_counter};
use anyhow::Context;
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
use serde_json::json;
use spring_sea_orm::DbConn;
use spring_web::{
axum::{response::IntoResponse, Json},
Expand Down Expand Up @@ -58,16 +59,16 @@ async fn post_view_count(
.context("increase view count failed")?;

let count = match req.r#type {
ColumnQueryAs::Times => count.times,
ColumnQueryAs::Reaction0 => count.reaction0,
ColumnQueryAs::Reaction1 => count.reaction1,
ColumnQueryAs::Reaction2 => count.reaction2,
ColumnQueryAs::Reaction3 => count.reaction3,
ColumnQueryAs::Reaction4 => count.reaction4,
ColumnQueryAs::Reaction5 => count.reaction5,
ColumnQueryAs::Reaction6 => count.reaction6,
ColumnQueryAs::Reaction7 => count.reaction7,
ColumnQueryAs::Reaction8 => count.reaction8,
ColumnQueryAs::Times => json!({"times":count.times}),
ColumnQueryAs::Reaction0 => json!({"reaction0":count.reaction0}),
ColumnQueryAs::Reaction1 => json!({"reaction1":count.reaction1}),
ColumnQueryAs::Reaction2 => json!({"reaction2":count.reaction2}),
ColumnQueryAs::Reaction3 => json!({"reaction3":count.reaction3}),
ColumnQueryAs::Reaction4 => json!({"reaction4":count.reaction4}),
ColumnQueryAs::Reaction5 => json!({"reaction5":count.reaction5}),
ColumnQueryAs::Reaction6 => json!({"reaction6":count.reaction6}),
ColumnQueryAs::Reaction7 => json!({"reaction7":count.reaction7}),
ColumnQueryAs::Reaction8 => json!({"reaction8":count.reaction8}),
};
Ok(Json(count))
Ok(Json(vec![count]))
}

0 comments on commit 33c02ce

Please sign in to comment.