Skip to content

Commit

Permalink
chore: 由于telegraph图床关闭,删除相关代码
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Sep 9, 2024
1 parent a38f7e8 commit bb11947
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 26 deletions.
2 changes: 0 additions & 2 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export class EnvironmentConfig {
SHOW_REPLY_BUTTON = false;
// 而外引用消息开关
EXTRA_MESSAGE_CONTEXT = false;
// 开启Telegraph图床
TELEGRAPH_ENABLE = false;

// -- 模式开关 --
//
Expand Down
6 changes: 1 addition & 5 deletions src/telegram/handler/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { requestCompletionsFromLLM } from '../../agent/chat';
import type { HistoryModifier, LLMChatRequestParams } from '../../agent/types';
import type { WorkerContext } from '../../config/context';
import { MessageSender } from '../utils/send';
import { uploadImageToTelegraph } from '../../utils/image';
import { createTelegramBotAPI } from '../api';
import { ENV } from '../../config/env';
import type { MessageHandler } from './types';
Expand Down Expand Up @@ -98,11 +97,8 @@ export class ChatHandler implements MessageHandler {
const id = findPhotoFileID(message.photo, ENV.TELEGRAM_PHOTO_SIZE_OFFSET);
const api = createTelegramBotAPI(context.SHARE_CONTEXT.botToken);
const file = await api.getFileWithReturns({ file_id: id });
let url = file.result.file_path;
const url = file.result.file_path;
if (url) {
if (ENV.TELEGRAPH_ENABLE) {
url = await uploadImageToTelegraph(url);
}
params.images = [url];
}
}
Expand Down
19 changes: 0 additions & 19 deletions src/utils/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@ async function fetchImage(url: string): Promise<Blob> {
});
}

export async function uploadImageToTelegraph(url: string): Promise<string> {
if (url.startsWith('https://telegra.ph')) {
return url;
}
const raw = await fetchImage(url);
const formData = new FormData();
formData.append('file', raw, 'blob');

const resp = await fetch('https://telegra.ph/upload', {
method: 'POST',
body: formData,
});
let [{ src }] = await resp.json() as any;
src = `https://telegra.ph${src}`;
IMAGE_CACHE.set(src, raw);

return src;
}

async function urlToBase64String(url: string): Promise<string> {
try {
const { Buffer } = await import('node:buffer');
Expand Down

0 comments on commit bb11947

Please sign in to comment.