-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.go
executable file
·133 lines (112 loc) · 2.95 KB
/
application.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/murlokswarm/app"
"github.com/sadlil/go-trigger"
"log"
"net/http"
)
var updemiaUser *Updemia
type Updemia struct {
Email string
Passphrase string
Hash string
Imgs []UpdemiaImg
}
type UpdemiaImg struct {
Key string
Url string
Img string
}
type ImgsResponse struct {
Collection []UpdemiaImg
}
func (h *Updemia) Render() string {
return `
<div class="WindowLayout" oncontextmenu="OnContextMenu">
{{if .Hash}}
<div class="Updemia">
<img src="http://www.updemia.com/images/logo.png" alt="" />
<img src="folder.png" alt="" onclick="OnOpenFolder" />
</div>
<div class="Gravatar">
<img src="https://www.gravatar.com/avatar/{{html .Hash}}" title="logout" onclick="OnUserLogout" alt="" />
</div>
<div class="">
<div class="listMedias">
{{ range $index, $element := .Imgs }}
<div class="media">
<a href="{{html .Url}}" target="_blank" style="background-image: url('{{ $element.Img }}');"> </a>
</div>
{{ end }}
</div>
</div>
{{else}}
<div class="HelloBox center">
<img src="http://www.updemia.com/images/logo.png" alt="" />
<h1>
Hello, you
</h1>
<input type="email"
value="{{html .Email}}"
placeholder="What's your user email?"
autofocus="true"
onkeydown="Email"
onkeyup="Email" required="required" />
<input type="password"
value="{{html .Passphrase}}"
placeholder="Pass phrase"
onkeydown="Passphrase"
onkeyup="Passphrase" required="required" />
<button type="button" class="btn" onclick="OnUserLog">Start</button>
</div>
{{end}}
</div>>
`
}
func (h *Updemia) OnUserLogout(arg app.ChangeArg) {
h.Hash = ""
app.Render(updemiaUser)
}
func (h *Updemia) OnUserLog(arg app.ChangeArg) {
if len(h.Email) > 0 {
hash := md5.Sum([]byte(h.Email))
h.Hash = hex.EncodeToString(hash[:])
h.updateImgs()
updemiaUser = h
// update screenshot capture
updateScreencaptureDirectory(getDestinationPath())
// start watching directory
go watchUploadFolder()
}
app.Render(h)
trigger.On("user-newfile-success", func() {
h.updateImgs()
app.Render(updemiaUser)
})
}
func (h *Updemia) OnOpenFolder(arg app.ChangeArg) {
openDirectory(getDestinationPath())
}
func (h *Updemia) updateImgs() {
url := fmt.Sprintf("http://www.updemia.com/api/v1/get?hash=%s", h.Hash)
req, _ := http.NewRequest("GET", url, nil)
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
keys := make([]UpdemiaImg, 0)
if err := json.NewDecoder(resp.Body).Decode(&keys); err != nil {
log.Println(err)
}
h.Imgs = keys
}
func (h *Updemia) OnContextMenu() {
ctxmenu := app.NewContextMenu()
ctxmenu.Mount(&AppMainMenu{})
}
func init() {
app.RegisterComponent(&Updemia{})
}