2022-07-06 09:01:29 +08:00
|
|
|
package migration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2023-04-24 16:39:25 +08:00
|
|
|
"strings"
|
2022-07-06 09:01:29 +08:00
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/zu1k/nali/internal/constant"
|
|
|
|
"github.com/zu1k/nali/internal/db"
|
2023-02-04 10:39:09 +08:00
|
|
|
"github.com/zu1k/nali/pkg/qqwry"
|
2022-07-06 09:01:29 +08:00
|
|
|
)
|
|
|
|
|
2023-02-04 10:39:09 +08:00
|
|
|
func migration2v7() {
|
2022-07-06 09:01:29 +08:00
|
|
|
viper.SetConfigName("config")
|
|
|
|
viper.SetConfigType("yaml")
|
2022-10-05 21:58:27 +08:00
|
|
|
viper.AddConfigPath(constant.ConfigDirPath)
|
2022-07-06 09:01:29 +08:00
|
|
|
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
if err != nil {
|
2022-07-21 10:53:26 +08:00
|
|
|
return
|
2022-07-06 09:01:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dbList := db.List{}
|
|
|
|
err = viper.UnmarshalKey("databases", &dbList)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("Config invalid:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
needOverwrite := false
|
|
|
|
for _, adb := range dbList {
|
2023-05-01 20:53:49 +08:00
|
|
|
if adb.Name == "qqwry" {
|
|
|
|
if len(adb.DownloadUrls) == 0 ||
|
|
|
|
adb.DownloadUrls[0] == "https://99wry.cf/qqwry.dat" ||
|
|
|
|
strings.Contains(adb.DownloadUrls[0], "sspanel-uim") {
|
|
|
|
needOverwrite = true
|
|
|
|
adb.DownloadUrls = qqwry.DownloadUrls
|
|
|
|
}
|
2022-07-06 09:01:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if needOverwrite {
|
|
|
|
viper.Set("databases", dbList)
|
|
|
|
err = viper.WriteConfig()
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|