Shares #109
2 changed files with 10 additions and 0 deletions
|
@ -2,6 +2,7 @@ package incidents
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"dynatron.me/x/stillbox/internal/jsontypes"
|
"dynatron.me/x/stillbox/internal/jsontypes"
|
||||||
"dynatron.me/x/stillbox/pkg/calls"
|
"dynatron.me/x/stillbox/pkg/calls"
|
||||||
|
@ -26,6 +27,11 @@ func (inc *Incident) GetResourceName() string {
|
||||||
return entities.ResourceIncident
|
return entities.ResourceIncident
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (inc *Incident) PlaylistFilename() string {
|
||||||
|
rep := strings.NewReplacer(" ", "_", "/", "_", ":", "_")
|
||||||
|
return rep.Replace(strings.ToLower(inc.Name))
|
||||||
|
}
|
||||||
|
|
||||||
type IncidentCall struct {
|
type IncidentCall struct {
|
||||||
calls.Call
|
calls.Call
|
||||||
Notes json.RawMessage `json:"notes"`
|
Notes json.RawMessage `json:"notes"`
|
||||||
|
|
|
@ -213,9 +213,12 @@ func (ia *incidentsAPI) getCallsM3U(id ID, share *shares.Share, w http.ResponseW
|
||||||
|
|
||||||
callUrl := common.PtrTo(*ia.baseURL)
|
callUrl := common.PtrTo(*ia.baseURL)
|
||||||
urlRoot := "/api/call"
|
urlRoot := "/api/call"
|
||||||
|
filename := inc.PlaylistFilename()
|
||||||
if share != nil {
|
if share != nil {
|
||||||
urlRoot = fmt.Sprintf("/share/%s/call/", share.ID)
|
urlRoot = fmt.Sprintf("/share/%s/call/", share.ID)
|
||||||
|
filename += "_" + share.ID
|
||||||
}
|
}
|
||||||
|
filename += ".m3u"
|
||||||
|
|
||||||
b.WriteString("#EXTM3U\n\n")
|
b.WriteString("#EXTM3U\n\n")
|
||||||
for _, c := range inc.Calls {
|
for _, c := range inc.Calls {
|
||||||
|
@ -243,6 +246,7 @@ func (ia *incidentsAPI) getCallsM3U(id ID, share *shares.Share, w http.ResponseW
|
||||||
// Not a lot of agreement on which MIME type to use for non-HLS m3u,
|
// Not a lot of agreement on which MIME type to use for non-HLS m3u,
|
||||||
// let's hope this is good enough
|
// let's hope this is good enough
|
||||||
w.Header().Set("Content-Type", "audio/x-mpegurl")
|
w.Header().Set("Content-Type", "audio/x-mpegurl")
|
||||||
|
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s", filename))
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, _ = b.WriteTo(w)
|
_, _ = b.WriteTo(w)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue