2018-10-25 15:51:47 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-11-02 19:03:00 +01:00
|
|
|
"bytes"
|
|
|
|
"encoding/json"
|
2018-10-25 15:51:47 +02:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/labstack/echo"
|
|
|
|
)
|
|
|
|
|
2018-11-02 19:03:00 +01:00
|
|
|
type configScript struct {
|
|
|
|
RootURL string `json:"rootURL"`
|
|
|
|
UploadURI string `json:"uploadURL"`
|
|
|
|
FromEmail string `json:"fromEmail"`
|
|
|
|
Messengers []string `json:"messengers"`
|
|
|
|
}
|
|
|
|
|
2018-10-25 15:51:47 +02:00
|
|
|
// handleGetStats returns a collection of general statistics.
|
|
|
|
func handleGetStats(c echo.Context) error {
|
|
|
|
app := c.Get("app").(*App)
|
|
|
|
return c.JSON(http.StatusOK, okResp{app.Runner.GetMessengerNames()})
|
|
|
|
}
|
2018-11-02 19:03:00 +01:00
|
|
|
|
|
|
|
// handleGetConfigScript returns general configuration as a Javascript
|
|
|
|
// variable that can be included in an HTML page directly.
|
|
|
|
func handleGetConfigScript(c echo.Context) error {
|
|
|
|
var (
|
|
|
|
app = c.Get("app").(*App)
|
|
|
|
out = configScript{
|
|
|
|
RootURL: app.Constants.RootURL,
|
|
|
|
UploadURI: app.Constants.UploadURI,
|
|
|
|
FromEmail: app.Constants.FromEmail,
|
|
|
|
Messengers: app.Runner.GetMessengerNames(),
|
|
|
|
}
|
|
|
|
|
|
|
|
b = bytes.Buffer{}
|
|
|
|
j = json.NewEncoder(&b)
|
|
|
|
)
|
|
|
|
|
|
|
|
b.Write([]byte(`var CONFIG = `))
|
|
|
|
j.Encode(out)
|
|
|
|
return c.Blob(http.StatusOK, "application/javascript", b.Bytes())
|
|
|
|
}
|