1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

coolq: remove support for old cache path

This commit is contained in:
wdvxdr 2022-03-18 19:49:32 +08:00
parent afbf42b709
commit 937538a7cb
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
2 changed files with 4 additions and 20 deletions

View File

@ -917,9 +917,6 @@ func (bot *CQBot) ToElement(t string, d map[string]string, sourceType message.So
case "record": case "record":
f := d["file"] f := d["file"]
data, err := global.FindFile(f, d["cache"], global.VoicePath) data, err := global.FindFile(f, d["cache"], global.VoicePath)
if err == global.ErrSyntax {
data, err = global.FindFile(f, d["cache"], global.VoicePathOld)
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1241,10 +1238,6 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video bool, sourceTy
} }
} }
exist := global.PathExists(rawPath) exist := global.PathExists(rawPath)
if !exist && global.PathExists(path.Join(global.ImagePathOld, f)) {
exist = true
rawPath = path.Join(global.ImagePathOld, f)
}
if !exist { if !exist {
if d["url"] != "" { if d["url"] != "" {
return bot.makeImageOrVideoElem(map[string]string{"file": d["url"]}, false, sourceType) return bot.makeImageOrVideoElem(map[string]string{"file": d["url"]}, false, sourceType)

View File

@ -22,27 +22,18 @@ import (
const ( const (
// ImagePath go-cqhttp使用的图片缓存目录 // ImagePath go-cqhttp使用的图片缓存目录
ImagePath = "data/images" ImagePath = "data/images"
// ImagePathOld 兼容旧版go-cqhttp使用的图片缓存目录
ImagePathOld = "data/image"
// VoicePath go-cqhttp使用的语音缓存目录 // VoicePath go-cqhttp使用的语音缓存目录
VoicePath = "data/voices" VoicePath = "data/voices"
// VoicePathOld 兼容旧版go-cqhttp使用的语音缓存目录
VoicePathOld = "data/record"
// VideoPath go-cqhttp使用的视频缓存目录 // VideoPath go-cqhttp使用的视频缓存目录
VideoPath = "data/videos" VideoPath = "data/videos"
// CachePath go-cqhttp使用的缓存目录 // CachePath go-cqhttp使用的缓存目录
CachePath = "data/cache" CachePath = "data/cache"
// DumpsPath go-cqhttp使用错误转储目录 // DumpsPath go-cqhttp使用错误转储目录
DumpsPath = "dumps" DumpsPath = "dumps"
)
var (
// ErrSyntax Path语法错误时返回的错误
ErrSyntax = errors.New("syntax error")
// HeaderAmr AMR文件头 // HeaderAmr AMR文件头
HeaderAmr = []byte("#!AMR") HeaderAmr = "#!AMR"
// HeaderSilk Silkv3文件头 // HeaderSilk Silkv3文件头
HeaderSilk = []byte("\x02#!SILK_V3") HeaderSilk = "\x02#!SILK_V3"
) )
// PathExists 判断给定path是否存在 // PathExists 判断给定path是否存在
@ -78,13 +69,13 @@ func Check(err error, deleteSession bool) {
// IsAMRorSILK 判断给定文件是否为Amr或Silk格式 // IsAMRorSILK 判断给定文件是否为Amr或Silk格式
func IsAMRorSILK(b []byte) bool { func IsAMRorSILK(b []byte) bool {
return bytes.HasPrefix(b, HeaderAmr) || bytes.HasPrefix(b, HeaderSilk) return bytes.HasPrefix(b, []byte(HeaderAmr)) || bytes.HasPrefix(b, []byte(HeaderSilk))
} }
// FindFile 从给定的File寻找文件并返回文件byte数组。File是一个合法的URL。p为文件寻找位置。 // FindFile 从给定的File寻找文件并返回文件byte数组。File是一个合法的URL。p为文件寻找位置。
// 对于HTTP/HTTPS形式的URLCache为"1"或空时表示启用缓存 // 对于HTTP/HTTPS形式的URLCache为"1"或空时表示启用缓存
func FindFile(file, cache, p string) (data []byte, err error) { func FindFile(file, cache, p string) (data []byte, err error) {
data, err = nil, ErrSyntax data, err = nil, os.ErrNotExist
switch { switch {
case strings.HasPrefix(file, "http"): // https also has prefix http case strings.HasPrefix(file, "http"): // https also has prefix http
hash := md5.Sum([]byte(file)) hash := md5.Sum([]byte(file))