mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-02-04 09:15:08 +01:00
Add regex
This commit is contained in:
@@ -315,7 +315,6 @@ func (s *Server) ScreenShotGet(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (s *Server) ScreenShot(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ScreenShot(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Create a struct representing the XML result
|
// Create a struct representing the XML result
|
||||||
type Result struct {
|
type Result struct {
|
||||||
XMLName xml.Name `xml:"result"`
|
XMLName xml.Name `xml:"result"`
|
||||||
@@ -324,33 +323,27 @@ func (s *Server) ScreenShot(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Set the Content-Type header to specify that the response is in XML format
|
// Set the Content-Type header to specify that the response is in XML format
|
||||||
w.Header().Set("Content-Type", "text/xml")
|
w.Header().Set("Content-Type", "text/xml")
|
||||||
result := Result{Code: "200"}
|
result := Result{Code: "200"}
|
||||||
|
|
||||||
if !s.erupeConfig.Screenshots.Enabled {
|
if !s.erupeConfig.Screenshots.Enabled {
|
||||||
result = Result{Code: "400"}
|
result = Result{Code: "400"}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
result = Result{Code: "405"}
|
result = Result{Code: "405"}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Get File from Request
|
// Get File from Request
|
||||||
file, _, err := r.FormFile("img")
|
file, _, err := r.FormFile("img")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result = Result{Code: "400"}
|
result = Result{Code: "400"}
|
||||||
|
|
||||||
}
|
}
|
||||||
token := r.FormValue("token")
|
token := r.FormValue("token")
|
||||||
if token == "" {
|
if token == "" {
|
||||||
result = Result{Code: "400"}
|
result = Result{Code: "400"}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate file
|
// Validate file
|
||||||
img, _, err := image.Decode(file)
|
img, _, err := image.Decode(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
result = Result{Code: "400"}
|
result = Result{Code: "400"}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := filepath.Join(s.erupeConfig.Screenshots.OutputDir)
|
dir := filepath.Join(s.erupeConfig.Screenshots.OutputDir)
|
||||||
@@ -380,9 +373,7 @@ func (s *Server) ScreenShot(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Error writing screenshot, could not write file", zap.Error(err))
|
s.logger.Error("Error writing screenshot, could not write file", zap.Error(err))
|
||||||
result = Result{Code: "500"}
|
result = Result{Code: "500"}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Marshal the struct into XML
|
// Marshal the struct into XML
|
||||||
xmlData, err := xml.Marshal(result)
|
xmlData, err := xml.Marshal(result)
|
||||||
@@ -390,7 +381,6 @@ func (s *Server) ScreenShot(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "Unable to marshal XML", http.StatusInternalServerError)
|
http.Error(w, "Unable to marshal XML", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the XML response with a 200 status code
|
// Write the XML response with a 200 status code
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Write(xmlData)
|
w.Write(xmlData)
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func (s *Server) Start() error {
|
|||||||
r.HandleFunc("/character/delete", s.DeleteCharacter)
|
r.HandleFunc("/character/delete", s.DeleteCharacter)
|
||||||
r.HandleFunc("/character/export", s.ExportSave)
|
r.HandleFunc("/character/export", s.ExportSave)
|
||||||
r.HandleFunc("/api/ss/bbs/upload.php", s.ScreenShot)
|
r.HandleFunc("/api/ss/bbs/upload.php", s.ScreenShot)
|
||||||
r.HandleFunc("/api/ss/bbs/{id}", s.ScreenShotGet)
|
r.HandleFunc("/api/ss/bbs/{id:[A-Za-z0-9]+}", s.ScreenShotGet)
|
||||||
handler := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}))(r)
|
handler := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}))(r)
|
||||||
s.httpServer.Handler = handlers.LoggingHandler(os.Stdout, handler)
|
s.httpServer.Handler = handlers.LoggingHandler(os.Stdout, handler)
|
||||||
s.httpServer.Addr = fmt.Sprintf(":%d", s.erupeConfig.SignV2.Port)
|
s.httpServer.Addr = fmt.Sprintf(":%d", s.erupeConfig.SignV2.Port)
|
||||||
|
|||||||
Reference in New Issue
Block a user