Sync updates with elichika

As of https://github.com/YumeMichi/elichika/commit/81a78e964dcdb8bb2d123237f966f95e7fba190e

Signed-off-by: Yuan Si <do4suki@gmail.com>
This commit is contained in:
2023-07-20 00:21:22 +08:00
parent 4146728579
commit 81e97cf997
43 changed files with 40727 additions and 35491 deletions
+53
View File
@@ -0,0 +1,53 @@
package config
import (
"encoding/json"
"honoka-chan/utils"
"os"
"strconv"
"time"
)
type AppConfigs struct {
AppName string `json:"app_name"`
Settings Settings `json:"settings"`
}
type Settings struct {
SifCdnServer string `json:"sif_cdn_server"`
AsCdnServer string `json:"as_cdn_server"`
}
func DefaultConfigs() *AppConfigs {
return &AppConfigs{
AppName: "honoka-chan",
Settings: Settings{
SifCdnServer: "http://192.168.1.123/static",
AsCdnServer: "http://192.168.1.123/static",
},
}
}
func Load(p string) *AppConfigs {
if !utils.PathExists(p) {
_ = DefaultConfigs().Save(p)
}
c := AppConfigs{}
err := json.Unmarshal([]byte(utils.ReadAllText(p)), &c)
if err != nil {
_ = os.Rename(p, p+".backup"+strconv.FormatInt(time.Now().Unix(), 10))
_ = DefaultConfigs().Save(p)
}
c = AppConfigs{}
_ = json.Unmarshal([]byte(utils.ReadAllText(p)), &c)
return &c
}
func (c *AppConfigs) Save(p string) error {
data, err := json.Marshal(c)
if err != nil {
return err
}
utils.WriteAllText(p, string(data))
return nil
}