Shortcodes

This commit is contained in:
cdricms
2025-02-10 08:52:32 +01:00
parent a7ad045631
commit 8e87d834bc
20 changed files with 485 additions and 71 deletions

View File

@@ -2,6 +2,7 @@ package shortcodes
import (
"context"
"fmt"
"net/http"
"fr.latosa-escrima/core"
@@ -14,6 +15,7 @@ func HandleShortcode(w http.ResponseWriter, r *http.Request) {
err := core.DB.NewSelect().
Model(&shortcode).
Where("code = ?", code).
Relation("Media").
Limit(1).
Scan(context.Background())
if err != nil {
@@ -24,6 +26,17 @@ func HandleShortcode(w http.ResponseWriter, r *http.Request) {
return
}
scheme := "http"
if r.TLS != nil { // Check if the request is over HTTPS
scheme = "https"
}
// Extract the host
host := r.Host
baseURL := fmt.Sprintf("%s://%s", scheme, host)
if shortcode.Media != nil {
shortcode.Media.URL = fmt.Sprintf("%s/media/%s/file", baseURL, shortcode.Media.ID)
}
core.JSONSuccess{
Status: core.Success,
Message: "Shortcode found",