mirror of
				https://github.com/binwiederhier/ntfy.git
				synced 2025-10-31 13:02:24 +01:00 
			
		
		
		
	Simplify
This commit is contained in:
		
							parent
							
								
									6b1f72fec9
								
							
						
					
					
						commit
						35eac5b9ad
					
				
					 3 changed files with 10 additions and 14 deletions
				
			
		|  | @ -106,7 +106,6 @@ var ( | |||
| 	errHTTPBadRequestNotAPaidUser                    = &errHTTP{40027, http.StatusBadRequest, "invalid request: not a paid user", "", nil} | ||||
| 	errHTTPBadRequestBillingRequestInvalid           = &errHTTP{40028, http.StatusBadRequest, "invalid request: not a valid billing request", "", nil} | ||||
| 	errHTTPBadRequestBillingSubscriptionExists       = &errHTTP{40029, http.StatusBadRequest, "invalid request: billing subscription already exists", "", nil} | ||||
| 	errHTTPBadRequestInvalidMimeHeader               = &errHTTP{40030, http.StatusBadRequest, "invalid request: invalid MIME encoding of header", "", nil} | ||||
| 	errHTTPNotFound                                  = &errHTTP{40401, http.StatusNotFound, "page not found", "", nil} | ||||
| 	errHTTPUnauthorized                              = &errHTTP{40101, http.StatusUnauthorized, "unauthorized", "https://ntfy.sh/docs/publish/#authentication", nil} | ||||
| 	errHTTPForbidden                                 = &errHTTP{40301, http.StatusForbidden, "forbidden", "https://ntfy.sh/docs/publish/#authentication", nil} | ||||
|  |  | |||
|  | @ -843,17 +843,10 @@ func (s *Server) forwardPollRequest(v *visitor, m *message) { | |||
| func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, firebase bool, email string, unifiedpush bool, err *errHTTP) { | ||||
| 	cache = readBoolParam(r, true, "x-cache", "cache") | ||||
| 	firebase = readBoolParam(r, true, "x-firebase", "firebase") | ||||
| 	m.Title = maybeDecodeHeader(readParam(r, "x-title", "title", "t")) | ||||
| 	m.Click = readParam(r, "x-click", "click") | ||||
| 	icon := readParam(r, "x-icon", "icon") | ||||
| 	filename := readParam(r, "x-filename", "filename", "file", "f") | ||||
| 	title := readParam(r, "x-title", "title", "t") | ||||
| 	if title != "" { | ||||
| 		title, err := mimeDecoder.DecodeHeader(title) | ||||
| 		if err != nil { | ||||
| 			return false, false, "", false, errHTTPBadRequestInvalidMimeHeader.Wrap("invalid X-Title header: %s", err.Error()) | ||||
| 		} | ||||
| 		m.Title = title | ||||
| 	} | ||||
| 	attach := readParam(r, "x-attach", "attach", "a") | ||||
| 	if attach != "" || filename != "" { | ||||
| 		m.Attachment = &attachment{} | ||||
|  | @ -891,11 +884,7 @@ func (s *Server) parsePublishParams(r *http.Request, m *message) (cache bool, fi | |||
| 	} | ||||
| 	messageStr := strings.ReplaceAll(readParam(r, "x-message", "message", "m"), "\\n", "\n") | ||||
| 	if messageStr != "" { | ||||
| 		messageStr, err := mimeDecoder.DecodeHeader(messageStr) | ||||
| 		if err != nil { | ||||
| 			return false, false, "", false, errHTTPBadRequestInvalidMimeHeader.Wrap("invalid X-Message header: %s", err.Error()) | ||||
| 		} | ||||
| 		m.Message = messageStr | ||||
| 		m.Message = maybeDecodeHeader(messageStr) | ||||
| 	} | ||||
| 	var e error | ||||
| 	m.Priority, e = util.ParsePriority(readParam(r, "x-priority", "priority", "prio", "p")) | ||||
|  |  | |||
|  | @ -117,3 +117,11 @@ func fromContext[T any](r *http.Request, key contextKey) (T, error) { | |||
| 	} | ||||
| 	return t, nil | ||||
| } | ||||
| 
 | ||||
| func maybeDecodeHeader(header string) string { | ||||
| 	decoded, err := mimeDecoder.DecodeHeader(header) | ||||
| 	if err != nil { | ||||
| 		return header | ||||
| 	} | ||||
| 	return decoded | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 binwiederhier
						binwiederhier