Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"net"
"net/http"
"net/url"
"os"
"path"
"unicode/utf8"
Expand Down Expand Up @@ -205,17 +206,17 @@ func action(w http.ResponseWriter, r *http.Request) {
}
case "copy":
if len(names) > 0 {
http.SetCookie(w, &http.Cookie{Name: "cpdir", Value: p})
http.SetCookie(w, &http.Cookie{Name: "cpdir", Value: url.QueryEscape(p)})
encodedNames := strings.Join(names, "!$!")
http.SetCookie(w, &http.Cookie{Name: "cpitems", Value: string(encodedNames)})
http.SetCookie(w, &http.Cookie{Name: "cpitems", Value: url.QueryEscape(encodedNames)})
http.SetCookie(w, &http.Cookie{Name: "delorigin", Value: "false"})
}
http.Redirect(w, r, p, http.StatusMovedPermanently)
case "cut":
if len(names) > 0 {
http.SetCookie(w, &http.Cookie{Name: "cpdir", Value: p})
http.SetCookie(w, &http.Cookie{Name: "cpdir", Value: url.QueryEscape(p)})
encodedNames := strings.Join(names, "!$!")
http.SetCookie(w, &http.Cookie{Name: "cpitems", Value: string(encodedNames)})
http.SetCookie(w, &http.Cookie{Name: "cpitems", Value: url.QueryEscape(encodedNames)})
http.SetCookie(w, &http.Cookie{Name: "delorigin", Value: "true"})
}
http.Redirect(w, r, p, http.StatusMovedPermanently)
Expand All @@ -226,21 +227,30 @@ func action(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, p, http.StatusMovedPermanently)
return
}
cpdirValue, err := url.QueryUnescape(cpdir.Value)
if err != nil {
http.Redirect(w, r, p, http.StatusMovedPermanently)
}
var encodedNames *http.Cookie
encodedNames, err = r.Cookie("cpitems")
if err != nil {
http.Redirect(w, r, p, http.StatusMovedPermanently)
return
}
decodedNamesValue, err := url.QueryUnescape(encodedNames.Value)
if err != nil {
http.Redirect(w, r, p, http.StatusMovedPermanently)
return
}
var delOrigin *http.Cookie
delOrigin, err = r.Cookie("delorigin")
if err != nil {
http.Redirect(w, r, p, http.StatusMovedPermanently)
return
}
decodedNames := strings.Split(encodedNames.Value, "!$!")
decodedNames := strings.Split(decodedNamesValue, "!$!")
for _, name := range decodedNames {
srcPath := path.Join(cpdir.Value, name)
srcPath := path.Join(cpdirValue, name)
destPath := path.Join(p, name)
_, err = os.Stat(destPath)
for !os.IsNotExist(err) {
Expand Down