44 "encoding/json"
55 "fmt"
66 "net/http"
7+ "os"
78 "strconv"
89 "sync"
910 "time"
@@ -14,6 +15,8 @@ import (
1415 "github.com/sirupsen/logrus"
1516)
1617
18+ const LOGDY_CONFIG_ENV_FILE = "logdy.config.json"
19+
1720func handleCheckPass (uiPass string ) func (w http.ResponseWriter , r * http.Request ) {
1821 return func (w http.ResponseWriter , r * http.Request ) {
1922 utils .Logger .Debug ("/api/check-pass" )
@@ -43,8 +46,15 @@ func handleStatus(config *Config) func(w http.ResponseWriter, r *http.Request) {
4346
4447 configStr := ""
4548 if config .ConfigFilePath != "" {
46- utils .Logger .Debug ("Reading config file" )
49+ utils .Logger .WithFields (logrus.Fields {
50+ "file" : config .ConfigFilePath ,
51+ }).Debug ("Reading config file" )
4752 configStr = utils .LoadFile (config .ConfigFilePath )
53+ } else if utils .FileExists (LOGDY_CONFIG_ENV_FILE ) {
54+ utils .Logger .WithFields (logrus.Fields {
55+ "file" : LOGDY_CONFIG_ENV_FILE ,
56+ }).Info ("Loading local env file" )
57+ configStr = utils .LoadFile (LOGDY_CONFIG_ENV_FILE )
4858 }
4959
5060 newVersion , _ := utils .IsNewVersionAvailable ()
@@ -231,6 +241,40 @@ func handleWs(uiPass string, clients *ClientsStruct) func(w http.ResponseWriter,
231241 }
232242}
233243
244+ func handleClientSettingsSave () func (w http.ResponseWriter , r * http.Request ) {
245+ return func (w http.ResponseWriter , r * http.Request ) {
246+ type Req struct {
247+ Layout string `json:"layout"`
248+ }
249+
250+ var p Req
251+
252+ err := json .NewDecoder (r .Body ).Decode (& p )
253+ if err != nil {
254+ http .Error (w , err .Error (), http .StatusBadRequest )
255+ return
256+ }
257+
258+ err = os .WriteFile (LOGDY_CONFIG_ENV_FILE , []byte (p .Layout ), 0644 )
259+ if err != nil {
260+ http .Error (w , err .Error (), http .StatusInternalServerError )
261+ return
262+ }
263+
264+ path , err := os .Getwd ()
265+ if err != nil {
266+ http .Error (w , err .Error (), http .StatusInternalServerError )
267+ return
268+ }
269+
270+ w .Header ().Set ("Content-Type" , "application/json" )
271+ w .WriteHeader (http .StatusOK )
272+ json .NewEncoder (w ).Encode (map [string ]string {
273+ "location" : path + string (os .PathSeparator ) + LOGDY_CONFIG_ENV_FILE ,
274+ })
275+ }
276+ }
277+
234278func handleClientStatus (clients * ClientsStruct ) func (w http.ResponseWriter , r * http.Request ) {
235279 return func (w http.ResponseWriter , r * http.Request ) {
236280 cl := getClientOrErr (r , w , clients )
0 commit comments