feat: report
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use crate::api::post::ps2outputs;
|
||||
use crate::api::{APIError, CurrentUser, PolicyError::*, API, UGC};
|
||||
use crate::api::{CurrentUser, JsonAPI, PolicyError::*, UGC};
|
||||
use crate::db_conn::Db;
|
||||
use crate::models::*;
|
||||
use crate::rds_conn::RdsConn;
|
||||
use crate::rds_models::*;
|
||||
use rocket::form::Form;
|
||||
use rocket::serde::json::{json, Value};
|
||||
use rocket::serde::json::json;
|
||||
|
||||
#[derive(FromForm)]
|
||||
pub struct AttentionInput {
|
||||
@@ -20,13 +20,15 @@ pub async fn attention_post(
|
||||
user: CurrentUser,
|
||||
db: Db,
|
||||
rconn: RdsConn,
|
||||
) -> API<Value> {
|
||||
user.id.ok_or_else(|| APIError::PcError(NotAllowed))?;
|
||||
) -> JsonAPI {
|
||||
// 临时用户不允许手动关注
|
||||
user.id.ok_or_else(|| NotAllowed)?;
|
||||
|
||||
let mut p = Post::get(&db, &rconn, ai.pid).await?;
|
||||
p.check_permission(&user, "r")?;
|
||||
let mut att = Attention::init(&user.namehash, &rconn);
|
||||
let switch_to = ai.switch == 1;
|
||||
let mut delta: i32 = 0;
|
||||
let delta: i32;
|
||||
if att.has(ai.pid).await? != switch_to {
|
||||
if switch_to {
|
||||
att.add(ai.pid).await?;
|
||||
@@ -37,20 +39,23 @@ pub async fn attention_post(
|
||||
}
|
||||
p.change_n_attentions(&db, delta).await?;
|
||||
p.change_hot_score(&db, delta * 2).await?;
|
||||
if switch_to && user.is_admin {
|
||||
p.set_is_reported(&db, false).await?;
|
||||
}
|
||||
p.refresh_cache(&rconn, false).await;
|
||||
}
|
||||
|
||||
Ok(json!({
|
||||
"code": 0,
|
||||
"attention": ai.switch == 1,
|
||||
"n_attentions": p.n_attentions + delta,
|
||||
"n_attentions": p.n_attentions,
|
||||
// for old version frontend
|
||||
"likenum": p.n_attentions + delta,
|
||||
"likenum": p.n_attentions,
|
||||
}))
|
||||
}
|
||||
|
||||
#[get("/getattention")]
|
||||
pub async fn get_attention(user: CurrentUser, db: Db, rconn: RdsConn) -> API<Value> {
|
||||
pub async fn get_attention(user: CurrentUser, db: Db, rconn: RdsConn) -> JsonAPI {
|
||||
let ids = Attention::init(&user.namehash, &rconn).all().await?;
|
||||
let ps = Post::get_multi(&db, &rconn, &ids).await?;
|
||||
let ps_data = ps2outputs(&ps, &user, &db, &rconn).await;
|
||||
|
||||
Reference in New Issue
Block a user