mirror of
				https://github.com/binwiederhier/ntfy.git
				synced 2025-10-31 13:02:24 +01:00 
			
		
		
		
	Attachment behavior fix for Firefox
This commit is contained in:
		
							parent
							
								
									f98743dd9b
								
							
						
					
					
						commit
						aba7e86cbc
					
				
					 13 changed files with 223 additions and 123 deletions
				
			
		server
|  | @ -22,6 +22,7 @@ var ( | |||
| // visitor represents an API user, and its associated rate.Limiter used for rate limiting | ||||
| type visitor struct { | ||||
| 	config        *Config | ||||
| 	messageCache  *messageCache | ||||
| 	ip            string | ||||
| 	requests      *rate.Limiter | ||||
| 	emails        *rate.Limiter | ||||
|  | @ -31,9 +32,17 @@ type visitor struct { | |||
| 	mu            sync.Mutex | ||||
| } | ||||
| 
 | ||||
| func newVisitor(conf *Config, ip string) *visitor { | ||||
| type visitorStats struct { | ||||
| 	AttachmentFileSizeLimit         int64 `json:"attachmentFileSizeLimit"` | ||||
| 	VisitorAttachmentBytesTotal     int64 `json:"visitorAttachmentBytesTotal"` | ||||
| 	VisitorAttachmentBytesUsed      int64 `json:"visitorAttachmentBytesUsed"` | ||||
| 	VisitorAttachmentBytesRemaining int64 `json:"visitorAttachmentBytesRemaining"` | ||||
| } | ||||
| 
 | ||||
| func newVisitor(conf *Config, messageCache *messageCache, ip string) *visitor { | ||||
| 	return &visitor{ | ||||
| 		config:        conf, | ||||
| 		messageCache:  messageCache, | ||||
| 		ip:            ip, | ||||
| 		requests:      rate.NewLimiter(rate.Every(conf.VisitorRequestLimitReplenish), conf.VisitorRequestLimitBurst), | ||||
| 		emails:        rate.NewLimiter(rate.Every(conf.VisitorEmailLimitReplenish), conf.VisitorEmailLimitBurst), | ||||
|  | @ -91,3 +100,20 @@ func (v *visitor) Stale() bool { | |||
| 	defer v.mu.Unlock() | ||||
| 	return time.Since(v.seen) > visitorExpungeAfter | ||||
| } | ||||
| 
 | ||||
| func (v *visitor) Stats() (*visitorStats, error) { | ||||
| 	attachmentsBytesUsed, err := v.messageCache.AttachmentBytesUsed(v.ip) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	attachmentsBytesRemaining := v.config.VisitorAttachmentTotalSizeLimit - attachmentsBytesUsed | ||||
| 	if attachmentsBytesRemaining < 0 { | ||||
| 		attachmentsBytesRemaining = 0 | ||||
| 	} | ||||
| 	return &visitorStats{ | ||||
| 		AttachmentFileSizeLimit:         v.config.AttachmentFileSizeLimit, | ||||
| 		VisitorAttachmentBytesTotal:     v.config.VisitorAttachmentTotalSizeLimit, | ||||
| 		VisitorAttachmentBytesUsed:      attachmentsBytesUsed, | ||||
| 		VisitorAttachmentBytesRemaining: attachmentsBytesRemaining, | ||||
| 	}, nil | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Philipp Heckel
						Philipp Heckel