Skip to content

Commit 977ab65

Browse files
committed
fix lack of error on file site export
Previously, status 200 was set for file export, which is used for backup, which resulted in an inability to set an error status code in case of a problem with file generation. After this change, status code 200 would be written automatically by Go before we start writing the response's body.
1 parent 81c30e0 commit 977ab65

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

backend/app/rest/api/migrator.go

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ func (m *Migrator) exportCtrl(w http.ResponseWriter, r *http.Request) {
136136
exportFile := fmt.Sprintf("%s-%s.json.gz", siteID, time.Now().Format("20060102"))
137137
w.Header().Set("Content-Type", "application/gzip")
138138
w.Header().Set("Content-Disposition", "attachment;filename="+exportFile)
139-
w.WriteHeader(http.StatusOK)
140139
gzWriter := gzip.NewWriter(w)
141140
defer func() {
142141
if e := gzWriter.Close(); e != nil {

backend/app/rest/api/rss.go

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ func (s *rss) postCommentsCtrl(w http.ResponseWriter, r *http.Request) {
5656

5757
w.Header().Set("Content-Type", "application/xml; charset=utf-8")
5858
w.WriteHeader(http.StatusOK)
59-
6059
if _, err = w.Write(data); err != nil {
6160
log.Printf("[WARN] failed to send response to %s, %s", r.RemoteAddr, err)
6261
}

backend/remark.rest

+8
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ GET {{host}}/api/v1/admin/blocked?site={{site}}
103103
### delete comment by id
104104
DELETE {{host}}/api/v1/admin/comment/3665976683?site={{site}}&url={{url}}
105105

106+
### export site (for backup)
107+
GET {{host}}/api/v1/admin/export?site={{site}}&mode=stream
108+
X-JWT: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZW1hcmsiLCJleHAiOjE5NzYwNTY3NTYsImp0aSI6IjJlOGJmMTE5OTI0MjQxMDRjYjFhZGRlODllMWYwNGFiMTg4YWZjMzQiLCJpYXQiOjE1NzYwNTY0NTYsImlzcyI6InJlbWFyazQyIiwidXNlciI6eyJuYW1lIjoiZGV2X3VzZXIiLCJpZCI6ImRldl91c2VyIiwicGljdHVyZSI6Imh0dHA6Ly8xMjcuMC4wLjE6ODA4MC9hcGkvdjEvYXZhdGFyL2NjZmEyYWJkMDE2Njc2MDViNGUxZmM0ZmNiOTFiMWUxYWYzMjMyNDAuaW1hZ2UiLCJhdHRycyI6eyJhZG1pbiI6dHJ1ZSwiYmxvY2tlZCI6ZmFsc2V9fX0.6Qt5s2enBMRC-Jmsua01yViVYI95Dx6BPBMaNjj36d4
109+
110+
### export site (for backup) to .gz file
111+
GET {{host}}/api/v1/admin/export?site={{site}}&mode=file
112+
X-JWT: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJyZW1hcmsiLCJleHAiOjE5NzYwNTY3NTYsImp0aSI6IjJlOGJmMTE5OTI0MjQxMDRjYjFhZGRlODllMWYwNGFiMTg4YWZjMzQiLCJpYXQiOjE1NzYwNTY0NTYsImlzcyI6InJlbWFyazQyIiwidXNlciI6eyJuYW1lIjoiZGV2X3VzZXIiLCJpZCI6ImRldl91c2VyIiwicGljdHVyZSI6Imh0dHA6Ly8xMjcuMC4wLjE6ODA4MC9hcGkvdjEvYXZhdGFyL2NjZmEyYWJkMDE2Njc2MDViNGUxZmM0ZmNiOTFiMWUxYWYzMjMyNDAuaW1hZ2UiLCJhdHRycyI6eyJhZG1pbiI6dHJ1ZSwiYmxvY2tlZCI6ZmFsc2V9fX0.6Qt5s2enBMRC-Jmsua01yViVYI95Dx6BPBMaNjj36d4
113+
106114
### get post info
107115
GET {{host}}/api/v1/info?site={{site}}&url={{url}}
108116

0 commit comments

Comments
 (0)