소스 검색

Return 507 for UP publishers without subscribers

binwiederhier 3 년 전
부모
커밋
70cd267ff5
3개의 변경된 파일7개의 추가작업 그리고 7개의 파일을 삭제
  1. 1 3
      server/errors.go
  2. 3 4
      server/server.go
  3. 3 0
      server/server_matrix.go

+ 1 - 3
server/errors.go

@@ -92,7 +92,5 @@ var (
 	errHTTPInternalError                             = &errHTTP{50001, http.StatusInternalServerError, "internal server error", ""}
 	errHTTPInternalErrorInvalidPath                  = &errHTTP{50002, http.StatusInternalServerError, "internal server error: invalid path", ""}
 	errHTTPInternalErrorMissingBaseURL               = &errHTTP{50003, http.StatusInternalServerError, "internal server error: base-url must be be configured for this feature", "https://ntfy.sh/docs/config/"}
+	errHTTPInsufficientStorage                       = &errHTTP{50701, http.StatusInsufficientStorage, "internal server error: cannot publish to UnifiedPush topic without active subscriber", ""}
 )
-
-// errHTTPConflictCannotPublishWithoutRateVisitor   = &errHTTP{40904, http.StatusConflict, "conflict: cannot publish to UnifiedPush topic without active subscriber", ""}
-	

+ 3 - 4
server/server.go

@@ -581,10 +581,9 @@ func (s *Server) handlePublishWithoutResponse(r *http.Request, v *visitor) (*mes
 	if err != nil {
 		return nil, err
 	}
-	/*if unifiedpush && t.RateVisitor() == nil {
-		return nil, errHTTPConflictCannotPublishWithoutRateVisitor
-	} else*/
-	if !util.ContainsIP(s.config.VisitorRequestExemptIPAddrs, v.ip) && !vrate.MessageAllowed() {
+	if unifiedpush && t.RateVisitor() == nil {
+		return nil, errHTTPInsufficientStorage
+	} else if !util.ContainsIP(s.config.VisitorRequestExemptIPAddrs, v.ip) && !vrate.MessageAllowed() {
 		return nil, errHTTPTooManyRequestsLimitMessages
 	} else if email != "" && !vrate.EmailAllowed() {
 		return nil, errHTTPTooManyRequestsLimitEmails

+ 3 - 0
server/server_matrix.go

@@ -72,6 +72,9 @@ type matrixResponse struct {
 }
 
 // errMatrix represents an error when handing Matrix gateway messages
+//
+// If the pushKey is set, the app server will remove it and will never send messages using the same
+// push key again, until the user repairs it.
 type errMatrix struct {
 	pushKey string
 	err     error