accept all paramters as base64
This commit is contained in:
parent
d82d07628b
commit
12bb1179b2
14
main.go
14
main.go
@ -8,7 +8,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -82,7 +81,7 @@ func GetAllHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetFileHandler(w http.ResponseWriter, r *http.Request) {
|
func GetFileHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
fileName, err := url.QueryUnescape(mux.Vars(r)["file"])
|
fileName, err := DecodeBase64String(mux.Vars(r)["file"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
InternalServerError(w, err)
|
InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
@ -92,7 +91,7 @@ func GetFileHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetFileHashHandler(w http.ResponseWriter, r *http.Request) {
|
func GetFileHashHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
fileName, err := url.QueryUnescape(mux.Vars(r)["file"])
|
fileName, err := DecodeBase64String(mux.Vars(r)["file"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
InternalServerError(w, err)
|
InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
@ -121,7 +120,11 @@ func GetFileHashHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetPlaylistHandler(w http.ResponseWriter, r *http.Request) {
|
func GetPlaylistHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
playlistName := mux.Vars(r)["playlist"]
|
playlistName, err := DecodeBase64String(mux.Vars(r)["playlist"])
|
||||||
|
if err != nil {
|
||||||
|
InternalServerError(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
songs, err := GetSongsByPlaylist(playlistName)
|
songs, err := GetSongsByPlaylist(playlistName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -177,7 +180,8 @@ func GetAllFilesHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
func GetEncodeFileHandler(w http.ResponseWriter, r *http.Request) {
|
func GetEncodeFileHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
format := vars["format"]
|
format := vars["format"]
|
||||||
fileName, err := url.QueryUnescape(vars["file"])
|
|
||||||
|
fileName, err := DecodeBase64String(vars["file"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
InternalServerError(w, err)
|
InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
|
10
utils.go
10
utils.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -56,3 +57,12 @@ func IsHidden(entry os.DirEntry) bool {
|
|||||||
func FsEntry2Name(entry os.DirEntry) string {
|
func FsEntry2Name(entry os.DirEntry) string {
|
||||||
return entry.Name()
|
return entry.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DecodeBase64String(str string) (string, error) {
|
||||||
|
data, err := base64.StdEncoding.DecodeString(str)
|
||||||
|
return string(data), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func EncodeBase64String(str string) string {
|
||||||
|
return base64.StdEncoding.EncodeToString([]byte(str))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user