| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | package core | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"net/http" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	validation "github.com/go-ozzo/ozzo-validation/v4" | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	"github.com/pocketbase/pocketbase/tools/hook" | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type BatchRequestEvent struct { | 
					
						
							| 
									
										
										
										
											2024-10-24 13:37:22 +08:00
										 |  |  | 	hook.Event | 
					
						
							| 
									
										
										
										
											2024-09-30 00:23:19 +08:00
										 |  |  | 	*RequestEvent | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Batch []*InternalRequest | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type InternalRequest struct { | 
					
						
							|  |  |  | 	// note: for uploading files the value must be either *filesystem.File or []*filesystem.File
 | 
					
						
							|  |  |  | 	Body map[string]any `form:"body" json:"body"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Headers map[string]string `form:"headers" json:"headers"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Method string `form:"method" json:"method"` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	URL string `form:"url" json:"url"` | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (br InternalRequest) Validate() error { | 
					
						
							|  |  |  | 	return validation.ValidateStruct(&br, | 
					
						
							|  |  |  | 		validation.Field(&br.Method, validation.Required, validation.In(http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete)), | 
					
						
							|  |  |  | 		validation.Field(&br.URL, validation.Required, validation.Length(0, 2000)), | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | } |