2016-07-07 13:10:39 +03:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
2016-09-21 21:44:52 +03:00
|
|
|
"io"
|
2016-08-26 23:45:55 +03:00
|
|
|
"log"
|
2016-07-07 13:10:39 +03:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
|
|
|
"elyby/minecraft-skinsystem/lib/tools"
|
2016-09-22 19:32:00 +03:00
|
|
|
"elyby/minecraft-skinsystem/lib/data"
|
2016-07-07 13:10:39 +03:00
|
|
|
)
|
|
|
|
|
2016-09-21 21:44:52 +03:00
|
|
|
func Cape(response http.ResponseWriter, request *http.Request) {
|
|
|
|
username := tools.ParseUsername(mux.Vars(request)["username"])
|
2016-08-26 23:45:55 +03:00
|
|
|
log.Println("request cape for username " + username)
|
2016-09-22 19:32:00 +03:00
|
|
|
rec, err := data.FindCapeByUsername(username)
|
2016-09-21 21:44:52 +03:00
|
|
|
if (err != nil) {
|
|
|
|
http.Redirect(response, request, "http://skins.minecraft.net/MinecraftCloaks/" + username + ".png", 301)
|
|
|
|
}
|
|
|
|
|
|
|
|
request.Header.Set("Content-Type", "image/png")
|
2016-09-22 19:32:00 +03:00
|
|
|
io.Copy(response, rec.File)
|
2016-07-07 13:10:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|