Fixed creation of users + better frontend handling of permissions
This commit is contained in:
@@ -2,15 +2,21 @@ package shortcodes
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"fr.latosa-escrima/core"
|
||||
"fr.latosa-escrima/core/models"
|
||||
"fr.latosa-escrima/utils"
|
||||
)
|
||||
|
||||
func HandleShortcodes(w http.ResponseWriter, r *http.Request) {
|
||||
var shortcodes []models.Shortcode
|
||||
err := core.DB.NewSelect().Model(&shortcodes).Scan(context.Background())
|
||||
err := core.DB.NewSelect().
|
||||
Model(&shortcodes).
|
||||
Relation("Media").
|
||||
Scan(context.Background())
|
||||
if err != nil {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
@@ -19,6 +25,26 @@ func HandleShortcodes(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
scheme := "http"
|
||||
if r.TLS != nil || os.Getenv("ENVIRONMENT") != "DEV" { // Check if the request is over HTTPS
|
||||
scheme = "https"
|
||||
}
|
||||
|
||||
// Extract the host
|
||||
host := r.Host
|
||||
baseURL := fmt.Sprintf("%s://%s", scheme, host)
|
||||
if os.Getenv("ENVIRONMENT") != "DEV" {
|
||||
baseURL += "/api"
|
||||
}
|
||||
shortcodes = utils.Map(shortcodes, func(s models.Shortcode) models.Shortcode {
|
||||
if s.MediaID == nil {
|
||||
return s
|
||||
}
|
||||
s.Media.Author = nil
|
||||
s.Media.URL = fmt.Sprintf("%s/media/%s/file", baseURL, s.MediaID)
|
||||
return s
|
||||
})
|
||||
|
||||
core.JSONSuccess{
|
||||
Status: core.Success,
|
||||
Message: "Shortcodes retrieved.",
|
||||
|
||||
Reference in New Issue
Block a user