Skip to content

Commit

Permalink
2024-03-16 v1.0.3-rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
ZxwyWebSite committed Mar 16, 2024
1 parent 0b44b07 commit 1ddc08d
Show file tree
Hide file tree
Showing 34 changed files with 2,160 additions and 1,267 deletions.
2 changes: 1 addition & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func doCompile(v_os, v_arch, v_archv, v_cc string) error {
pname := filepath.Clean(ztool.Str_FastConcat(args_path, fname))
cmd := ztool.Str_FastConcat(
`go build -o `, pname,
` -gcflags=-trimpath="`, workDir, `" -asmflags=-trimpath="`, workDir, `" -buildvcs=false`,
` -gcflags=-trimpath="`, workDir, `" -asmflags=-trimpath="`, workDir, `" -trimpath -buildvcs=false`,
` -ldflags "-s -w -linkmode external" -tags "go_json"`, // go_json | json(std) | jsoniter | sonic
)
// 输出要执行的命令
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/ZxwyWebSite/ztool v0.0.1
github.com/gin-contrib/gzip v0.0.6
github.com/gin-gonic/gin v1.9.1
github.com/mattn/go-colorable v0.1.13 // indirect
)

require (
Expand All @@ -23,6 +22,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -32,8 +32,9 @@ require (
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,17 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
Expand Down
52 changes: 38 additions & 14 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"lx-source/src/caches"
"lx-source/src/caches/localcache"
"lx-source/src/env"
"lx-source/src/sources"
"lx-source/src/sources/builtin"

// "lx-source/src/sources"
// "lx-source/src/sources/builtin"
"net/http"
stdurl "net/url"
"path/filepath"
Expand Down Expand Up @@ -64,6 +65,29 @@ func loadFileLoger() {

// 初始化基础功能
func initMain() {
// 载入内存缓存
storepath := env.RunPath + env.Config.Main.Store
env.Cache.MustRestore(storepath)
env.Defer.Add(func() { env.Cache.MustPersist(storepath) })
env.Tasker.Add(`memo_flush`, func(*logs.Logger, int64) error {
return env.Cache.Persist(storepath)
}, 3600, false)

// 初始化数据库
// idb := env.Loger.NewGroup(`InitDB`)
// switch `sqlite` {
// case `memo`:
// break
// case `sqlite`:
// err := database.InitDB(`data/data.db`)
// if err != nil {
// idb.Error(`数据库载入失败: %s`, err)
// }
// default:
// idb.Error(`未定义的数据库模式,请检查配置 [DataBase].Mode`)
// }
// idb.Free()

// 初始化代理
ipr := env.Loger.NewGroup(`InitProxy`)
switch env.Config.Source.FakeIP_Mode {
Expand Down Expand Up @@ -167,16 +191,16 @@ func initMain() {
icl.Free()

// 初始化音乐源
ise := env.Loger.NewGroup(`InitSource`)
switch env.Config.Source.Mode {
case `0`, `off`:
break
case `1`, `builtin`:
sources.UseSource = &builtin.Source{}
case `2`, `custom`:
ise.Fatal(`暂未实现账号解析源`)
default:
ise.Error(`未定义的音乐源,请检查配置 [Source].Mode,本次启动禁用内置源`)
}
ise.Free()
// ise := env.Loger.NewGroup(`InitSource`)
// switch env.Config.Source.Mode {
// case `0`, `off`:
// break
// case `1`, `builtin`:
// sources.UseSource = &builtin.Source{}
// case `2`, `custom`:
// ise.Fatal(`暂未实现账号解析源`)
// default:
// ise.Error(`未定义的音乐源,请检查配置 [Source].Mode,本次启动禁用内置源`)
// }
// ise.Free()
}
37 changes: 37 additions & 0 deletions src/database/driver.go
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
//go:build gorm

package database

// import (
// "lx-source/src/database/modules"
// "lx-source/src/env"
// "lx-source/src/sources"

// "gorm.io/gorm"
// )

// var DB *gorm.DB

// func InitDB(dsn string) (err error) {
// loger := env.Loger.NewGroup(`InitDB`)
// defer loger.Free()
// DB, err = gorm.Open(modules.Sqlite(dsn), &gorm.Config{})
// if err == nil {
// for _, typ := range []struct {
// Name string
// Type interface{}
// }{
// {Name: T_music, Type: &XMusicItem{}},
// {Name: T_lyric, Type: &XLyricItem{}},
// } {
// for _, src := range sources.S_al {
// err = DB.Table(src + `_` + typ.Name).AutoMigrate(typ.Type)
// if err != nil {
// return
// }
// }
// }
// }
// return
// }

// type Driver struct{}
9 changes: 9 additions & 0 deletions src/database/modules/sqlite_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build cgo && gorm

package modules

// import (
// "gorm.io/driver/sqlite"
// )

// var Sqlite = sqlite.Open
9 changes: 9 additions & 0 deletions src/database/modules/sqlite_etc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !cgo && gorm

package modules

// import (
// "github.com/glebarez/sqlite"
// )

// var Sqlite = sqlite.Open
87 changes: 73 additions & 14 deletions src/database/types.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,71 @@
//go:build gorm

package database

// MusicFree 数据结构
// type (
// // 其他
// IExtra map[string]interface{}
// // 音乐
// IMusicItem struct {
// Artist string `json:"artist"` // 作者
// Title string `json:"title"` // 歌曲标题
// Duration int `json:"duration,omitempty"` // 时长(s)
// Album string `json:"album,omitempty"` // 专辑名
// Artwork string `json:"artwork,omitempty"` // 专辑封面图
// Url string `json:"url,omitempty"` // 默认音源
// Lrc string `json:"lrc,omitempty"` // 歌词URL
// RawLrc string `json:"rawLrc,omitempty"` // 歌词文本(lrc格式 带时间戳)
// Other IExtra `json:"extra,omitempty"` // 其他
// }
// // 歌单
// IMusicSheetItem struct {
// Artwork string `json:"artwork,omitempty"` // 封面图
// Title string `json:"title"` // 标题
// Description string `json:"description,omitempty"` // 描述
// WorksNum int `json:"worksNum,omitempty"` // 作品总数
// PlayCount int `json:"playCount,omitempty"` // 播放次数
// MusicList []IMusicItem `json:"musicList,omitempty"` // 播放列表
// CreateAt int64 `json:"createAt,omitempty"` // 歌单创建日期
// Artist string `json:"artist,omitempty"` // 歌单作者
// Other IExtra `json:"extra,omitempty"` // 其他
// }
// // 专辑
// IAlbumItem IMusicSheetItem
// // 作者
// IArtistItem struct {
// Platform string `json:"platform,omitempty"` // 插件名
// ID interface{} `json:"id"` // 唯一id
// Name string `json:"name"` // 姓名
// Fans int `json:"fans,omitempty"` // 粉丝数
// Description string `json:"description,omitempty"` // 简介
// Avatar string `json:"avatar,omitempty"` // 头像
// WorksNum int `json:"worksNum,omitempty"` // 作品数目
// MusicList []IMusicItem `json:"musicList,omitempty"` // 作者的音乐列表
// AlbumList []IAlbumItem `json:"albumList,omitempty"` // 作者的专辑列表
// Other IExtra `json:"extra,omitempty"` // 其他
// }
// )

// 结构表
// type (
// PublicKeys struct {
// ID string `json:"id" gorm:"primaryKey"`
// // 重复
// XPublicKeys struct {
// ID string `json:"id" gorm:"primaryKey"` // 唯一ID
// Exp int64 `json:"exp" gorm:"column:exp"` // 过期时间
// }
// // 音乐
// MusicItem struct {
// ID string `json:"id" gorm:"primaryKey"` // 唯一ID
// Name string `json:"name" gorm:"column:name"` //
// // Source string `json:"source" gorm:"-:all"`
// XMusicItem struct {
// ID string `json:"id" gorm:"primaryKey"` // 唯一ID
// Name string `json:"name" gorm:"column:name"` // 歌曲名称
// }
// // 作者
// ArtistItem struct {
// ID string `json:"id" gorm:"primaryKey"`
// Name string `json:"name" gorm:"column:name"`
// }
// // XArtistItem struct {
// // ID string `json:"id" gorm:"primaryKey"`
// // Name string `json:"name" gorm:"column:name"`
// // }
// // 歌词
// LyricItem struct {
// XLyricItem struct {
// ID string `json:"id" gorm:"primaryKey"`
// Lyric string `json:"lyric" gorm:"column:lyric"` // 歌曲歌词
// TLyric string `json:"tlyric" gorm:"column:tlyric"` // 翻译歌词,没有可为 null
Expand All @@ -27,12 +75,23 @@ package database
// // 例如: [00:00.000]<0,36>测<36,36>试<50,60>歌<80,75>词
// }
// // 视频
// MovieItem struct {
// ID string `json:"id" gorm:"primaryKey"`
// Name string `json:"name" gorm:"column:name"`
// // XMovieItem struct {
// // ID string `json:"id" gorm:"primaryKey"`
// // Name string `json:"name" gorm:"column:name"`
// // }
// // 链接
// XLinkItem struct {
// ID string `json:"id" gorm:"primaryKey"`
// }
// )

// const (
// T_artist = `artist`
// T_detail = `detail`
// T_lyric = `lyric`
// T_music = `music`
// )

// 分源表
// type (
// // Music
Expand Down
12 changes: 9 additions & 3 deletions src/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
Version = `1.0.3-rc1`
Version = `1.0.3-rc2`
)

var (
Expand All @@ -37,6 +37,8 @@ type (
// FFConv bool `comment:"(实验性) 使用FFMpeg修复音频(本地缓存)"`
NgProxy bool `comment:"兼容反向代理(beta)"`
Timeout int64 `comment:"网络请求超时(单位:秒,海外服务器可适当调大)"`

Store string `comment:"内存缓存持久化文件地址"`
}
// 接口
Conf_Apis struct {
Expand Down Expand Up @@ -69,7 +71,7 @@ type (
}
// 来源
Conf_Source struct {
Mode string `comment:"音乐来源 0: off(关闭 仅本地), 1: builtin(内置), 2: custom(登录账号 暂不支持)"`
// Mode string `comment:"音乐来源 0: off(关闭 仅本地), 1: builtin(内置), 2: custom(登录账号 暂不支持)"`
// 伪装IP
FakeIP_Mode string `comment:"伪装IP模式 0: off(关闭), 1: req(传入值), 2: val(静态)"`
FakeIP_Value string `comment:"静态伪装IP"`
Expand Down Expand Up @@ -108,6 +110,9 @@ type (
Mg_Usr_Token string `comment:"field user.token"`
Mg_Usr_OSVer string `comment:"field user.osversion"`
Mg_Usr_ReqUA string `comment:"field user.useragent"`
// mg refresh
Mg_Refresh_Enable bool `comment:"是否启用Cookie保活"`
Mg_Refresh_Interval int64 `comment:"下次运行时间 (自动更新)"`

// kw
Kw_Enable bool `comment:"是否启用小蜗源"`
Expand Down Expand Up @@ -193,6 +198,7 @@ var (
Print: true,
SysLev: false,
Timeout: 30,
Store: `/data/memo.bin`,
},
Apis: Conf_Apis{
// BindAddr: `http://192.168.10.22:1011/`,
Expand All @@ -209,7 +215,7 @@ var (
// BanList_White: []string{`127.0.0.1`},
},
Source: Conf_Source{
Mode: `builtin`,
// Mode: `builtin`,
FakeIP_Mode: `0`,
FakeIP_Value: `192.168.10.2`,
Proxy_Enable: false,
Expand Down
5 changes: 5 additions & 0 deletions src/middleware/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package auth

import (
"encoding/gob"
"lx-source/src/env"
"lx-source/src/middleware/resp"
"sync/atomic"
Expand All @@ -17,6 +18,10 @@ type (
}
)

func init() {
gob.Register(RateLimit{})
}

func InitHandler(h gin.HandlerFunc) (out []gin.HandlerFunc) {
loger := env.Loger.NewGroup(`AuthHandler`)
// RateLimit 速率限制
Expand Down
6 changes: 6 additions & 0 deletions src/server/api_music.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func musicHandler(c *gin.Context) {
// 定位源方法
switch pm {
case `url`, `link`:
// if !active && pq != sources.Q_128k {
// out.Msg = `未激活源仅可试听128k音质`
// return out
// }
// 查询文件缓存
var cstat bool
if caches.UseCache != nil {
Expand Down Expand Up @@ -127,6 +131,8 @@ func musicHandler(c *gin.Context) {
} else {
out.Msg = cacheMISS
}
} else {
loger.Warn(`发生错误: %s`, out.Msg)
}
// 无法获取直链 直接返回原链接
env.Cache.Set(cquery, out.Data, source.Exp()-300)
Expand Down
2 changes: 2 additions & 0 deletions src/server/app_lxmusic.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build extapp

package server

import (
Expand Down
Loading

0 comments on commit 1ddc08d

Please sign in to comment.