From 52676cdd1fe953809d5941533521a5100dc0b51d Mon Sep 17 00:00:00 2001 From: shockrah Date: Tue, 20 Apr 2021 12:09:05 -0700 Subject: [PATCH] - Removing /messages/from_id as its no longer usable with the new id generation model + Adding new flags to sample .env file + Wrapper script run-api-tests.sh which does as its called - Removing build.sh in favor of run-api-tests.sh Makefile takes care of building, and apitests are ran with special script anyway --- json-api/.env | 7 +++--- json-api/build.sh | 52 --------------------------------------- json-api/run-api-tests.sh | 24 ++++++++++++++++++ json-api/src/main.rs | 1 - json-api/src/messages.rs | 43 -------------------------------- json-api/src/routes.rs | 1 - 6 files changed, 27 insertions(+), 101 deletions(-) delete mode 100755 json-api/build.sh create mode 100644 json-api/run-api-tests.sh diff --git a/json-api/.env b/json-api/.env index c9dd33f..1b90928 100644 --- a/json-api/.env +++ b/json-api/.env @@ -4,12 +4,11 @@ DATABASE_PASS=password DATABASE_USER=freechat_dev DATABASE_HOST=localhost DATABASE_PORT=3306 -REDIS_URL=redis://127.0.0.1:6379 # Server meta things SERVER_NAME="Freechat Dev Server" SERVER_DESCRIPTION="Server for sick development things" -SERVER_HOSTNAME=localhost -SERVER_PORT=4536 -SERVER_PROTOCOL=http +# NOTE: most clients shouldn't expect these to end with a slash +PUBLIC_URL=http://localhost:4536 +PUBLIC_WS_URL=ws://localhost:5648 diff --git a/json-api/build.sh b/json-api/build.sh deleted file mode 100755 index e98630d..0000000 --- a/json-api/build.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -_help() { -cat < messages::send_message(pool, resp, body, headers, params).await, (GET, routes::MESSAGE_TIME_RANGE) => messages::get_by_time(pool, resp, params).await, - (GET, routes::MESSAGE_FROM_ID) =>messages::from_id(pool, resp, params).await, (GET, routes::MESSAGE_LAST_N) => messages::recent_messages(pool, resp, params).await, /* ADMIN */ (POST, routes::SET_PERMS_BY_ADMIN) => admin::set_permissions(pool, resp, params).await, diff --git a/json-api/src/messages.rs b/json-api/src/messages.rs index 71a621d..12599ea 100644 --- a/json-api/src/messages.rs +++ b/json-api/src/messages.rs @@ -130,49 +130,6 @@ pub async fn send_message(pool: &Pool, response: &mut Response, body: Body } } -pub async fn from_id(pool: &Pool, response: &mut Response, params: HashMap) { - /* - * @start-id: u64 - * @limit: optional - * @channel: u64 - * { - * "channel_id": 1, - * "start": 123, - * "limit": 100 - * } - */ - let channel = qs_param!(params, "channel_id", u64); - let start_id = qs_param!(params, "start", u64); - let limit = qs_param!(params, "limit", u64); - - if let (Some(channel), Some(start_id)) = (channel, start_id) { - match Message::get_from_id(pool, channel, start_id, limit).await { - Ok(db_response) => { - match db_response { - db::Response::Set(messages) => { - // *any* kind of empty response, even those from weird - // parameters get 404's - if messages.len() == 0 { - *response.status_mut() = StatusCode::NOT_FOUND; - } else { - set_json_body(response, json!({"messages": messages})); - } - }, - - _ => *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR - }; - }, - Err(err) => { - *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; - eprintln!("{}", err); - } - }; - } - else { - *response.status_mut() = StatusCode::BAD_REQUEST; - } -} - pub async fn recent_messages(pool: &Pool, response: &mut Response, params: HashMap) { let limit = qs_param!(params, "limit", i32); let channel_id = qs_param!(params, "channel_id", u64); diff --git a/json-api/src/routes.rs b/json-api/src/routes.rs index e4c484c..e2bfb6e 100644 --- a/json-api/src/routes.rs +++ b/json-api/src/routes.rs @@ -12,7 +12,6 @@ pub const CHANNELS_DELETE: Rstr = "/channels/delete"; // requires @name perms: pub const MESSAGE_SEND: Rstr = "/message/send"; // requires @content perms::MESSAGE_SEND pub const MESSAGE_TIME_RANGE: Rstr = "/message/get_range"; // requires @channel(id) @start-time @end-time -pub const MESSAGE_FROM_ID: Rstr = "/message/from_id"; // requires @channel_id requires @start(id) @limit(1..1000) pub const MESSAGE_LAST_N: Rstr = "/message/recent"; // requires @channel_id requires @limit(1..100) pub const GET_ONLINE_MEMBERS: Rstr = "/members/get_online"; // requires none