-
Notifications
You must be signed in to change notification settings - Fork 1
/
task.go
55 lines (50 loc) · 1.11 KB
/
task.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
package main
import (
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/sessions"
"io/ioutil"
)
func getTask(ctx iris.Context) {
if auth, _ := sessions.Get(ctx).GetBoolean("authenticated"); !auth{
ctx.JSON(iris.Map{
"redirect": true,
})
return
}
mdData, err := ioutil.ReadFile("userdata/task/task.md")
Message := []byte("Default")
if err != nil{
Message = []byte("# No task")
} else {
Message = []byte(string(mdData))
}
Task := iris.Map{
"task" : Message,
}
ctx.JSON(Task)
}
func SendTask(ctx iris.Context) {
if auth, _ := sessions.Get(ctx).GetBoolean("authenticated"); !auth{
ctx.JSON(iris.Map{
"redirect": true,
})
return
}
var taskStream MDStream
ResponseMessage := []byte("Default")
err := ctx.ReadJSON(&taskStream)
if err != nil{
ResponseMessage = []byte("JSON Format Error")
} else {
err2 := ioutil.WriteFile("userdata/task/task.md", []byte(taskStream.DataStream), 755)
if err2 != nil {
ResponseMessage = []byte("error1")
} else{
ResponseMessage = []byte("fooooooooo!!!!!")
}
}
Response := iris.Map{
"response":ResponseMessage,
}
ctx.JSON(Response)
}