-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.go
134 lines (116 loc) · 2.76 KB
/
app.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
134
package main
import (
gofs "callie/goFs"
"callie/schedule"
"context"
"fmt"
"io/fs"
"log"
"net/http"
"os"
"strings"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// App struct
type App struct {
ctx context.Context
dburl string
}
// type User Struct
type User struct {
Name string `json:"name"`
Age string `json:"age"`
}
// NewApp creates a new App application struct
func NewApp(dburl string) *App {
return &App{dburl: dburl}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, How do you do today?", name)
}
func (a *App) OpenFile() (string, error) {
return runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{})
}
func (a *App) Write(dest string, data []byte) {
os.Mkdir("usrMediaFiles", 0750)
err := os.WriteFile(fmt.Sprintf("usrMediaFiles/%v", dest), data, 0666)
if err != nil {
log.Fatal(err)
}
}
func (a *App) Read(name string) []byte {
return gofs.ReadFile(name)
}
func (a *App) Schedule(exp int, owner, id string) bool {
return schedule.Schedule(exp, owner, id, a.dburl)
}
func (a *App) Schedule2(exp int, owner, id string) bool {
return schedule.Schedulev2(exp, owner, id, a.dburl)
}
func (a *App) DeleteSch(id string) {
schedule.DeleteSchedule(id, a.dburl)
}
type Info struct {
Name string `json:"name"`
Size int64 `json:"size"`
Mode fs.FileMode `json:"mode"`
}
func (a *App) Stats(name string) Info {
s, err := os.Lstat(name)
if err != nil {
log.Fatal(err)
}
return Info{
Name: s.Name(),
Size: s.Size(),
Mode: s.Mode(),
}
}
func (a *App) ShowInfo(i, t string) (string, error) {
return runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: "info",
Title: t,
Message: i,
})
}
func (a *App) GetString(b []byte) string {
return gofs.ByteToJsons(b)
}
func (a *App) GetByte(s string) []byte {
return gofs.JsonToBytes(s)
}
func (a *App) GetUser() string {
return gofs.UserBytesToJson()
}
func (a *App) EditUser(d string) {
gofs.WriteUserData(d)
}
func (a *App) GetMeetings() string {
return gofs.GetMeetings()
}
func (a *App) AddMeeting(m string) {
gofs.AddMeeting(m)
}
type FileLoader struct {
http.Handler
}
func NewFileLoader() *FileLoader {
return &FileLoader{}
}
func (h *FileLoader) ServeHTTP(res http.ResponseWriter, req *http.Request) {
var err error
requestedFilename := strings.TrimPrefix(req.URL.Path, "/")
println("Requesting file:", requestedFilename)
fileData, err := os.ReadFile(requestedFilename)
if err != nil {
res.WriteHeader(http.StatusBadRequest)
res.Write([]byte(fmt.Sprintf("Could not load file %s", requestedFilename)))
}
res.Write(fileData)
}