fix: Fix space and LF can't transfer
This commit is contained in:
parent
0165ab48c0
commit
3598c872e3
3
.gitignore
vendored
3
.gitignore
vendored
@ -26,4 +26,5 @@ _testmain.go
|
||||
|
||||
/vendor
|
||||
debug
|
||||
*.exe
|
||||
*.exe
|
||||
clipboard-sync
|
||||
|
@ -12,4 +12,11 @@
|
||||
./clipboard-sync -t s -b :8080
|
||||
|
||||
### Client
|
||||
./clipboard-sync -a http://172.30.34.2:8080
|
||||
./clipboard-sync -a http://172.30.34.2:8080
|
||||
|
||||
#### Changelog
|
||||
|
||||
- 2018-08-30
|
||||
- First Alphe Version
|
||||
- 2018-08-31
|
||||
- Fix space and LF can't transfer
|
14
main.go
14
main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@ -59,13 +60,13 @@ func readClipboard(a string) {
|
||||
old = text
|
||||
updateTime = time.Now().Unix()
|
||||
request, _ := http.NewRequest("POST",
|
||||
fmt.Sprintf(address, text, strconv.FormatInt(updateTime, 10)), nil)
|
||||
fmt.Sprintf(address, encode(text), strconv.FormatInt(updateTime, 10)), nil)
|
||||
client.Do(request)
|
||||
} else {
|
||||
response, _ := http.Get(a)
|
||||
texts, ok := response.Header[textHeader]
|
||||
if ok {
|
||||
sText := texts[0]
|
||||
sText := decode(texts[0])
|
||||
sTime, _ := strconv.ParseInt(response.Header[timeHeader][0], 10, 64)
|
||||
if sTime > updateTime && sText != old {
|
||||
old = sText
|
||||
@ -77,3 +78,12 @@ func readClipboard(a string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func encode(text string) string {
|
||||
return base64.URLEncoding.EncodeToString([]byte(text))
|
||||
}
|
||||
|
||||
func decode(text string) string {
|
||||
origin, _ := base64.URLEncoding.DecodeString(text)
|
||||
return string(origin)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user