Browse Source

use 404 for old api

master
hole-thu 3 years ago
parent
commit
503a8a3b9b
  1. 5
      src/api/comment.rs
  2. 7
      src/api/mod.rs
  3. 8
      src/api/upload.rs
  4. 8
      src/main.rs

5
src/api/comment.rs

@ -112,11 +112,6 @@ pub async fn get_comment(pid: i32, user: CurrentUser, db: Db, rconn: RdsConn) ->
})) }))
} }
#[post("/docomment")]
pub async fn old_add_comment() -> ApiError {
OldApi.into()
}
#[post("/post/<pid>/comment", data = "<ci>")] #[post("/post/<pid>/comment", data = "<ci>")]
pub async fn add_comment( pub async fn add_comment(
pid: i32, pid: i32,

7
src/api/mod.rs

@ -55,6 +55,11 @@ pub fn catch_403_error() -> &'static str {
"可能被封禁了,等下次重置吧" "可能被封禁了,等下次重置吧"
} }
#[catch(404)]
pub fn catch_404_error() -> &'static str {
"请更新前端版本"
}
pub struct CurrentUser { pub struct CurrentUser {
pub id: Option<i32>, // tmp user has no id, only for block pub id: Option<i32>, // tmp user has no id, only for block
namehash: String, namehash: String,
@ -136,7 +141,6 @@ pub enum PolicyError {
InvalidTitle, InvalidTitle,
YouAreTmp, YouAreTmp,
NoReason, NoReason,
OldApi,
UnknownPushEndpoint, UnknownPushEndpoint,
} }
@ -167,7 +171,6 @@ impl<'r> Responder<'r, 'static> for ApiError {
PolicyError::InvalidTitle => "头衔包含不允许的符号", PolicyError::InvalidTitle => "头衔包含不允许的符号",
PolicyError::YouAreTmp => "临时用户只可发布内容和进入单个洞", PolicyError::YouAreTmp => "临时用户只可发布内容和进入单个洞",
PolicyError::NoReason => "未填写理由", PolicyError::NoReason => "未填写理由",
PolicyError::OldApi => "请使用最新版前端地址并检查更新",
PolicyError::UnknownPushEndpoint => "未知的浏览器推送地址", PolicyError::UnknownPushEndpoint => "未知的浏览器推送地址",
} }
}) })

8
src/api/upload.rs

@ -1,14 +1,8 @@
use super::PolicyError::OldApi; use super::{CurrentUser, JsonApi};
use super::{ApiError, CurrentUser, JsonApi};
use rocket::fs::TempFile; use rocket::fs::TempFile;
use rocket::serde::json::json; use rocket::serde::json::json;
use std::env::var; use std::env::var;
#[post("/upload")]
pub async fn ipfs_upload() -> ApiError {
OldApi.into()
}
#[post("/upload", data = "<file>")] #[post("/upload", data = "<file>")]
pub async fn local_upload(_user: CurrentUser, mut file: TempFile<'_>) -> JsonApi { pub async fn local_upload(_user: CurrentUser, mut file: TempFile<'_>) -> JsonApi {
let filename: String = format!( let filename: String = format!(

8
src/main.rs

@ -67,7 +67,6 @@ async fn main() {
"/_api/v1", "/_api/v1",
routes![ routes![
api::comment::get_comment, api::comment::get_comment,
api::comment::old_add_comment,
api::post::get_list, api::post::get_list,
api::post::get_one, api::post::get_one,
api::post::publish_post, api::post::publish_post,
@ -82,7 +81,6 @@ async fn main() {
api::operation::block, api::operation::block,
api::operation::set_auto_block, api::operation::set_auto_block,
api::vote::vote, api::vote::vote,
api::upload::ipfs_upload,
cors::options_handler, cors::options_handler,
], ],
) )
@ -107,7 +105,11 @@ async fn main() {
) )
.register( .register(
"/_api", "/_api",
catchers![api::catch_401_error, api::catch_403_error,], catchers![
api::catch_401_error,
api::catch_403_error,
api::catch_404_error
],
) )
.manage(RandomHasher::get_random_one()) .manage(RandomHasher::get_random_one())
.manage(rmc) .manage(rmc)

Loading…
Cancel
Save