-
Notifications
You must be signed in to change notification settings - Fork 2
/
history.go
77 lines (66 loc) · 1.95 KB
/
history.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
package sync
import (
"log"
"reflect"
"github.com/quic-s/quics-client/pkg/db/badger"
"github.com/quic-s/quics-client/pkg/net/qclient"
qp "github.com/quic-s/quics-protocol"
qstypes "github.com/quic-s/quics/pkg/types"
)
// @URL /api/v1/history/rollback
func RollBack(path string, version uint64) error {
_, AfterPath := badger.SplitBeforeAfterRoot(path)
err := Conn.OpenTransaction(qstypes.ROLLBACK, func(stream *qp.Stream, transactionName string, transactionID []byte) error {
rollbackres, err := qclient.SendRollBack(stream, badger.GetUUID(), AfterPath, version)
if err != nil {
return err
}
if reflect.ValueOf(rollbackres).IsZero() {
return nil
}
return nil
})
if err != nil {
return err
}
return nil
}
// @URL /api/v1/history/show
func HistoryShow(path string, cntfromhead uint64) ([]qstypes.FileHistory, error) {
historyShowRes := []qstypes.FileHistory{}
_, AfterPath := badger.SplitBeforeAfterRoot(path)
err := Conn.OpenTransaction(qstypes.HISTORYSHOW, func(stream *qp.Stream, transactionName string, transactionID []byte) error {
historyshowres, err := qclient.SendShowHistory(stream, badger.GetUUID(), AfterPath, cntfromhead)
if err != nil {
return err
}
if reflect.ValueOf(historyshowres).IsZero() {
log.Println("dont have history")
return nil
}
historyShowRes = historyshowres.History
return nil
})
if err != nil {
return nil, err
}
return historyShowRes, nil
}
// @URL /api/v1/history/download
func HistoryDownload(path string, version uint64) error {
_, AfterPath := badger.SplitBeforeAfterRoot(path)
err := Conn.OpenTransaction(qstypes.HISTORYDOWNLOAD, func(stream *qp.Stream, transactionName string, transactionID []byte) error {
historydownloadres, err := qclient.SendDownloadHistory(stream, badger.GetUUID(), AfterPath, version)
if err != nil {
return err
}
if reflect.ValueOf(historydownloadres).IsZero() {
return nil
}
return nil
})
if err != nil {
return err
}
return nil
}