2016-07-07 15:40:39 +05:30
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
2016-09-22 00:14:52 +05:30
|
|
|
"os"
|
|
|
|
"io"
|
2016-08-27 02:15:55 +05:30
|
|
|
"log"
|
2016-09-22 00:14:52 +05:30
|
|
|
"strings"
|
2016-07-07 15:40:39 +05:30
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
|
|
|
"elyby/minecraft-skinsystem/lib/tools"
|
2016-09-22 00:14:52 +05:30
|
|
|
"elyby/minecraft-skinsystem/lib/services"
|
2016-07-07 15:40:39 +05:30
|
|
|
)
|
|
|
|
|
2016-09-22 00:14:52 +05:30
|
|
|
func Cape(response http.ResponseWriter, request *http.Request) {
|
|
|
|
username := tools.ParseUsername(mux.Vars(request)["username"])
|
2016-08-27 02:15:55 +05:30
|
|
|
log.Println("request cape for username " + username)
|
2016-09-22 00:14:52 +05:30
|
|
|
file, err := os.Open(services.RootFolder + "/data/capes/" + strings.ToLower(username) + ".png")
|
|
|
|
if (err != nil) {
|
|
|
|
http.Redirect(response, request, "http://skins.minecraft.net/MinecraftCloaks/" + username + ".png", 301)
|
|
|
|
}
|
|
|
|
|
|
|
|
request.Header.Set("Content-Type", "image/png")
|
|
|
|
io.Copy(response, file)
|
2016-07-07 15:40:39 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func CapeGET(w http.ResponseWriter, r *http.Request) {
|
|
|
|
username := r.URL.Query().Get("name")
|
|
|
|
if username == "" {
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.Vars(r)["username"] = username
|
|
|
|
Cape(w, r)
|
|
|
|
}
|