Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
twitter_syncer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
twitter_syncer
Commits
b0cd91c1
Commit
b0cd91c1
authored
Dec 13, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add api to add/remove bee
parent
1fd4fb38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
api_service.go
api_service.go
+76
-0
main.go
main.go
+2
-0
No files found.
api_service.go
View file @
b0cd91c1
...
...
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"log/slog"
"strings"
// "github.com/gofiber/fiber/v2"
// "github.com/gofiber/fiber/v2/middleware/cors"
...
...
@@ -525,3 +526,78 @@ func VerifyLike(c *fiber.Ctx) error {
})
}
type
BeeReq
struct
{
Bee
string
`json:"bee"`
}
// BeeAdd godoc
// @Summary BeeAdd
// @Description add a bee client.
// @Tags bee
// @Accept json
// @Produce json
// @Param bee body BeeReq true "bee"
// @Success 200 {object} Res
// @Failure 400 {object} Res
// @Failure 500 {object} Res
// @Router /bee/add [post]
func
BeeAdd
(
c
*
fiber
.
Ctx
)
error
{
slog
.
Info
(
c
.
Route
()
.
Path
,
"body"
,
string
(
c
.
Request
()
.
Body
()))
req
:=
BeeReq
{}
if
err
:=
json
.
Unmarshal
(
c
.
Request
()
.
Body
(),
&
req
);
err
!=
nil
{
slog
.
Error
(
"json.Unmarshal(c.Request().Body(), &req)"
,
"err"
,
err
.
Error
())
return
c
.
JSON
(
Res
{
Code
:
500
,
Msg
:
err
.
Error
(),
})
}
swarm
:=
swarm
.
GetSwarm
()
bees
:=
strings
.
Split
(
req
.
Bee
,
","
)
for
_
,
bee
:=
range
bees
{
swarm
.
AddClient
(
bee
)
slog
.
Info
(
"add new bee"
,
"Bee"
,
bee
)
}
return
c
.
JSON
(
Res
{
Code
:
200
,
})
}
// BeeDel godoc
// @Summary BeeDel
// @Description add a bee client.
// @Tags bee
// @Accept json
// @Produce json
// @Param bee body BeeReq true "bee"
// @Success 200 {object} Res
// @Failure 400 {object} Res
// @Failure 500 {object} Res
// @Router /bee/del [post]
func
BeeDel
(
c
*
fiber
.
Ctx
)
error
{
slog
.
Info
(
c
.
Route
()
.
Path
,
"body"
,
string
(
c
.
Request
()
.
Body
()))
req
:=
BeeReq
{}
if
err
:=
json
.
Unmarshal
(
c
.
Request
()
.
Body
(),
&
req
);
err
!=
nil
{
slog
.
Error
(
"json.Unmarshal(c.Request().Body(), &req)"
,
"err"
,
err
.
Error
())
return
c
.
JSON
(
Res
{
Code
:
500
,
Msg
:
err
.
Error
(),
})
}
swarm
:=
swarm
.
GetSwarm
()
bees
:=
strings
.
Split
(
req
.
Bee
,
","
)
for
_
,
bee
:=
range
bees
{
swarm
.
RemoveClient
(
bee
)
slog
.
Info
(
"remove bee"
,
"Bee"
,
bee
)
}
return
c
.
JSON
(
Res
{
Code
:
200
,
})
}
main.go
View file @
b0cd91c1
...
...
@@ -87,6 +87,8 @@ func main() {
app
.
Post
(
"/task/stop"
,
TaskStop
)
app
.
Get
(
"/verify/follower"
,
VerifyFollower
)
app
.
Get
(
"/verify/retweeter"
,
VerifyRetweeter
)
app
.
Post
(
"/bee/add"
,
BeeAdd
)
app
.
Post
(
"/bee/del"
,
BeeDel
)
//VerifyLike
app
.
Get
(
"/verify/like"
,
VerifyLike
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment