Disable logging on md5 404's
This commit is contained in:
@@ -98,7 +98,7 @@ export async function handleMessageCreate(message: Message) {
|
|||||||
if (md5s.length == 0) continue;
|
if (md5s.length == 0) continue;
|
||||||
|
|
||||||
for (const md5 of md5s) {
|
for (const md5 of md5s) {
|
||||||
const post = await getE621PostByMd5(md5);
|
const post = await getE621PostByMd5(md5, false);
|
||||||
|
|
||||||
if (post) {
|
if (post) {
|
||||||
if (await blacklistIfNecessary(message, [post])) return;
|
if (await blacklistIfNecessary(message, [post])) return;
|
||||||
@@ -377,7 +377,7 @@ async function imageHandler(message: Message, matchedGroups: RegExpExecArray[]):
|
|||||||
|
|
||||||
for (const match of matchedGroups) {
|
for (const match of matchedGroups) {
|
||||||
try {
|
try {
|
||||||
const post = await getE621PostByMd5(match[1]);
|
const post = await getE621PostByMd5(match[1], false);
|
||||||
if (post) posts.push(post);
|
if (post) posts.push(post);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ if (secure && existsSync('./certs/cert.pem') && existsSync('./certs/cert.pem'))
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function request(path: string, query?: { [name: string]: string }): Promise<any> {
|
async function request(path: string, query?: { [name: string]: string }, logErrors = true): Promise<any> {
|
||||||
const url = new URL(config.E621_BASE_URL!);
|
const url = new URL(config.E621_BASE_URL!);
|
||||||
url.pathname = path + '.json';
|
url.pathname = path + '.json';
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ async function request(path: string, query?: { [name: string]: string }): Promis
|
|||||||
}
|
}
|
||||||
}, (res) => {
|
}, (res) => {
|
||||||
if (res.statusCode! < 200 || res.statusCode! >= 300) {
|
if (res.statusCode! < 200 || res.statusCode! >= 300) {
|
||||||
console.error(`[E621 Requester] Received status code ${res.statusCode} while requesting: ${url}`);
|
if (logErrors) console.error(`[E621 Requester] Received status code ${res.statusCode} while requesting: ${url}`);
|
||||||
res.resume();
|
res.resume();
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
}
|
}
|
||||||
@@ -64,14 +64,18 @@ async function request(path: string, query?: { [name: string]: string }): Promis
|
|||||||
try {
|
try {
|
||||||
resolve(JSON.parse(data));
|
resolve(JSON.parse(data));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (logErrors) {
|
||||||
console.error('[E621 Requester] Error parsing JSON from:');
|
console.error('[E621 Requester] Error parsing JSON from:');
|
||||||
console.error(data);
|
console.error(data);
|
||||||
|
}
|
||||||
resolve(null);
|
resolve(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).on('error', (e) => {
|
}).on('error', (e) => {
|
||||||
|
if (logErrors) {
|
||||||
console.error('[E621 Requester] Error fetching:');
|
console.error('[E621 Requester] Error fetching:');
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
}
|
||||||
resolve(null);
|
resolve(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -89,8 +93,8 @@ export async function getManyE621Posts(ids: string[] | number[]): Promise<E621Po
|
|||||||
return (await request('/posts', { v2: 'true', tags: `id:${ids.join(',')}` })) as E621Post[] ?? [];
|
return (await request('/posts', { v2: 'true', tags: `id:${ids.join(',')}` })) as E621Post[] ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getE621PostByMd5(md5: string): Promise<E621Post | null> {
|
export async function getE621PostByMd5(md5: string, logErrors = true): Promise<E621Post | null> {
|
||||||
return (await request('/posts', { md5, v2: 'true' })) as E621Post ?? null;
|
return (await request('/posts', { md5, v2: 'true' }, logErrors)) as E621Post ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getE621PostFlag(id: number): Promise<PostFlag | null> {
|
export async function getE621PostFlag(id: number): Promise<PostFlag | null> {
|
||||||
|
|||||||
Reference in New Issue
Block a user