Fix image downloading

This commit is contained in:
2022-04-01 21:48:15 +03:00
parent 69ca54b055
commit ef43c5c454

View File

@@ -4,6 +4,7 @@ import { AuthorAnnnotation, BookAnnotation } from "./services/book_library";
import { isNormalText } from "./utils"; import { isNormalText } from "./utils";
import { getTextPaginationData } from './keyboard'; import { getTextPaginationData } from './keyboard';
import Sentry from '@/sentry'; import Sentry from '@/sentry';
import { downloadImage } from "./services/downloader";
export function getAnnotationHandler<T extends BookAnnotation | AuthorAnnnotation>( export function getAnnotationHandler<T extends BookAnnotation | AuthorAnnnotation>(
@@ -25,11 +26,15 @@ export function getAnnotationHandler<T extends BookAnnotation | AuthorAnnnotatio
} }
if (annotation.file) { if (annotation.file) {
try { const imageData = await downloadImage(annotation.file);
await ctx.telegram.sendPhoto(ctx.message.chat.id, annotation.file);
} catch (e) { if (imageData !== null) {
console.log(e); try {
Sentry.captureException(e); await ctx.telegram.sendPhoto(ctx.message.chat.id, { source: imageData });
} catch (e) {
console.log(e);
Sentry.captureException(e);
}
} }
} }