Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
2024-02-15 v1.0.3-pre
Browse files Browse the repository at this point in the history
  • Loading branch information
ZxwyWebSite committed Feb 15, 2024
1 parent 32c2617 commit 2dea36c
Show file tree
Hide file tree
Showing 40 changed files with 1,685 additions and 610 deletions.
10 changes: 8 additions & 2 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"

"github.com/ZxwyWebSite/ztool"
"github.com/ZxwyWebSite/ztool/logs"
"github.com/ZxwyWebSite/ztool/zcypt"
"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -43,9 +44,14 @@ func loadFileLoger() {
if env.Config.Main.LogPath != `` {
lg := env.Loger.NewGroup(`FileLoger`)
printout := env.Config.Main.Print // || env.Config.Main.Debug
_, do, err := env.Loger.SetOutFile(ztool.Str_FastConcat(env.RunPath, env.Config.Main.LogPath), printout)
f, do, err := env.Loger.SetOutFile(ztool.Str_FastConcat(env.RunPath, env.Config.Main.LogPath), printout)
if err == nil {
env.Defer.Add(do)
// env.Defer.Add(do)
env.Defer.Add(func() { do(); f.Close() })
env.Tasker.Add(`flog_flush`, func(loger *logs.Logger, now int64) error {
loger.Debug(`已写入文件并清理日志缓存`)
return do()
}, 3600, false)
gin.DefaultWriter = env.Loger.GetOutput()
gin.ForceConsoleColor()
// lg.Info(`文件日志初始化成功`)
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
+ 视频教程:[使用教程.mp4](https://r2eu.zxwy.link/gh/lx-source/v1.0.2-b0.1/%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B.mp4)
<!-- + *手持两把锟斤拷,口中疾呼烫烫烫。 脚踏千朵屯屯屯,笑看万物锘锘锘。* -->

### 注意
+ 不保证内置源可用性,如需长期使用请自备会员账号
+ 音源最好留着自己用,你非要当大好人当我没说(由于传播导致的账号被封与本项目无关)

### 使用
#### 服务端
+ 到Release下载对应平台可执行文件运行
Expand Down
2 changes: 1 addition & 1 deletion src/caches/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *Query) Query() string {
return c.query
}

// 分割查询字符串
// 分割查询字符串 (已弃用)
/*
kg: 分割 Hash-Album 如 "6DC276334F56E22BE2A0E8254D332B45-13097991"
tx: 分割 songmid-strMediaMid 如 "002fktJg3cmSpC-000V6uuv35Cwnh"
Expand Down
1 change: 1 addition & 0 deletions src/database/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package database
59 changes: 59 additions & 0 deletions src/database/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package database

// 结构表
// type (
// PublicKeys struct {
// ID string `json:"id" gorm:"primaryKey"`
// }
// // 音乐
// MusicItem struct {
// ID string `json:"id" gorm:"primaryKey"` // 唯一ID
// Name string `json:"name" gorm:"column:name"` //
// // Source string `json:"source" gorm:"-:all"`
// }
// // 作者
// ArtistItem struct {
// ID string `json:"id" gorm:"primaryKey"`
// Name string `json:"name" gorm:"column:name"`
// }
// // 歌词
// LyricItem struct {
// ID string `json:"id" gorm:"primaryKey"`
// Lyric string `json:"lyric" gorm:"column:lyric"` // 歌曲歌词
// TLyric string `json:"tlyric" gorm:"column:tlyric"` // 翻译歌词,没有可为 null
// RLyric string `json:"rlyric" gorm:"column:rlyric"` // 罗马音歌词,没有可为 null
// LxLyric string `json:"lxlyric" gorm:"column:lxlyric"` // lx 逐字歌词,没有可为 null
// // 歌词格式为 [分钟:秒.毫秒]<开始时间(基于该句),持续时间>歌词文字
// // 例如: [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"`
// }
// )

// 分源表
// type (
// // Music
// WyMusic MusicItem
// MgMusic MusicItem
// KwMusic MusicItem
// KgMusic MusicItem
// TxMusic MusicItem
// LxMusic MusicItem
// // Artist
// WyArtist ArtistItem
// MgArtist ArtistItem
// KwArtist ArtistItem
// KgArtist ArtistItem
// TxArtist ArtistItem
// LxArtist ArtistItem
// // Lyric
// WyLyric LyricItem
// MgLyric LyricItem
// KwLyric LyricItem
// KgLyric LyricItem
// TxLyric LyricItem
// LxLyric LyricItem
// )
42 changes: 27 additions & 15 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.2-dev`
Version = `1.0.3-pre`
)

var (
Expand Down Expand Up @@ -78,7 +78,7 @@ type (
Proxy_Address string `comment:"代理地址 (支持http, socks)"`
// 验证
MusicIdVerify bool `comment:"(beta) 验证音乐ID可用性"`
ForceFallback bool `comment:"忽略音质限制,强制获取试听音频"`
ForceFallback bool `comment:"忽略音质限制,强制返回链接(部分支持)"`
// 总开关(解决部分源无法彻底禁用问题)?
Enable_Wy bool `comment:"是否开启小芸源"`
Enable_Mg bool `comment:"是否开启小蜜源"`
Expand All @@ -97,11 +97,17 @@ type (
Wy_Api_Address string `comment:"NeteaseCloudMusicApi项目地址"`
Wy_Api_Cookie string `comment:"账号cookie数据"`
// wy refresh
// Wy_Refresh_Enable bool `comment:"是否启用刷新登录"`
// Wy_Refresh_Interval int64 `comment:"下次刷新时间 (由程序维护)"`
Wy_Refresh_Enable bool `comment:"是否启用刷新登录"`
Wy_Refresh_Interval int64 `comment:"下次刷新时间 (由程序维护)"`

// mg (暂未实现)
Mg_Enable bool `comment:"是否启用小蜜源"`
// mg
Mg_Enable bool `comment:"是否启用小蜜源"`
Mg_Mode string `comment:"获取方式 0: builtin, 1: custom"`
// mg custom
Mg_Usr_VerId string `comment:"field user.aversionid"`
Mg_Usr_Token string `comment:"field user.token"`
Mg_Usr_OSVer string `comment:"field user.osversion"`
Mg_Usr_ReqUA string `comment:"field user.useragent"`

// kw
Kw_Enable bool `comment:"是否启用小蜗源"`
Expand All @@ -114,8 +120,10 @@ type (
Kw_Des_Type string `comment:"返回格式 0: text, 1: json"`
Kw_Des_Header string `comment:"请求头 User-Agent"`

// kg (暂未实现)
Kg_Enable bool `comment:"是否启用小枸源"`
// kg
Kg_Enable bool `comment:"是否启用小枸源"`
Kg_token string `comment:"field user.token"`
Kg_userId string `comment:"field user.userid"`

// tx
Tx_Enable bool `comment:"是否启用小秋源"`
Expand Down Expand Up @@ -201,22 +209,26 @@ var (
Enable_Kw: true,
Enable_Kg: true,
Enable_Tx: true,
Enable_Lx: true,
Enable_Lx: false,
},
Custom: Conf_Custom{
Wy_Enable: true,
Wy_Mode: `builtin`,
Wy_Api_Type: `native`,
// Wy_Refresh_Interval: 1633622400,
Wy_Enable: true,
Wy_Mode: `builtin`,
Wy_Api_Type: `native`,
Wy_Refresh_Interval: 1633622400,

Mg_Enable: true,
Mg_Enable: true,
Mg_Mode: `builtin`,
Mg_Usr_OSVer: `10`,
Mg_Usr_ReqUA: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36`,

Kw_Enable: true,
Kw_Mode: `kwdes`,
Kw_Des_Type: `json`,
Kw_Des_Header: `okhttp/3.10.0`,

Kg_Enable: true,
Kg_Enable: false,
Kg_userId: `0`,

Tx_Enable: false,
Tx_Refresh_Enable: false,
Expand Down
1 change: 1 addition & 0 deletions src/middleware/auth/ratelimit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package auth
55 changes: 35 additions & 20 deletions src/middleware/resp/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// 统一输出
/*
返回码对应表:
返回码对应表 (参考Python版)
0: http.StatusOK, // [200] 成功
1: http.StatusForbidden, // [403] IP被封禁
2: http.StatusServiceUnavailable, // [503] 获取失败
Expand All @@ -21,38 +21,47 @@ import (
type Resp struct {
Code int `json:"code"` // 状态码 为兼容内置源设置 暂无实际作用 (1.0.2后已兼容Python版定义)
Msg string `json:"msg"` // 提示or报错信息
Data string `json:"data"` // 音乐URL
Ext string `json:"ext,omitempty"` // 其它信息
}

// 返回码对应列表 (参考Python版)
var statusMap = map[int]int{
0: http.StatusOK, // 成功
1: http.StatusForbidden, // IP被封禁
2: http.StatusServiceUnavailable, // 获取失败
3: http.StatusUnauthorized, // 验证失败
4: http.StatusInternalServerError, // 服务器内部错误
5: http.StatusTooManyRequests, // 请求过于频繁
6: http.StatusBadRequest, // 参数错误
Data any `json:"data"` // 音乐URL
Ext any `json:"ext,omitempty"` // 其它信息
}

// 获取失败默认音频
var ErrMp3 = `https://r2eu.zxwy.link/gh/lx-source/static/error.mp3`

// 返回请求
/*
注:Code不为0时调用c.Abort()终止Handler
*/
func (o *Resp) Execute(c *gin.Context) {
status, ok := statusMap[o.Code]
if !ok {
// StatusCode转换 (小分支switch快, 大分支map快)
var status int
switch o.Code {
case 0:
status = http.StatusOK
}
if o.Code != 0 {
if o.Code == 2 /*&& o.Data == ``*/ {
case 1:
status = http.StatusForbidden
case 2:
status = http.StatusServiceUnavailable
if o.Data == nil || o.Data == `` {
o.Data = ErrMp3
}
c.Abort()
case 3:
status = http.StatusUnauthorized
case 4:
status = http.StatusInternalServerError
case 5:
status = http.StatusTooManyRequests
case 6:
status = http.StatusBadRequest
default:
status = http.StatusOK
}
// if o.Code != 0 {
// if o.Code == 2 /*&& o.Data == ``*/ {
// o.Data = ErrMp3
// }
// c.Abort()
// }
c.JSON(status, o)
}

Expand All @@ -65,3 +74,9 @@ func Wrap(c *gin.Context, f func() *Resp) {
r.Execute(c)
}
}

// func Wrap2(c *gin.Context, p []string, f func([]string) *Resp) {
// if r := f(util.ParaArr(c)); r != nil {
// r.Execute(c)
// }
// }
23 changes: 23 additions & 0 deletions src/middleware/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ func ParaMap(c *gin.Context) map[string]string {
return parms
}

// 将路由参数转为Array
/*
ParaArr(c, `id`, `s`, `xxx`) => [
`musicId`,
`source`,
``,
]
*/
func ParaArr(c *gin.Context, s ...string) []string {
parmlen := len(c.Params)
parslen := len(s)
out := make([]string, parslen)
for im := 0; im < parmlen; im++ {
obj := c.Params[im]
for is := 0; is < parslen; is++ {
if s[is] == obj.Key {
out[is] = obj.Value
}
}
}
return out
}

var pathCache string

func init() {
Expand Down
Loading

0 comments on commit 2dea36c

Please sign in to comment.