-
Notifications
You must be signed in to change notification settings - Fork 0
/
received.go
51 lines (40 loc) · 1.12 KB
/
received.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package liveshare_routes
import (
"fmt"
"github.com/Liphium/station/chatserver/liveshare"
"github.com/Liphium/station/main/integration"
"github.com/gofiber/fiber/v2"
)
type chunkReceivedRequest struct {
Id string `json:"id"`
Receiver string `json:"receiver"`
Token string `json:"token"`
}
func receivedChunk(c *fiber.Ctx) error {
var req chunkReceivedRequest
if err := c.BodyParser(&req); err != nil {
return integration.InvalidRequest(c, "invalid request")
}
if req.Id == "" || req.Receiver == "" || req.Token == "" {
return integration.InvalidRequest(c, "id and token are required")
}
transaction, ok := liveshare.GetTransaction(req.Id)
if !ok || transaction.Token != req.Token {
return integration.InvalidRequest(c, "invalid id or token")
}
finished, err := transaction.PartReceived(req.Receiver)
if err != nil {
return integration.InvalidRequest(c, fmt.Sprint("invalid receiver: ", err))
}
if finished {
liveshare.CancelTransaction(transaction.Id)
return c.JSON(fiber.Map{
"success": true,
"complete": true,
})
}
return c.JSON(fiber.Map{
"success": true,
"complete": false,
})
}