diff --git a/README.md b/README.md index 302b290..71cfe89 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ tgState 旧版本:https://tgtu.ikun123.com/ -搭建在Vercel,大文件可能会上传失败 +搭建在Vercel,大文件可能会上传失败(资源限制) 测试图片: @@ -37,6 +37,17 @@ tgState 部署前需要准备一个Telegram Bot(@botfather处申请) 如果是需要存储在频道,则需要将Bot拉入频道作为管理员,公开频道并自定义频道Link +后台管理 +=== + +后台管理计划是全Telegram管理,Vercel目前不支持,目前实现的有: + +获取FileID +--- + +对bot聊天中的文件引用并回复```get```可以获取FileID,搭建地址+/d/+FileID即可访问资源 + + Vercel部署 ==== diff --git a/control/control.go b/control/control.go index 55bbc6c..820da9f 100644 --- a/control/control.go +++ b/control/control.go @@ -59,18 +59,18 @@ func UploadImageAPI(w http.ResponseWriter, r *http.Request) { } // 读取文件内容 - fileBytes, err := io.ReadAll(file) - if err != nil { - errJsonMsg("Failed to read file", w) - // http.Error(w, "Failed to read file", http.StatusInternalServerError) - return - } + // fileBytes, err := io.ReadAll(file) + // if err != nil { + // errJsonMsg("Failed to read file", w) + // // http.Error(w, "Failed to read file", http.StatusInternalServerError) + // return + // } res := conf.UploadResponse{ Code: 0, Message: "error", } var img string - img = "/d/" + utils.UpDocument(utils.TgFileData(header.Filename, fileBytes)) + img = "/d/" + utils.UpDocument(utils.TgFileData(header.Filename, file)) res = conf.UploadResponse{ Code: 1, Message: img, diff --git a/utils/utils.go b/utils/utils.go index d2fc59f..28e421b 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -2,20 +2,21 @@ package utils import ( "encoding/json" + "io" "log" "csz.net/tgstate/conf" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) -func TgFileData(fileName string, fileData []byte) tgbotapi.FileBytes { - return tgbotapi.FileBytes{ - Name: fileName, - Bytes: fileData, +func TgFileData(fileName string, fileData io.Reader) tgbotapi.FileReader { + return tgbotapi.FileReader{ + Name: fileName, + Reader: fileData, } } -func UpDocument(fileData tgbotapi.FileBytes) string { +func UpDocument(fileData tgbotapi.FileReader) string { bot, err := tgbotapi.NewBotAPI(conf.BotToken) if err != nil { log.Panic(err)