-
Notifications
You must be signed in to change notification settings - Fork 1
/
import.go
57 lines (49 loc) · 1.46 KB
/
import.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
// +build js
package importhandler
import (
"context"
"net/url"
"time"
"github.com/flimzy/goweb/file"
"github.com/flimzy/jqeventrouter"
"github.com/flimzy/log"
"github.com/gopherjs/gopherjs/js"
"github.com/gopherjs/jquery"
"github.com/FlashbackSRS/flashback/model"
)
var jQuery = jquery.NewJQuery
// BeforeTransition prepares import page
func BeforeTransition(repo *model.Repo) jqeventrouter.HandlerFunc {
return func(_ *jquery.Event, _ *js.Object, _ url.Values) bool {
go func() {
container := jQuery(":mobile-pagecontainer")
jQuery("#importnow", container).On("click", func() {
log.Debug("Attempting to import something...\n")
go func() {
start := time.Now()
if err := DoImport(repo); err != nil {
log.Printf("Error importing: %s\n", err)
}
log.Printf("DoImport() complete, %v\n", time.Now().Sub(start))
}()
})
jQuery(".show-until-load", container).Hide()
jQuery(".hide-until-load", container).Show()
}()
return true
}
}
// DoImport does an import of a *.fbb package
func DoImport(repo *model.Repo) error {
files := file.InternalizeFileList(jQuery("#apkg", ":mobile-pagecontainer").Get(0).Get("files"))
for i := 0; i < files.Length; i++ {
reporter := func(total, progress uint64, percent float64) {
log.Printf("%d/%d : %.2f\n", progress, total, percent)
}
if err := repo.ImportFile(context.TODO(), files.Item(i), reporter); err != nil {
return err
}
}
log.Debugf("Done with import\n")
return nil
}