Files
tg-chat-bot/src/common/user-store.ts
T
melod1n 9e30086af2 fix(images): cache Telegram photos by unique_id and pass base64 to LLM commands
Stop reading image files inside gemini/mistral commands; use pre-encoded image data from message parts

Rework loadImagesIfExists / loadImagesFromFileIds to return cached file_unique_ids and download only missing sizes

Encode cached images to base64 when assembling the reply chain

Make getPhotoMaxSize synchronous (returns PhotoSize), and map to URL only when needed

Await MessageStore.put / UserStore.put and prefetch single-image downloads on message receipt
2026-01-29 20:58:08 +03:00

39 lines
963 B
TypeScript

import {User} from "typescript-telegram-bot-api";
import {userDao} from "../index";
import {StoredUser} from "../model/stored-user";
export class UserStore {
private static map = new Map<number, StoredUser>();
static all(): Map<number, StoredUser> {
return this.map;
}
static async put(u: User): Promise<StoredUser> {
const user: StoredUser = {
id: u.id,
isBot: u.is_bot,
firstName: u.first_name,
lastName: u.last_name,
userName: u.username,
isPremium: u.is_premium,
};
this.map.set(u.id, user);
await userDao.insert(userDao.mapTo([u]));
return user;
}
static async get(id: number): Promise<StoredUser | null> {
const user = await userDao.getById({id: id});
if (!user) return null;
this.map.set(id, user);
return user;
}
static clear() {
this.map.clear();
}
}