33 lines
735 B
Go
33 lines
735 B
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"go-socket/packages/convertions"
|
|
)
|
|
|
|
func HandleFileUpload(response http.ResponseWriter, request *http.Request) {
|
|
if !postValidCheckWithResponseOnFail(&response, request, true) {
|
|
return
|
|
}
|
|
ctx := request.Context()
|
|
|
|
user, err := getUserByToken(ctx, request.Header.Get("token"))
|
|
if err != nil {
|
|
http.Error(response, "invalid token", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
connectionId, err := convertions.ConvertStringUuid(request.FormValue("connectionid"))
|
|
if err != nil {
|
|
http.Error(response, "invalid connectionid", http.StatusBadRequest)
|
|
return
|
|
}
|
|
_, ok := user.Connections[connectionId]
|
|
if !ok {
|
|
http.Error(response, "no such connection", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
}
|