Skip to content

Commit

Permalink
Merge pull request clansty#140 from sakarie9/fix-invalid-dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty authored Sep 28, 2023
2 parents fca8055 + d93c221 commit 52e17e7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"file-type": "^17.1.4",
"fluent-ffmpeg": "^2.1.2",
"icqq": "^0.4.12",
"image-size": "^1.0.2",
"lodash": "^4.17.21",
"log4js": "^6.6.1",
"nodejs-base64": "^2.0.0",
Expand Down
13 changes: 13 additions & 0 deletions src/helpers/forwardHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getLogger } from 'log4js';
import { Entity } from 'telegram/define';
import { ForwardMessage } from 'icqq';
import { Api } from 'telegram';
import { imageSize } from 'image-size';

const log = getLogger('ForwardHelper');

Expand All @@ -21,6 +22,18 @@ export default {
return new CustomFile(filename, file.length, '', file);
}
const type = await fileTypeFromBuffer(file);
// The photo must be at most 10 MB in size. The photo's width and height must not exceed 10000 in total. Width and height ratio must be at most 20
if (type.ext === 'png' || type.ext === 'jpg') {
const dimensions = imageSize(file);
const aspectRatio = dimensions.width / dimensions.height;
if (aspectRatio > 20 || aspectRatio < 1 / 20
|| dimensions.width + dimensions.height > 10000
|| file.length > 1024 * 1024 * 10
) {
// 让 Telegram 服务器下载
return url
}
}
if (allowWebp) {
return new CustomFile(`image.${type.ext}`, file.length, '', file);
}
Expand Down
Loading

0 comments on commit 52e17e7

Please sign in to comment.