// GET /export?site=site-id&secret=12345
// exports all comments for siteID as gz file
GET /export?site=site-id&secret=12345
exports all comments for siteID as gz file
// GET / export?site = site - id&secret = 12345 // exports all comments for siteID as gz file
func (m *Migrator) exportCtrl(w http.ResponseWriter, r *http.Request) {
	secret := r.URL.Query().Get("secret")
	if strings.TrimSpace(secret) == "" || secret != m.SecretKey {
		render.Status(r, http.StatusForbidden)
		render.JSON(w, r, JSON{"status": "error", "details": "secret key"})
		return
	}
	siteID := r.URL.Query().Get("site")
	exportFile := fmt.Sprintf("%s-%s.json.gz", siteID, time.Now().Format("20060102"))
	w.Header().Set("Content-Type", "application/gzip")
	w.Header().Set("Content-Disposition", "attachment;filename="+exportFile)
	w.WriteHeader(http.StatusOK)
	gzWriter := gzip.NewWriter(w)
	defer func() {
		if e := gzWriter.Close(); e != nil {
			log.Printf("[WARN] can't close gzip writer, %s", e)
		}
	}()
	if _, err := m.NativeExported.Export(gzWriter, siteID); err != nil {
		rest.SendErrorJSON(w, r, http.StatusInternalServerError, err, "export failed")
		return
	}
}
func ( m * Migrator ) exportCtrl ( w http . ResponseWriter , r * http . Request ) { secret := r . URL . Query ( ) . Get ( " " ) if strings . TrimSpace ( secret ) == " " || secret != m . SecretKey { render . Status ( r , http . StatusForbidden ) render . JSON ( w , r , JSON { " " : " " , " " : " " } ) return } siteID := r . URL . Query ( ) . Get ( " " ) exportFile := fmt . Sprintf ( " " , siteID , time . Now ( ) . Format ( " " ) ) w . Header ( ) . Set ( " " , " " ) w . Header ( ) . Set ( " " , " " + exportFile ) w . WriteHeader ( http . StatusOK ) gzWriter := gzip . NewWriter ( w ) defer func ( ) { if e := gzWriter . Close ( ) ; e != nil { log . Printf ( " " , e ) } } ( ) if _ , err := m . NativeExported . Export ( gzWriter , siteID ) ; err != nil { rest . SendErrorJSON ( w , r , http . StatusInternalServerError , err , " " ) return } }
GET /export?site=site-id&secret=12345
exports all comments for siteID as gz file
GET / export?site = site - id&secret = 12345 exports all comments for siteID as gz file