fix using wrong dirs

This commit is contained in:
2026-02-16 20:05:21 +03:00
parent c98528a54f
commit 51db4ba9b5
2 changed files with 6 additions and 21 deletions
+4 -14
View File
@@ -15,7 +15,7 @@ import {
} from "typescript-telegram-bot-api";
import {Environment} from "../common/environment";
import {TelegramError} from "typescript-telegram-bot-api/dist/errors";
import {bot, botUser, callbackCommands, commands, messageDao, ollama} from "../index";
import {bot, botUser, callbackCommands, commands, messageDao, ollama, photoDir} from "../index";
import os from "os";
import axios from "axios";
import {MessagePart} from "../common/message-part";
@@ -538,12 +538,7 @@ export async function loadImagesIfExists(msg: Message | StoredMessage): Promise<
const maxSize = await mapPhotoSizeToMax(getPhotoMaxSize(msg.photo));
if (maxSize) {
const imagePath = path.join(Environment.DATA_PATH, "photo");
if (!fs.existsSync(imagePath)) {
fs.mkdirSync(imagePath);
}
let imageFilePath = path.join(imagePath, maxSize.unique_file_id + ".jpg");
let imageFilePath = path.join(photoDir, maxSize.unique_file_id + ".jpg");
if (!fs.existsSync(imageFilePath)) {
const res = await axios.get<ArrayBuffer>(maxSize.url, {responseType: "arraybuffer"});
const src = Buffer.from(res.data);
@@ -567,11 +562,6 @@ export async function loadImagesIfExists(msg: Message | StoredMessage): Promise<
export async function loadImagesFromFileIds(sizes: PhotoSize[]): Promise<string[] | null> {
if (!sizes?.length) return null;
const dataPath = path.join(Environment.DATA_PATH, "photo");
if (!fs.existsSync(dataPath)) {
fs.mkdirSync(dataPath);
}
const existing =
sizes.filter(s => fs.existsSync(photoPathByUniqueId(s.file_unique_id)))
.map(s => s.file_unique_id);
@@ -589,7 +579,7 @@ export async function loadImagesFromFileIds(sizes: PhotoSize[]): Promise<string[
const paths = responses.map((res, index) => {
try {
const uniqueFileId = maxSizes[index].unique_file_id;
const imageFilePath = path.join(dataPath, uniqueFileId + ".jpg");
const imageFilePath = path.join(photoDir, uniqueFileId + ".jpg");
const src = Buffer.from(res.data);
fs.writeFileSync(imageFilePath, src);
return uniqueFileId;
@@ -1063,7 +1053,7 @@ async function processAlbum(groupId: string): Promise<string[]> {
}
export function photoPathByUniqueId(uniqueId: string): string {
return path.join(Environment.DATA_PATH, "photo", uniqueId + ".jpg");
return path.join(photoDir, uniqueId + ".jpg");
}
export function getCurrentModel(): string {
+2 -7
View File
@@ -1,7 +1,7 @@
import Innertube, {Platform, Types, Utils} from "youtubei.js";
import fs, {createWriteStream} from "node:fs";
import path from "node:path";
import {Environment} from "../common/environment";
import {videoDir} from "../index";
export function getYouTubeVideoId(url: string): string {
const regex = /(?:(?:youtube\.com|music\.youtube\.com)\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?|shorts|clip)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/i;
@@ -20,12 +20,7 @@ export async function downloadVideoFromYouTube(url: string, targetQuality: strin
try {
const videoId = getYouTubeVideoId(url);
const videoFolder = path.join(Environment.DATA_PATH, "video");
if (!fs.existsSync(videoFolder)) {
fs.mkdirSync(videoFolder);
}
const filePath = path.join(videoFolder, `${videoId}.mp4`);
const filePath = path.join(videoDir, `${videoId}.mp4`);
if (fs.existsSync(filePath)) {
const buffer = Buffer.from(fs.readFileSync(filePath));
return {