mirror of
https://github.com/Trollobot/Telemax.git
synced 2026-10-19 10:23:24 +00:00
1.3.10-beta.1: ВРЕМЕННАЯ диагностика PHOTO_COMPARE=1 (только тест) — каждое фото из MAX качается всеми способами (baseUrl+token, baseUrl, url, baseUrl&fn=w_1440) и в лог идут ответ, байты, формат, размер — чтобы решить, какой способ первым; убрать до выпуска
This commit is contained in:
parent
ef547287f7
commit
dcae9353ab
3 changed files with 27 additions and 3 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "telemax",
|
||||
"version": "1.3.9",
|
||||
"version": "1.3.10-beta.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "telemax",
|
||||
"version": "1.3.9",
|
||||
"version": "1.3.10-beta.1",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"dotenv": "^17.2.3",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "telemax",
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-only",
|
||||
"version": "1.3.9",
|
||||
"version": "1.3.10-beta.1",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "tsx watch src/server/app.ts",
|
||||
|
|
|
|||
|
|
@ -374,8 +374,32 @@ export function photoUrls(att: Pick<MaxAttachment, 'baseUrl' | 'photoToken' | 'u
|
|||
return all.filter((v, i): v is { how: string; url: string } => !!v.url && all.findIndex((w) => w.url === v.url) === i);
|
||||
}
|
||||
|
||||
/**
|
||||
* TEMPORARY diagnostic (PHOTO_COMPARE=1, test server only, 2026-10-16): fetches a MAX photo every
|
||||
* way — photoUrls plus MAX web's on-screen size (`&fn=w_1440`) — and logs what each gives, to settle
|
||||
* which way goes first. Remove before the release.
|
||||
*/
|
||||
async function comparePhotoUrls(att: MaxAttachment): Promise<void> {
|
||||
const id = String(att.photoId ?? '?');
|
||||
const declared = att as { width?: unknown; height?: unknown };
|
||||
logger.info(`PHOTO_COMPARE ${id}: MAX says ${String(declared.width)}×${String(declared.height)}`);
|
||||
const ways = [...photoUrls(att)];
|
||||
if (att.baseUrl) ways.push({ how: 'baseUrl&fn=w_1440', url: `${att.baseUrl}&fn=w_1440` });
|
||||
for (const { how, url } of ways) {
|
||||
try {
|
||||
const res = await maxFetch(url, { signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS) });
|
||||
const buf = res.ok ? Buffer.from(await res.arrayBuffer()) : undefined;
|
||||
const size = buf ? imageSize(buf) : null;
|
||||
logger.info(`PHOTO_COMPARE ${id}: «${how}» → ${res.status}${buf ? `, ${buf.byteLength} bytes, ${imageExtension(buf)}${size ? `, ${size.width}×${size.height}` : ''}` : ''}`);
|
||||
} catch (err) {
|
||||
logger.info(`PHOTO_COMPARE ${id}: «${how}» → ${(err as Error).message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A photo by the first of photoUrls that the CDN gives — the next one tried only after a refusal (an outage is no reason to). */
|
||||
async function downloadPhoto(att: MaxAttachment): Promise<Buffer> {
|
||||
if (process.env.PHOTO_COMPARE === '1') void comparePhotoUrls(att);
|
||||
let miss: DownloadMissError | undefined;
|
||||
for (const { how, url } of photoUrls(att)) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue