-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
112 lines (92 loc) · 2.21 KB
/
api.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
//import "time"
//import "os"
import "github.com/gin-gonic/gin"
//import "container/list"
import "strconv"
type DownloadManagerRestAPI struct {
*DownloadManager
}
func (dm *DownloadManagerRestAPI) ListAll(c *gin.Context) {
c.JSON(200, dm.AllDownloads())
}
func (dm *DownloadManagerRestAPI) GetParamOrThrow(c *gin.Context) int {
i, err := strconv.Atoi(c.Params.ByName("id"))
if err != nil {
c.String(500, "Error")
return -1
}
return i
}
func (dm *DownloadManagerRestAPI) Create(c *gin.Context) {
var d Download
c.Bind(&d)
found, pack:= dm.Indx.GetPackage(d.Packid)
if found {
d.Pack = pack
dm.CreateDownload(d)
}
dm.ListAll(c)
}
func (dm *DownloadManagerRestAPI) Update(c *gin.Context) {
//i := dm.GetParamOrThrow(c)
i := c.Params.ByName("id")
found, _ := dm.GetDownload(i)
if found>-1 {
}
}
func (dm *DownloadManagerRestAPI) Delete(c *gin.Context) {
//i := dm.GetParamOrThrow(c)
i := c.Params.ByName("id")
dm.DeleteOne(i)
dm.ListAll(c)
}
type IndexerEndpoints struct{
*Indexer
}
func (ie *IndexerEndpoints) ResetDlDb(c *gin.Context) {
ie.ResetDownloaded()
}
func (ie *IndexerEndpoints) pkgQuery(c *gin.Context) {
c.JSON(200,ie.Search(c.Param("query")))
}
type TaskmgrEndpoints struct {
*Taskmgr
}
func (tm *TaskmgrEndpoints) All(c *gin.Context) {
c.JSON(200,tm.GetAllTasks())
}
func (tm *TaskmgrEndpoints) Get(c *gin.Context) {
if i, err := strconv.ParseUint(c.Params.ByName("id"), 10, 64); err == nil {
c.JSON(200,tm.GetTask(i))
}
}
func (tm *TaskmgrEndpoints) Delete(c *gin.Context) {
if i, err := strconv.ParseUint(c.Params.ByName("id"), 10, 64); err == nil {
tm.RemoveTask(&(tm.GetTask(i).Taskinfo))
}
}
func (tm *TaskmgrEndpoints) Create(c *gin.Context) {
var ti Taskinfo
c.BindJSON(&ti)
if !(ti.ID > 0) {
tm.CreateTask(&ti)
}
tm.All(c)
}
func (tm *TaskmgrEndpoints) Update(c *gin.Context) {
if i, err := strconv.Atoi(c.Params.ByName("id")); err == nil {
var ti Taskinfo
c.BindJSON(&ti)
if ti.ID != uint64(i) {
panic("ids dont match")
}
err,_ := ParseToPE(ti.Criteria)
if err != nil {
c.JSON(500, "")
return
} else {
tm.UpdateTask(&ti)
}
}
}