This commit is contained in:
seb
2026-08-01 01:36:49 +02:00
parent 243143e7eb
commit 671064bf3f
9 changed files with 181 additions and 5 deletions

View File

@@ -42,7 +42,7 @@ export default function addImage(pool) {
.input('thumbh', processed.thumb.h)
.input('thumbhash', processed.thumb.hash)
.input('source', '')
.input('binary', processed.full.buffer)
.input('fullbinary', processed.full.buffer)
.input('thumbbinary', processed.thumb.buffer)
.query(CREATE_PIC);

View File

@@ -0,0 +1,28 @@
import { GET_FULL_BY_HASH } from '../../sql/pic.js';
import resolvePicAccess from './resolvePicAccess.js';
export default function getImageByHash(pool) {
const authorize = resolvePicAccess(pool);
return async (googleAuthId, hash) => {
await authorize(googleAuthId, hash);
const result = await pool
.request()
.input('hash', hash)
.query(GET_FULL_BY_HASH);
const row = result.recordset[0];
if (!row?.buffer) {
throw new Error('Image not found');
}
return {
buffer: row.buffer,
w: row.w,
h: row.h,
size: row.size,
contentType: 'image/avif',
};
};
}

View File

@@ -0,0 +1,27 @@
import { GET_THUMB_BY_HASH } from '../../sql/pic.js';
import resolvePicAccess from './resolvePicAccess.js';
export default function getThumbByHash(pool) {
const authorize = resolvePicAccess(pool);
return async (googleAuthId, hash) => {
await authorize(googleAuthId, hash);
const result = await pool
.request()
.input('hash', hash)
.query(GET_THUMB_BY_HASH);
const row = result.recordset[0];
if (!row?.buffer) {
throw new Error('Image not found');
}
return {
buffer: row.buffer,
w: row.w,
h: row.h,
contentType: 'image/avif',
};
};
}

View File

@@ -0,0 +1,20 @@
import { GET_CATEGORY_ID_BY_HASH } from '../../sql/pic.js';
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
export default function resolvePicAccess(pool) {
const access = resolveCategoryAccess(pool);
return async (googleAuthId, hash) => {
const result = await pool
.request()
.input('hash', hash)
.query(GET_CATEGORY_ID_BY_HASH);
const categoryId = result.recordset[0]?.categoryId;
if (!categoryId) {
throw new Error('Image not found');
}
await access(googleAuthId, categoryId);
};
}