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

Commit

Permalink
2024-04-30 v1.0.3.0430
Browse files Browse the repository at this point in the history
  • Loading branch information
ZxwyWebSite committed Apr 30, 2024
1 parent 1ddc08d commit e402c10
Show file tree
Hide file tree
Showing 19 changed files with 500 additions and 102 deletions.
36 changes: 20 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
module lx-source

go 1.21.4
go 1.21

require (
github.com/ZxwyWebSite/ztool v0.0.1
github.com/gin-contrib/gzip v0.0.6
github.com/gin-contrib/gzip v1.0.0
github.com/gin-gonic/gin v1.9.1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
)

require (
github.com/bytedance/sonic v1.10.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/bytedance/sonic v1.11.5 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.3 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/cors v1.7.1
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
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/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // 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
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
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.17.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
115 changes: 41 additions & 74 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func init() {
// }
fp.Info(`设置默认文件权限为 %o (%v)`, *perm, ztool.Fbj_DefPerm).Free()
}
parseEtag(etag)
env.Cfg.MustInit(confPath)
parseEtag(etag)
// fmt.Printf("%+v\n", env.Config)
env.Loger.NewGroup(`ServHello`).Info(`欢迎使用 LX-SOURCE 洛雪音乐自定义源`).Free()
if !env.Config.Main.Debug {
Expand Down
59 changes: 59 additions & 0 deletions menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package main

import (
"lx-source/src/env"
wm "lx-source/src/sources/custom/wy/modules"
"strings"
"time"

qrcode "github.com/skip2/go-qrcode"
)

func parseEtag(etag *string) {
Expand All @@ -15,12 +20,66 @@ func parseEtag(etag *string) {
case `menu`:
loger.Fatal(`暂不支持交互菜单,敬请期待...`)
// menuMian()
case `wyqr`:
wyQrLogin()
default:
loger.Fatal(`未知参数:%q`, *etag)
}
loger.Free()
}

// 网易云扫码登录
func wyQrLogin() {
loger := env.Loger.NewGroup(`WyQrLogin`)
defer loger.Free()
loger.Info(`执行模块: 网易云扫码登录`)
res, err := wm.LoginQrKey()
if err != nil {
loger.Fatal(`无法创建请求: %s`, err)
}
key := res.Body[`unikey`].(string)
loger.Info(`创建请求成功: %v`, key)

link := wm.LoginQrCreate(key)
qr, err := qrcode.New(link, qrcode.Low)
if err != nil {
loger.Fatal(`无法生成二维码: %s`, err)
}
loger.Info("\n请使用网易云音乐手机APP扫描以下二维码授权登录:\n%v", qr.ToSmallString(false))

for {
time.Sleep(time.Second * 5)
res, err = wm.LoginQrCheck(key)
if err != nil {
loger.Error(`检测状态失败: %s`, err)
continue
}
msg := res.Body[`message`].(string)
switch msg {
case `等待扫码`:
loger.Info(msg)
case `授权中`:
loger.Info(`扫码成功: %q, 请在手机上确认登录`, res.Body[`nickname`])
case `授权登陆成功`:
loger.Info(`授权成功`)
env.Config.Custom.Wy_Enable = true
env.Config.Custom.Wy_Mode = `163api`
env.Config.Custom.Wy_Api_Cookie = strings.Join(res.Cookie, `; `)
env.Config.Custom.Wy_Refresh_Enable = true
if err := env.Cfg.Save(``); err != nil {
loger.Error(`配置保存失败: %s`, err)
} else {
loger.Info(`配置保存成功`)
}
return
case `二维码不存在或已过期`:
loger.Fatal(`授权请求超时,请重试!`)
default:
loger.Fatal(`未知状态: %v`, msg)
}
}
}

// func menuMian() {
// app := menu.NewApp(`Lx-Source`)
// app.Data = menu.Data{
Expand Down
8 changes: 7 additions & 1 deletion 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-rc2`
Version = `1.0.3.0430`
)

var (
Expand All @@ -31,6 +31,7 @@ type (
Debug bool `comment:"调试模式"`
Listen []string `comment:"监听地址 (多端口以','分隔)"`
Gzip bool `comment:"开启GZip (对已压缩的内容使用会产生反效果)"`
Cors bool `comment:"添加跨域响应头 (兼容前端请求)"`
LogPath string `comment:"文件日志路径,不填禁用"`
Print bool `comment:"控制台输出 (影响io性能,后台使用建议关闭)"`
SysLev bool `comment:"(实验性) 设置进程高优先级"`
Expand Down Expand Up @@ -140,11 +141,15 @@ type (
Kg_Lite_Enable bool `comment:"是否启用概念版自动签到,仅在appid=3116时运行"`
Kg_Lite_MixId string `comment:"mix_songmid的获取方式, 默认auto, 可以改成一个数字手动"`
Kg_Lite_Interval int64 `comment:"调用时间,自动刷新"`
// kg refresh_login
Kg_Refresh_Enable bool `comment:"是否启动刷新登录"`
Kg_Refresh_Interval int64 `comment:""`

// tx
Tx_Enable bool `comment:"是否启用小秋源"`
Tx_Ukey string `comment:"Cookie中/客户端的请求体中的(comm.authst)"`
Tx_Uuin string `comment:"key对应的QQ号"`
Tx_CDNUrl string `comment:"指定音频CDN地址"`
// tx refresh_login
Tx_Refresh_Enable bool `comment:"是否启动刷新登录"`
Tx_Refresh_Interval int64 `comment:"刷新间隔 (由程序维护,非必要无需修改)"`
Expand Down Expand Up @@ -254,6 +259,7 @@ var (
Kg_Lite_MixId: `auto`,

Tx_Enable: false,
Tx_CDNUrl: `https://isure6.stream.qqmusic.qq.com/`,
Tx_Refresh_Enable: false,
Tx_Refresh_Interval: 86000,
},
Expand Down
8 changes: 7 additions & 1 deletion src/middleware/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ func InitHandler(h gin.HandlerFunc) (out []gin.HandlerFunc) {
loger.Debug(`ApiKeyAuth Enabled`)
out = append(out, func(c *gin.Context) {
resp.Wrap(c, func() *resp.Resp {
if auth := c.Request.Header.Get(`X-LxM-Auth`); auth != env.Config.Auth.ApiKey_Value {
var auth string
if key, ok := c.GetQuery(`key`); ok {
auth = key
} else {
auth = c.Request.Header.Get(`X-LxM-Auth`)
}
if auth != env.Config.Auth.ApiKey_Value {
loger.Debug(`验证失败: %q`, auth)
return &resp.Resp{Code: 3, Msg: `验证Key失败, 请联系网站管理员`}
}
Expand Down
1 change: 1 addition & 0 deletions src/server/api_music.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func musicHandler(c *gin.Context) {
return out
}
// 查询内存缓存
atomic.AddInt64(&accnum, 1)
cquery := strings.Join([]string{pm, ps, pid, pq}, `/`)
loger.Debug(`MemoGet: %v`, cquery)
if cdata, ok := env.Cache.Get(cquery); ok {
Expand Down
1 change: 1 addition & 0 deletions src/server/loadpublic.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@ func loadPublic(r *gin.Engine) {
r.StaticFileFS(`/lx-custom-source.js`, `lx-custom-source.js`, httpFS)
}
r.StaticFileFS(`/favicon.ico`, `lx-icon.ico`, httpFS)
r.StaticFileFS(`/status`, `status.html`, httpFS)
r.StaticFS(`/public`, httpFS)
}
126 changes: 126 additions & 0 deletions src/server/public/status.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<!DOCTYPE html>
<html lang="zh">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>LX Source API</title>
</head>

<body>
<h1>LX Source API</h1>
当你看到这个页面时,服务已经成功跑起来了~
<h2>示例:</h2>
<script>
const api = './';
function l(s, id, q) {
let url = `${api}link/${s}/${id[Math.floor(Math.random() * id.length)]}/${q}`;
const key = localStorage.getItem('apipass'); if (key) url += `?key=${key}`;
fetch(url)
.then((response) => response.json())
.then((res) => {
if (res.code != 0 || res.data == '') throw res.msg;
window.open(res.data);
})
.catch((err) => {
alert(err);
});
};
</script>
<ul>
<li>0. <a href="./lx-custom-source.js?raw">获取源脚本</a></li>
<li>1. <a onclick="l('wy',['473120817','434022356','2112290949','27646205'],'320k')">WY小芸源</a></li>
<li>2. <a onclick="l('mg',['6005970X6D1','63278105706','60054702010'],'320k')">MG小蜜源</a></li>
<li>3. <a onclick="l('kw',['236891','26428340','133360','112051'],'320k')">KW小蜗源</a></li>
<li>4. <a onclick="l('kg',['A90B30D3F51C56841D3FE51D5C5B09A8'],'128k')">KG小枸源</a></li>
<li>5. <a onclick="l('tx',['002Le9vl2JlYDK','0013Xlvm0ZKNnA'],'128k')">TX小秋源</a></li>
</ul>
<h2>状态:</h2>
<ul>
<li>
已持续运行
<strong id="lxs_run_d">20</strong>
<strong id="lxs_run_h">21</strong>
<strong id="lxs_run_m">10</strong>
<strong id="lxs_run_s">08</strong>
</li>
<li>
调用:
<strong id="lxs_sum_acc">0</strong>
/解析:
<strong id="lxs_sum_req">0</strong>
/成功:
<strong id="lxs_sum_sec">0</strong>
</li>
<li>
版本号:
<strong id="lxs_ver">dev</strong>
</li>
<li><strong id="lxs_err"></strong></li>
</ul>
<script>
fetch(api)
.then((response) => response.json())
.then((res) => {
document.getElementById("lxs_sum_acc").innerText = res.summary.Accessn;
document.getElementById("lxs_sum_req").innerText = res.summary.Request;
document.getElementById("lxs_sum_sec").innerText = res.summary.Success;
const startTime = new Date(res.summary.StartAt * 1000);
const updateTimer = () => {
const elapsed = new Date() - startTime;
document.getElementById("lxs_run_d").innerText = String(Math.floor(elapsed / 864e5)).padStart(2, "0");
document.getElementById("lxs_run_h").innerText = String(Math.floor((elapsed % 864e5) / 36e5)).padStart(2, "0");
document.getElementById("lxs_run_m").innerText = String(Math.floor((elapsed % 36e5) / 6e4)).padStart(2, "0");
document.getElementById("lxs_run_s").innerText = String(Math.floor((elapsed % 6e4) / 1000)).padStart(2, "0");
};
updateTimer(), setInterval(updateTimer, 1e3);
document.getElementById("lxs_ver").innerText = res.version;
if (res.auth.apikey && !localStorage.getItem("apipass")) {
const key = prompt("请填写API密钥"); if (key) localStorage.setItem("apipass", key);
}
})
.catch((err) => {
document.getElementById("lxs_err").innerText = err;
});
</script>
<style>
html,
body {
height: 100vh;
width: 100vw;
margin: 0;
padding: 0;
background: #ffffff;
text-align: center;
margin-top: 30px;
overflow: hidden;
}

* {
color: rgb(100, 100, 100);
}

a {
color: #42b983;
text-decoration: none;
cursor: pointer;
}

ul,
li {
margin: 0;
}

ul {
margin-left: -40px;
line-height: 30px;
}

li {
list-style: none;
}
</style>
</body>

</html>
11 changes: 11 additions & 0 deletions src/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"net/http"
"time"

"github.com/gin-contrib/cors"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
)

var (
accnum int64
reqnum int64
secnum int64
)
Expand All @@ -24,6 +26,10 @@ func InitRouter() *gin.Engine {
if env.Config.Main.Gzip {
r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedPaths([]string{"/file/"})))
}
// Cors跨域
if env.Config.Main.Cors {
r.Use(cors.Default())
}
startime := time.Now().Unix()
// 源信息
r.GET(`/`, func(c *gin.Context) {
Expand All @@ -48,9 +54,14 @@ func InitRouter() *gin.Engine {
// 数据统计
`summary`: gin.H{
`StartAt`: startime, // 启动时间
`Accessn`: accnum, // 访问次数
`Request`: reqnum, // 解析次数
`Success`: secnum, // 成功次数
},
// 验证方式
`auth`: gin.H{
`apikey`: env.Config.Auth.ApiKey_Enable,
},
})
})
// 静态文件
Expand Down
Loading

0 comments on commit e402c10

Please sign in to comment.