feat(web-proxy): throw error when trying to access apiv1 on apiv2
This commit is contained in:
		@@ -74,6 +74,23 @@ func (p ProxyHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if r.URL.Path == "/" {
 | 
			
		||||
			http.Redirect(rw, r, "https://pluralkit.me", http.StatusFound)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if strings.HasPrefix(r.URL.Path, "/v1") {
 | 
			
		||||
			rw.Header().Set("content-type", "application/json")
 | 
			
		||||
			rw.WriteHeader(410)
 | 
			
		||||
			rw.Write([]byte(`{"message":"Unsupported API version","code":0}`))
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if is_trying_to_use_v1_path_on_v2(r.URL.Path) {
 | 
			
		||||
			rw.WriteHeader(400)
 | 
			
		||||
			rw.Write([]byte(`{"message":"Invalid path for API version","code":0}`))
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if is_api_ratelimited(rw, r) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -63,3 +63,12 @@ func requireEnv(key string) string {
 | 
			
		||||
		return val
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func is_trying_to_use_v1_path_on_v2(path string) bool {
 | 
			
		||||
	return strings.HasPrefix(path, "/v2/s/") ||
 | 
			
		||||
		strings.HasPrefix(path, "/v2/m/") ||
 | 
			
		||||
		strings.HasPrefix(path, "/v2/a/") ||
 | 
			
		||||
		strings.HasPrefix(path, "/v2/msg/") ||
 | 
			
		||||
		path == "/v2/s" ||
 | 
			
		||||
		path == "/v2/m"
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user