2019-01-31 15:06:11 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-02-05 07:10:59 +08:00
|
|
|
"net/http"
|
2019-01-31 15:06:11 +08:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func domainExportDownloadHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
exportHex := r.FormValue("exportHex")
|
|
|
|
if exportHex == "" {
|
|
|
|
fmt.Fprintf(w, "Error: empty exportHex\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
statement := `
|
|
|
|
SELECT domain, binData, creationDate
|
|
|
|
FROM exports
|
|
|
|
WHERE exportHex = $1;
|
|
|
|
`
|
|
|
|
row := db.QueryRow(statement, exportHex)
|
|
|
|
|
|
|
|
var domain string
|
|
|
|
var binData []byte
|
|
|
|
var creationDate time.Time
|
|
|
|
if err := row.Scan(&domain, &binData, &creationDate); err != nil {
|
|
|
|
fmt.Fprintf(w, "Error: that exportHex does not exist\n")
|
|
|
|
}
|
|
|
|
|
2020-03-31 18:08:23 +08:00
|
|
|
w.Header().Set("Content-Disposition", fmt.Sprintf(`inline; filename="%s-%v.json.gz"`, domain, creationDate.Unix()))
|
2019-01-31 15:06:11 +08:00
|
|
|
w.Write(binData)
|
|
|
|
}
|