rate limit
Some checks are pending
Docker Build and Push / build (push) Waiting to run

This commit is contained in:
tsuki 2025-08-13 22:00:56 +08:00
parent 1d0e96ead4
commit fb3706ff38
2 changed files with 13 additions and 29 deletions

View File

@ -94,19 +94,19 @@ pub async fn create_router(
Router::new() Router::new()
.route("/", get(graphql_playground)) .route("/", get(graphql_playground))
.route("/graphql", get(graphql_playground).post(graphql_handler)) .route("/graphql", get(graphql_playground).post(graphql_handler))
// .route_layer( .route_layer(
// RateLimitLayer::<RealIp>::builder() RateLimitLayer::<RealIp>::builder()
// .with_route( .with_route(
// (Method::GET, "/graphql"), (Method::GET, "/graphql"),
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()), Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
// ) )
// .with_route( .with_route(
// (Method::POST, "/graphql"), (Method::POST, "/graphql"),
// Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()), Quota::new(Duration::from_millis(100), NonZero::new(10).unwrap()),
// ) )
// .with_gc_interval(1000) .with_gc_interval(1000)
// .default_handle_error(), .default_handle_error(),
// ) )
.route_service("/ws", GraphQLSubscription::new(schema)) .route_service("/ws", GraphQLSubscription::new(schema))
.layer(CorsLayer::permissive()) .layer(CorsLayer::permissive())
.merge(router) .merge(router)

View File

@ -1246,8 +1246,6 @@ impl QueryRoot {
// ==================== Blog 相关查询 ==================== // ==================== Blog 相关查询 ====================
/// 获取博客文章列表
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
async fn blogs( async fn blogs(
&self, &self,
ctx: &Context<'_>, ctx: &Context<'_>,
@ -1263,7 +1261,6 @@ impl QueryRoot {
} }
/// 根据ID获取博客文章 /// 根据ID获取博客文章
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
async fn blog(&self, ctx: &Context<'_>, id: Uuid) -> Result<Blog> { async fn blog(&self, ctx: &Context<'_>, id: Uuid) -> Result<Blog> {
let blog_service = ctx.data::<BlogService>()?; let blog_service = ctx.data::<BlogService>()?;
blog_service blog_service
@ -1273,7 +1270,6 @@ impl QueryRoot {
} }
/// 根据slug获取博客文章 /// 根据slug获取博客文章
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
async fn blog_by_slug(&self, ctx: &Context<'_>, slug: String) -> Result<Blog> { async fn blog_by_slug(&self, ctx: &Context<'_>, slug: String) -> Result<Blog> {
let blog_service = ctx.data::<BlogService>()?; let blog_service = ctx.data::<BlogService>()?;
blog_service blog_service
@ -1282,8 +1278,6 @@ impl QueryRoot {
.map_err(|e| GraphQLError::new(e.to_string())) .map_err(|e| GraphQLError::new(e.to_string()))
} }
/// 获取博客文章详情(包含分类和标签)
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
async fn blog_detail(&self, ctx: &Context<'_>, id: Uuid) -> Result<BlogDetail> { async fn blog_detail(&self, ctx: &Context<'_>, id: Uuid) -> Result<BlogDetail> {
let blog_service = ctx.data::<BlogService>()?; let blog_service = ctx.data::<BlogService>()?;
blog_service blog_service
@ -1292,8 +1286,6 @@ impl QueryRoot {
.map_err(|e| GraphQLError::new(e.to_string())) .map_err(|e| GraphQLError::new(e.to_string()))
} }
/// 获取博客统计信息
#[graphql(guard = "RequireReadPermission::new(\"blogs\")")]
async fn blog_stats(&self, ctx: &Context<'_>) -> Result<BlogStats> { async fn blog_stats(&self, ctx: &Context<'_>) -> Result<BlogStats> {
let blog_service = ctx.data::<BlogService>()?; let blog_service = ctx.data::<BlogService>()?;
blog_service blog_service
@ -1302,8 +1294,6 @@ impl QueryRoot {
.map_err(|e| GraphQLError::new(e.to_string())) .map_err(|e| GraphQLError::new(e.to_string()))
} }
/// 获取博客分类列表
#[graphql(guard = "RequireReadPermission::new(\"blog_categories\")")]
async fn blog_categories( async fn blog_categories(
&self, &self,
ctx: &Context<'_>, ctx: &Context<'_>,
@ -1316,8 +1306,6 @@ impl QueryRoot {
.map_err(|e| GraphQLError::new(e.to_string())) .map_err(|e| GraphQLError::new(e.to_string()))
} }
/// 根据ID获取博客分类
#[graphql(guard = "RequireReadPermission::new(\"blog_categories\")")]
async fn blog_category(&self, ctx: &Context<'_>, id: Uuid) -> Result<BlogCategory> { async fn blog_category(&self, ctx: &Context<'_>, id: Uuid) -> Result<BlogCategory> {
let blog_service = ctx.data::<BlogService>()?; let blog_service = ctx.data::<BlogService>()?;
blog_service blog_service
@ -1326,8 +1314,6 @@ impl QueryRoot {
.map_err(|e| GraphQLError::new(e.to_string())) .map_err(|e| GraphQLError::new(e.to_string()))
} }
/// 获取博客标签列表
#[graphql(guard = "RequireReadPermission::new(\"blog_tags\")")]
async fn blog_tags( async fn blog_tags(
&self, &self,
ctx: &Context<'_>, ctx: &Context<'_>,
@ -1340,8 +1326,6 @@ impl QueryRoot {
.map_err(|e| GraphQLError::new(e.to_string())) .map_err(|e| GraphQLError::new(e.to_string()))
} }
/// 根据ID获取博客标签
#[graphql(guard = "RequireReadPermission::new(\"blog_tags\")")]
async fn blog_tag(&self, ctx: &Context<'_>, id: Uuid) -> Result<BlogTag> { async fn blog_tag(&self, ctx: &Context<'_>, id: Uuid) -> Result<BlogTag> {
let blog_service = ctx.data::<BlogService>()?; let blog_service = ctx.data::<BlogService>()?;
blog_service blog_service