This commit is contained in:
seb
2026-07-06 01:31:11 +02:00
commit 917930d0fa
34 changed files with 2912 additions and 0 deletions

43
src/queries/image.js Normal file
View File

@@ -0,0 +1,43 @@
import sql from 'mssql';
import { getPool } from '../db.js';
const IMAGE_BY_HASH_SQL = `
SELECT bBild, bVorschauBild, nBreite, nHoehe, nVorschauBreite, nVorschauHoehe, cQuelle
FROM dbo.tBild
WHERE cHash = @hash;
`;
function contentTypeFor(cQuelle) {
const extension = (cQuelle || '').split('.').pop()?.toLowerCase();
switch (extension) {
case 'png':
return 'image/png';
case 'gif':
return 'image/gif';
case 'webp':
return 'image/webp';
case 'jpg':
case 'jpeg':
default:
return 'image/jpeg';
}
}
export async function getImageByHash(hash, size) {
const result = await getPool().request().input('hash', sql.NVarChar, hash).query(IMAGE_BY_HASH_SQL);
const row = result.recordset[0];
if (!row) {
return null;
}
const previewMaxDimension = Math.max(row.nVorschauBreite || 0, row.nVorschauHoehe || 0);
const useFull = !previewMaxDimension || Number(size) > previewMaxDimension;
const buffer = useFull ? row.bBild : row.bVorschauBild;
if (!buffer) {
return null;
}
return { buffer, contentType: contentTypeFor(row.cQuelle) };
}