Fix upload logs
This commit is contained in:
parent
4534394abc
commit
6ece881a52
10
dau.go
10
dau.go
@ -33,7 +33,7 @@ type watch struct {
|
||||
lastCheck time.Time
|
||||
newLastCheck time.Time
|
||||
config config.Watcher
|
||||
uploader upload.Uploader
|
||||
uploader *upload.Uploader
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -47,18 +47,18 @@ func main() {
|
||||
config.LoadOrInit()
|
||||
|
||||
// create the uploader
|
||||
up := upload.Uploader{}
|
||||
up := upload.NewUploader()
|
||||
|
||||
// log.Print("Opening web browser")
|
||||
// open.Start("http://localhost:9090")
|
||||
web := web.WebService{Config: config}
|
||||
web := web.WebService{Config: config, Uploader: up}
|
||||
web.StartWebServer()
|
||||
|
||||
go func() { checkUpdates() }()
|
||||
|
||||
// create the watchers, restart them if config changes
|
||||
// blocks forever
|
||||
startWatchers(config, &up, configChanged)
|
||||
startWatchers(config, up, configChanged)
|
||||
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ func startWatchers(config *config.ConfigService, up *upload.Uploader, configChan
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
for _, c := range config.Config.Watchers {
|
||||
log.Printf("Creating watcher for %s interval %d", c.Path, config.Config.WatchInterval)
|
||||
watcher := watch{uploader: *up, lastCheck: time.Now(), newLastCheck: time.Now(), config: c}
|
||||
watcher := watch{uploader: up, lastCheck: time.Now(), newLastCheck: time.Now(), config: c}
|
||||
go watcher.Watch(config.Config.WatchInterval, ctx)
|
||||
}
|
||||
// wait for single that the config changed
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
type Uploader struct {
|
||||
Uploads []*Upload
|
||||
Uploads []*Upload `json:"uploads"`
|
||||
}
|
||||
|
||||
type Upload struct {
|
||||
@ -45,6 +45,13 @@ type Upload struct {
|
||||
Height int `json:"height"`
|
||||
}
|
||||
|
||||
func NewUploader() *Uploader {
|
||||
u := Uploader{}
|
||||
uploads := make([]*Upload, 0)
|
||||
u.Uploads = uploads
|
||||
return &u
|
||||
}
|
||||
|
||||
func (u *Uploader) AddFile(file string, conf config.Watcher) {
|
||||
thisUpload := Upload{
|
||||
Uploaded: false,
|
||||
@ -58,6 +65,7 @@ func (u *Uploader) AddFile(file string, conf config.Watcher) {
|
||||
|
||||
// Upload uploads any files that have not yet been uploaded
|
||||
func (u *Uploader) Upload() {
|
||||
|
||||
for _, upload := range u.Uploads {
|
||||
if !upload.Uploaded {
|
||||
upload.processUpload()
|
||||
|
@ -14,11 +14,13 @@ import (
|
||||
|
||||
"github.com/tardisx/discord-auto-upload/config"
|
||||
daulog "github.com/tardisx/discord-auto-upload/log"
|
||||
"github.com/tardisx/discord-auto-upload/upload"
|
||||
"github.com/tardisx/discord-auto-upload/version"
|
||||
)
|
||||
|
||||
type WebService struct {
|
||||
Config *config.ConfigService
|
||||
Uploader *upload.Uploader
|
||||
}
|
||||
|
||||
//go:embed data
|
||||
@ -149,19 +151,19 @@ func (ws *WebService) handleConfig(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(b)
|
||||
}
|
||||
|
||||
// func getUploads(w http.ResponseWriter, r *http.Request) {
|
||||
// w.Header().Set("Content-Type", "application/json")
|
||||
// ups := uploads.Uploads
|
||||
// text, _ := json.Marshal(ups)
|
||||
// w.Write([]byte(text))
|
||||
// }
|
||||
func (ws *WebService) getUploads(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
ups := ws.Uploader.Uploads
|
||||
text, _ := json.Marshal(ups)
|
||||
w.Write([]byte(text))
|
||||
}
|
||||
|
||||
func (ws *WebService) StartWebServer() {
|
||||
|
||||
http.HandleFunc("/", ws.getStatic)
|
||||
|
||||
http.HandleFunc("/rest/logs", ws.getLogs)
|
||||
// http.HandleFunc("/rest/uploads", getUploads)
|
||||
http.HandleFunc("/rest/uploads", ws.getUploads)
|
||||
http.HandleFunc("/rest/config", ws.handleConfig)
|
||||
|
||||
go func() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user