Refactor upload function and improve file handling #183
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solve issue: #178 #180 #182
Use tg channel/chat for storage
How to use?
First, you need to create a new telegram bot to obtain the token and a telegram channel to obtain Chat_ID
How to Obtain
Bot_Token
andChat_ID
for TelegramIf you don't have a Telegram account yet, please create one first. Then, follow these steps to get the
Bot_Token
andChat_ID
:Get the
Bot_Token
/newbot
to @BotFather, and follow the prompts to input your bot's name and username. Once successfully created, you will receive aBot_Token
, which is used to interact with the Telegram API.Set the bot as a channel administrator
Get the
Chat_ID
Chat_ID
(the ID of your channel).Important
由于原有的Telegraph API接口被官方关闭,需要将上传渠道切换至Telegram Channel,请按照文档中的部署要求设置
TG_Bot_Token
和TG_Chat_ID
,否则将无法正常使用上传功能。如何获取Telegram的
Bot_Token
和Chat_ID
如果您还没有Telegram账户,请先创建一个。接着,按照以下步骤操作以获取
BOT_TOKEN
和CHAT_ID
:Bot_Token
/newbot
,根据提示依次输入您的机器人名称和用户名。成功创建机器人后,您将会收到一个BOT_TOKEN
,用于与Telegram API进行交互。获取
Chat_ID
CHAT_ID
(即频道的ID)。CHAT_ID
(即频道的ID)。最后去Cloudflare Pages后台设置相关的环境变量(注:修改环境变量后,需要重新部署才能生效)
TG_Bot_Token
123468:AAxxxGKrn5
TG_Chat_ID
-1234567
本地运行命令,需先按照Cloudflare官方文档安装
wrangler
npx wrangler pages dev ./ --kv "img_url" --port 8080 --binding BASIC_USER=admin --binding BASIC_PASS=123 --binding TG_Chat_ID=[Your Chat ID] --binding TG_Bot_Token=[Your Telegram Bot token] --persist-to ./data
Reference:
@x-dr/telegraph-Image
@MarSeventh/CloudFlare-ImgBed