This repository was archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e402c10
commit 30b3260
Showing
13 changed files
with
592 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,121 @@ | ||
package cloudcache | ||
|
||
import ( | ||
"lx-source/src/caches" | ||
"lx-source/src/env" | ||
"net/http" | ||
"strings" | ||
|
||
cr "github.com/ZxwyWebSite/cr-go-sdk" | ||
"github.com/ZxwyWebSite/cr-go-sdk/service/explorer" | ||
"github.com/ZxwyWebSite/ztool" | ||
) | ||
|
||
type Cache struct { | ||
Site *cr.SiteObj | ||
Path string | ||
state bool | ||
} | ||
|
||
func (c *Cache) Get(q *caches.Query) string { | ||
var b strings.Builder | ||
b.WriteString(c.Path) | ||
b.WriteByte('/') | ||
b.WriteString(q.Source) | ||
b.WriteByte('/') | ||
b.WriteString(q.MusicID) | ||
list, err := c.Site.Directory(b.String()) | ||
if err != nil { | ||
caches.Loger.Debug(`列出目录: %v`, err) | ||
return `` | ||
} | ||
name := q.Quality + `.` + q.Extname | ||
var id string | ||
for _, v := range list.Objects { | ||
if v.Name == name && v.Type == `file` { | ||
id = v.ID | ||
break | ||
} | ||
} | ||
if id == `` { | ||
caches.Loger.Debug(`文件不存在`) | ||
return `` | ||
} | ||
srcs, err := c.Site.FileSource(cr.GenerateSrc(false, id)) | ||
if err != nil { | ||
caches.Loger.Debug(`生成外链: %v`, err) | ||
return `` | ||
} | ||
return (*srcs)[0].URL | ||
/*link, err := c.Site.FileDownload(id) | ||
if err != nil { | ||
caches.Loger.Debug(`下载文件: %v`, err) | ||
return `` | ||
} | ||
if (*link)[0] == '/' { | ||
return c.Site.Addr + (*link)[1:] | ||
} | ||
return *link*/ | ||
} | ||
|
||
func (c *Cache) Set(q *caches.Query, l string) string { | ||
var b strings.Builder | ||
b.WriteString(c.Path) | ||
b.WriteByte('/') | ||
b.WriteString(q.Source) | ||
b.WriteByte('/') | ||
b.WriteString(q.MusicID) | ||
dir := b.String() | ||
err := c.Site.DirectoryNew(&explorer.DirectoryService{ | ||
Path: dir, | ||
}) | ||
if err != nil { | ||
caches.Loger.Debug(`创建目录: %v`, err) | ||
return `` | ||
} | ||
/*var buf bytes.Buffer | ||
err = ztool.Net_Download(l, &buf, nil) | ||
if err != nil { | ||
caches.Loger.Debug(`下载文件: %v`, err) | ||
return `` | ||
}*/ | ||
name := q.Quality + `.` + q.Extname | ||
err = ztool.Net_Request( | ||
http.MethodGet, l, nil, | ||
[]ztool.Net_ReqHandlerFunc{ztool.Net_ReqAddHeaders()}, | ||
[]ztool.Net_ResHandlerFunc{func(res *http.Response) error { | ||
return (&cr.UploadTask{ | ||
Site: c.Site, | ||
File: res.Body, | ||
Size: uint64(res.ContentLength), | ||
Name: name, | ||
Mime: `audio/mpeg`, | ||
}).Do(dir) | ||
}}, | ||
) | ||
if err != nil { | ||
caches.Loger.Debug(`上传文件: %v`, err) | ||
return `` | ||
} | ||
return c.Get(q) | ||
} | ||
|
||
func (c *Cache) Stat() bool { | ||
return c.state | ||
} | ||
|
||
func (c *Cache) Init() error { | ||
cr.Cr_Debug = env.Config.Main.Debug | ||
err := c.Site.SdkInit() | ||
if err != nil { | ||
return err | ||
} | ||
if c.Site.Users.Cookie == nil || c.Site.Config.User.Anonymous { | ||
err = c.Site.SdkLogin() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
c.state = true | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import ( | |
) | ||
|
||
const ( | ||
Version = `1.0.3.0430` | ||
Version = `1.0.3.0518` | ||
) | ||
|
||
var ( | ||
|
@@ -36,10 +36,10 @@ type ( | |
Print bool `comment:"控制台输出 (影响io性能,后台使用建议关闭)"` | ||
SysLev bool `comment:"(实验性) 设置进程高优先级"` | ||
// FFConv bool `comment:"(实验性) 使用FFMpeg修复音频(本地缓存)"` | ||
NgProxy bool `comment:"兼容反向代理(beta)"` | ||
Timeout int64 `comment:"网络请求超时(单位:秒,海外服务器可适当调大)"` | ||
|
||
Store string `comment:"内存缓存持久化文件地址"` | ||
NgProxy bool `comment:"兼容反向代理(beta)"` | ||
Timeout int64 `comment:"网络请求超时(单位:秒,海外服务器可适当调大)"` | ||
Store string `comment:"内存缓存持久化文件地址"` | ||
ErrMp3 string `comment:"获取失败默认音频"` | ||
} | ||
// 接口 | ||
Conf_Apis struct { | ||
|
@@ -174,11 +174,11 @@ type ( | |
Local_Bind string `comment:"本地缓存外部访问地址"` | ||
Local_Auto bool `comment:"自适应缓存访问地址(beta)"` | ||
// 云盘 | ||
// Cloud_Site string `comment:"Cloudreve站点地址"` | ||
// Cloud_User string `comment:"Cloudreve用户名"` | ||
// Cloud_Pass string `comment:"Cloudreve密码"` | ||
// Cloud_Sess string `comment:"Cloudreve会话"` | ||
// Cloud_Path string `comment:"Cloudreve存储路径"` | ||
Cloud_Site string `comment:"Cloudreve站点地址"` | ||
Cloud_User string `comment:"Cloudreve用户名"` | ||
Cloud_Pass string `comment:"Cloudreve密码"` | ||
Cloud_Sess string `comment:"Cloudreve会话"` | ||
Cloud_Path string `comment:"Cloudreve存储路径"` | ||
} | ||
// 结构 | ||
Conf struct { | ||
|
@@ -204,6 +204,7 @@ var ( | |
SysLev: false, | ||
Timeout: 30, | ||
Store: `/data/memo.bin`, | ||
ErrMp3: `https://r2eu.zxwy.link/gh/lx-source/static/error.mp3`, | ||
}, | ||
Apis: Conf_Apis{ | ||
// BindAddr: `http://192.168.10.22:1011/`, | ||
|
@@ -276,11 +277,11 @@ var ( | |
LinkMode: `1`, | ||
Local_Path: `data/cache`, | ||
Local_Bind: `http://127.0.0.1:1011/`, | ||
// Cloud_Site: `https://cloudreveplus-demo.onrender.com/`, | ||
// Cloud_User: `[email protected]`, | ||
// Cloud_Pass: `CloudrevePlusDemo`, | ||
// Cloud_Sess: ``, | ||
// Cloud_Path: `/Lx-Source/cache`, | ||
Cloud_Site: `https://cloudreveplus-demo.onrender.com/`, | ||
Cloud_User: `[email protected]`, | ||
Cloud_Pass: `CloudrevePlusDemo`, | ||
Cloud_Sess: ``, | ||
Cloud_Path: `/Lx-Source/cache`, | ||
}, | ||
} | ||
Config = DefCfg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.