Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Drone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
Drone
Commits
14cbb9da
Commit
14cbb9da
authored
1 year ago
by
DeathwingTheBoss
Browse files
Options
Downloads
Patches
Plain Diff
- Update error structure to support JSON-RPC 2.0 specification
- Add follow_api and tags_api to support Beem (python library)
parent
f4ebbddb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Cargo.lock
+1
-1
1 addition, 1 deletion
Cargo.lock
Cargo.toml
+1
-1
1 addition, 1 deletion
Cargo.toml
src/main.rs
+16
-0
16 additions, 0 deletions
src/main.rs
with
18 additions
and
2 deletions
Cargo.lock
+
1
−
1
View file @
14cbb9da
...
@@ -574,7 +574,7 @@ checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
...
@@ -574,7 +574,7 @@ checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
[[package]]
[[package]]
name = "drone"
name = "drone"
version = "0.2.
2
"
version = "0.2.
3
"
dependencies = [
dependencies = [
"actix-cors",
"actix-cors",
"actix-web",
"actix-web",
...
...
This diff is collapsed.
Click to expand it.
Cargo.toml
+
1
−
1
View file @
14cbb9da
[package]
[package]
name
=
"drone"
name
=
"drone"
version
=
"0.2.
2
"
version
=
"0.2.
3
"
edition
=
"2021"
edition
=
"2021"
authors
=
[
"Deathwing <hi@deathwing.me>"
]
authors
=
[
"Deathwing <hi@deathwing.me>"
]
description
=
"A caching reverse-proxy application for the Hive blockchain."
description
=
"A caching reverse-proxy application for the Hive blockchain."
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
16
−
0
View file @
14cbb9da
...
@@ -81,6 +81,8 @@ impl Serialize for ErrorField {
...
@@ -81,6 +81,8 @@ impl Serialize for ErrorField {
// Structure for the error response.
// Structure for the error response.
#[derive(Serialize,
Deserialize,
Debug)]
#[derive(Serialize,
Deserialize,
Debug)]
struct
ErrorStructure
{
struct
ErrorStructure
{
jsonrpc
:
String
,
id
:
u32
,
code
:
i32
,
code
:
i32
,
message
:
String
,
message
:
String
,
error
:
ErrorField
,
error
:
ErrorField
,
...
@@ -166,6 +168,8 @@ async fn handle_request(
...
@@ -166,6 +168,8 @@ async fn handle_request(
"condenser_api.get_replies_by_last_update"
=>
Endpoints
::
HIVEMIND
,
"condenser_api.get_replies_by_last_update"
=>
Endpoints
::
HIVEMIND
,
"condenser_api.get_reblogged_by"
=>
Endpoints
::
HIVEMIND
,
"condenser_api.get_reblogged_by"
=>
Endpoints
::
HIVEMIND
,
_bridge_endpoint
if
method
.starts_with
(
"bridge."
)
=>
Endpoints
::
HIVEMIND
,
_bridge_endpoint
if
method
.starts_with
(
"bridge."
)
=>
Endpoints
::
HIVEMIND
,
_follow_api_endpoint
if
method
.starts_with
(
"follow_api."
)
=>
Endpoints
::
HIVEMIND
,
// Remove when beem is updated. (Deprecated)
_tags_api_endpoint
if
method
.starts_with
(
"tags_api."
)
=>
Endpoints
::
HIVEMIND
,
// Remove when beem is updated. (Deprecated)
_anything_else
=>
Endpoints
::
HAF
,
_anything_else
=>
Endpoints
::
HAF
,
};
};
...
@@ -191,6 +195,8 @@ async fn handle_request(
...
@@ -191,6 +195,8 @@ async fn handle_request(
Ok
(
response
)
=>
response
,
Ok
(
response
)
=>
response
,
Err
(
err
)
=>
{
Err
(
err
)
=>
{
return
Err
(
ErrorStructure
{
return
Err
(
ErrorStructure
{
jsonrpc
:
request
.jsonrpc
.clone
(),
id
:
request
.id
,
code
:
-
32700
,
code
:
-
32700
,
message
:
format!
(
"Unable to send request to endpoint."
),
message
:
format!
(
"Unable to send request to endpoint."
),
error
:
ErrorField
::
Message
(
err
.to_string
()),
error
:
ErrorField
::
Message
(
err
.to_string
()),
...
@@ -201,6 +207,8 @@ async fn handle_request(
...
@@ -201,6 +207,8 @@ async fn handle_request(
Ok
(
text
)
=>
text
,
Ok
(
text
)
=>
text
,
Err
(
err
)
=>
{
Err
(
err
)
=>
{
return
Err
(
ErrorStructure
{
return
Err
(
ErrorStructure
{
jsonrpc
:
request
.jsonrpc
.clone
(),
id
:
request
.id
,
code
:
-
32600
,
code
:
-
32600
,
message
:
format!
(
"Received an invalid response from the endpoint."
),
message
:
format!
(
"Received an invalid response from the endpoint."
),
error
:
ErrorField
::
Message
(
err
.to_string
()),
error
:
ErrorField
::
Message
(
err
.to_string
()),
...
@@ -211,6 +219,8 @@ async fn handle_request(
...
@@ -211,6 +219,8 @@ async fn handle_request(
Ok
(
parsed
)
=>
parsed
,
Ok
(
parsed
)
=>
parsed
,
Err
(
err
)
=>
{
Err
(
err
)
=>
{
return
Err
(
ErrorStructure
{
return
Err
(
ErrorStructure
{
jsonrpc
:
request
.jsonrpc
.clone
(),
id
:
request
.id
,
code
:
-
32602
,
code
:
-
32602
,
message
:
format!
(
"Unable to parse endpoint data."
),
message
:
format!
(
"Unable to parse endpoint data."
),
error
:
ErrorField
::
Message
(
err
.to_string
()),
error
:
ErrorField
::
Message
(
err
.to_string
()),
...
@@ -219,6 +229,8 @@ async fn handle_request(
...
@@ -219,6 +229,8 @@ async fn handle_request(
};
};
if
json_body
[
"error"
]
.is_object
()
{
if
json_body
[
"error"
]
.is_object
()
{
return
Err
(
ErrorStructure
{
return
Err
(
ErrorStructure
{
jsonrpc
:
request
.jsonrpc
.clone
(),
id
:
request
.id
,
code
:
-
32700
,
code
:
-
32700
,
message
:
format!
(
"Endpoint returned an error."
),
message
:
format!
(
"Endpoint returned an error."
),
error
:
ErrorField
::
Object
(
json_body
[
"error"
]
.clone
()),
error
:
ErrorField
::
Object
(
json_body
[
"error"
]
.clone
()),
...
@@ -262,6 +274,8 @@ async fn api_call(
...
@@ -262,6 +274,8 @@ async fn api_call(
Ok
(
ip
)
=>
ip
,
Ok
(
ip
)
=>
ip
,
Err
(
_
)
=>
{
Err
(
_
)
=>
{
return
HttpResponse
::
InternalServerError
()
.json
(
ErrorStructure
{
return
HttpResponse
::
InternalServerError
()
.json
(
ErrorStructure
{
jsonrpc
:
"2.0"
.to_string
(),
id
:
0
,
code
:
-
32000
,
code
:
-
32000
,
message
:
"Internal Server Error"
.to_string
(),
message
:
"Internal Server Error"
.to_string
(),
error
:
ErrorField
::
Message
(
"Invalid Cloudflare Proxy Header."
.to_string
()),
error
:
ErrorField
::
Message
(
"Invalid Cloudflare Proxy Header."
.to_string
()),
...
@@ -288,6 +302,8 @@ async fn api_call(
...
@@ -288,6 +302,8 @@ async fn api_call(
let
mut
responses
=
Vec
::
new
();
let
mut
responses
=
Vec
::
new
();
if
requests
.len
()
>
100
{
if
requests
.len
()
>
100
{
return
HttpResponse
::
InternalServerError
()
.json
(
ErrorStructure
{
return
HttpResponse
::
InternalServerError
()
.json
(
ErrorStructure
{
jsonrpc
:
"2.0"
.to_string
(),
id
:
0
,
code
:
-
32600
,
code
:
-
32600
,
message
:
"Request parameter error."
.to_string
(),
message
:
"Request parameter error."
.to_string
(),
error
:
ErrorField
::
Message
(
error
:
ErrorField
::
Message
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment