2020-11-09 17:33:56 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func allPostAliases() ([]string, error) {
|
|
|
|
var aliases []string
|
|
|
|
rows, err := appDbQuery("select distinct value from post_parameters where parameter = 'aliases' and value != path")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for rows.Next() {
|
|
|
|
var path string
|
|
|
|
_ = rows.Scan(&path)
|
2021-02-16 15:26:21 +00:00
|
|
|
if path != "" {
|
|
|
|
aliases = append(aliases, path)
|
|
|
|
}
|
2020-11-09 17:33:56 +00:00
|
|
|
}
|
|
|
|
return aliases, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func servePostAlias(w http.ResponseWriter, r *http.Request) {
|
|
|
|
row, err := appDbQueryRow("select path from post_parameters where parameter = 'aliases' and value = @alias", sql.Named("alias", r.URL.Path))
|
|
|
|
if err != nil {
|
2020-12-24 09:09:34 +00:00
|
|
|
serveError(w, r, err.Error(), http.StatusInternalServerError)
|
2020-11-09 17:33:56 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
var path string
|
2021-02-08 17:51:07 +00:00
|
|
|
if err := row.Scan(&path); err == sql.ErrNoRows {
|
2020-11-09 17:33:56 +00:00
|
|
|
serve404(w, r)
|
|
|
|
return
|
|
|
|
} else if err != nil {
|
2020-12-24 09:09:34 +00:00
|
|
|
serveError(w, r, err.Error(), http.StatusInternalServerError)
|
2020-11-09 17:33:56 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
http.Redirect(w, r, path, http.StatusFound)
|
|
|
|
}
|