mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-30 22:02:25 -05:00 
			
		
		
		
	[feature] Allow users to export data via the settings panel (#3140)
* [feature] Allow users to export data via the settings panel * rename/move some stuff
This commit is contained in:
		
					parent
					
						
							
								43519324b3
							
						
					
				
			
			
				commit
				
					
						38f041cea1
					
				
			
		
					 32 changed files with 2102 additions and 7 deletions
				
			
		|  | @ -18,6 +18,7 @@ | |||
| package util | ||||
| 
 | ||||
| import ( | ||||
| 	"encoding/csv" | ||||
| 	"encoding/json" | ||||
| 	"encoding/xml" | ||||
| 	"io" | ||||
|  | @ -213,6 +214,47 @@ func EncodeXMLResponse( | |||
| 	putBuf(buf) | ||||
| } | ||||
| 
 | ||||
| // EncodeCSVResponse encodes 'records' as CSV HTTP response | ||||
| // to ResponseWriter with given status code, using CSV content-type. | ||||
| func EncodeCSVResponse( | ||||
| 	rw http.ResponseWriter, | ||||
| 	r *http.Request, | ||||
| 	statusCode int, | ||||
| 	records [][]string, | ||||
| ) { | ||||
| 	// Acquire buffer. | ||||
| 	buf := getBuf() | ||||
| 
 | ||||
| 	// Wrap buffer in CSV writer. | ||||
| 	csvWriter := csv.NewWriter(buf) | ||||
| 
 | ||||
| 	// Write all the records to the buffer. | ||||
| 	if err := csvWriter.WriteAll(records); err == nil { | ||||
| 		// Respond with the now-known | ||||
| 		// size byte slice within buf. | ||||
| 		WriteResponseBytes(rw, r, | ||||
| 			statusCode, | ||||
| 			TextCSV, | ||||
| 			buf.B, | ||||
| 		) | ||||
| 	} else { | ||||
| 		// This will always be an csv error, we | ||||
| 		// can't really add any more useful context. | ||||
| 		log.Error(r.Context(), err) | ||||
| 
 | ||||
| 		// Any error returned here is unrecoverable, | ||||
| 		// set Internal Server Error JSON response. | ||||
| 		WriteResponseBytes(rw, r, | ||||
| 			http.StatusInternalServerError, | ||||
| 			AppJSON, | ||||
| 			StatusInternalServerErrorJSON, | ||||
| 		) | ||||
| 	} | ||||
| 
 | ||||
| 	// Release. | ||||
| 	putBuf(buf) | ||||
| } | ||||
| 
 | ||||
| // writeResponseUnknownLength handles reading data of unknown legnth | ||||
| // efficiently into memory, and passing on to WriteResponseBytes(). | ||||
| func writeResponseUnknownLength( | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue