fix using wrong dirs
This commit is contained in:
+4
-14
@@ -15,7 +15,7 @@ import {
|
|||||||
} from "typescript-telegram-bot-api";
|
} from "typescript-telegram-bot-api";
|
||||||
import {Environment} from "../common/environment";
|
import {Environment} from "../common/environment";
|
||||||
import {TelegramError} from "typescript-telegram-bot-api/dist/errors";
|
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 os from "os";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {MessagePart} from "../common/message-part";
|
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));
|
const maxSize = await mapPhotoSizeToMax(getPhotoMaxSize(msg.photo));
|
||||||
if (maxSize) {
|
if (maxSize) {
|
||||||
const imagePath = path.join(Environment.DATA_PATH, "photo");
|
let imageFilePath = path.join(photoDir, maxSize.unique_file_id + ".jpg");
|
||||||
if (!fs.existsSync(imagePath)) {
|
|
||||||
fs.mkdirSync(imagePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
let imageFilePath = path.join(imagePath, maxSize.unique_file_id + ".jpg");
|
|
||||||
if (!fs.existsSync(imageFilePath)) {
|
if (!fs.existsSync(imageFilePath)) {
|
||||||
const res = await axios.get<ArrayBuffer>(maxSize.url, {responseType: "arraybuffer"});
|
const res = await axios.get<ArrayBuffer>(maxSize.url, {responseType: "arraybuffer"});
|
||||||
const src = Buffer.from(res.data);
|
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> {
|
export async function loadImagesFromFileIds(sizes: PhotoSize[]): Promise<string[] | null> {
|
||||||
if (!sizes?.length) return null;
|
if (!sizes?.length) return null;
|
||||||
|
|
||||||
const dataPath = path.join(Environment.DATA_PATH, "photo");
|
|
||||||
if (!fs.existsSync(dataPath)) {
|
|
||||||
fs.mkdirSync(dataPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const existing =
|
const existing =
|
||||||
sizes.filter(s => fs.existsSync(photoPathByUniqueId(s.file_unique_id)))
|
sizes.filter(s => fs.existsSync(photoPathByUniqueId(s.file_unique_id)))
|
||||||
.map(s => 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) => {
|
const paths = responses.map((res, index) => {
|
||||||
try {
|
try {
|
||||||
const uniqueFileId = maxSizes[index].unique_file_id;
|
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);
|
const src = Buffer.from(res.data);
|
||||||
fs.writeFileSync(imageFilePath, src);
|
fs.writeFileSync(imageFilePath, src);
|
||||||
return uniqueFileId;
|
return uniqueFileId;
|
||||||
@@ -1063,7 +1053,7 @@ async function processAlbum(groupId: string): Promise<string[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function photoPathByUniqueId(uniqueId: string): 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 {
|
export function getCurrentModel(): string {
|
||||||
|
|||||||
+2
-7
@@ -1,7 +1,7 @@
|
|||||||
import Innertube, {Platform, Types, Utils} from "youtubei.js";
|
import Innertube, {Platform, Types, Utils} from "youtubei.js";
|
||||||
import fs, {createWriteStream} from "node:fs";
|
import fs, {createWriteStream} from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import {Environment} from "../common/environment";
|
import {videoDir} from "../index";
|
||||||
|
|
||||||
export function getYouTubeVideoId(url: string): string {
|
export function getYouTubeVideoId(url: string): string {
|
||||||
const regex = /(?:(?:youtube\.com|music\.youtube\.com)\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?|shorts|clip)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/i;
|
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 {
|
try {
|
||||||
const videoId = getYouTubeVideoId(url);
|
const videoId = getYouTubeVideoId(url);
|
||||||
const videoFolder = path.join(Environment.DATA_PATH, "video");
|
const filePath = path.join(videoDir, `${videoId}.mp4`);
|
||||||
if (!fs.existsSync(videoFolder)) {
|
|
||||||
fs.mkdirSync(videoFolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
const filePath = path.join(videoFolder, `${videoId}.mp4`);
|
|
||||||
if (fs.existsSync(filePath)) {
|
if (fs.existsSync(filePath)) {
|
||||||
const buffer = Buffer.from(fs.readFileSync(filePath));
|
const buffer = Buffer.from(fs.readFileSync(filePath));
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user