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
+2 -3
View File
@@ -12,8 +12,7 @@ import (
)
var (
ConfName = "config.yml"
Conf = &AppConfigs{}
Conf = &AppConfigs{}
ExampleDb = "assets/data.example.db"
MainDb = "assets/main.db"
@@ -29,7 +28,7 @@ var (
)
func init() {
Conf = Load(ConfName)
Conf = Load("./config.json")
_, err := os.Stat(UserDb)
if err != nil {
+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
}
-67
View File
@@ -1,67 +0,0 @@
// Copyright (C) 2021-2022 YumeMichi
//
// SPDX-License-Identifier: Apache-2.0
package config
import (
"fmt"
"honoka-chan/utils"
"os"
"strconv"
"time"
"gopkg.in/yaml.v3"
)
type AppConfigs struct {
AppName string `yaml:"app_name"`
LevelDb LevelDbConfigs `yaml:"leveldb"`
Cdn CdnConfigs `yaml:"cdn"`
}
type LevelDbConfigs struct {
DataPath string `yaml:"data_path"`
}
type CdnConfigs struct {
CdnUrl string `yaml:"cdn_url"`
}
func DefaultConfigs() *AppConfigs {
return &AppConfigs{
AppName: "LL! SIF Private Server",
LevelDb: LevelDbConfigs{
DataPath: "./data/honoka-chan.db",
},
Cdn: CdnConfigs{
CdnUrl: "",
},
}
}
func Load(p string) *AppConfigs {
if !utils.PathExists(p) {
_ = DefaultConfigs().Save(p)
}
c := AppConfigs{}
err := yaml.Unmarshal([]byte(utils.ReadAllText(p)), &c)
if err != nil {
fmt.Println("Failed to load" + ConfName + ":" + err.Error())
_ = os.Rename(p, p+".backup"+strconv.FormatInt(time.Now().Unix(), 10))
_ = DefaultConfigs().Save(p)
}
c = AppConfigs{}
_ = yaml.Unmarshal([]byte(utils.ReadAllText(p)), &c)
// fmt.Println(ConfName + "loaded!")
return &c
}
func (c *AppConfigs) Save(p string) error {
data, err := yaml.Marshal(c)
if err != nil {
fmt.Println("Failed to save" + ConfName + ":" + err.Error())
return err
}
utils.WriteAllText(p, string(data))
return nil
}