This commit is contained in:
seb
2026-10-25 22:38:01 +01:00
parent c07e4dc083
commit fb2dafd920
5 changed files with 50 additions and 97 deletions

View File

@@ -140,39 +140,10 @@ export async function getPosImageByHash(hash, { width = 200, height = 200 } = {}
const provider = await getProvider();
const isSqlite = provider?.dialect === 'sqlite3';
if (isSqlite) {
const result = await provider.query(
'SELECT w, h, size, hash, thumbw, thumbh, thumbhash FROM pic WHERE hash = @hash OR thumbhash = @hash OR hash = @baseHash OR thumbhash = @baseHash LIMIT 1',
{ hash: cleanHash, baseHash }
);
const row = result.rows[0];
if (!row) return null;
const fullHash = row.hash;
const useThumb = width <= 200 && height <= 200;
let buffer = null;
if (useThumb) {
buffer = await provider.readPicThumb?.(fullHash);
}
if (!buffer) {
buffer = await provider.readPicFull?.(fullHash);
}
if (!buffer && !useThumb) {
buffer = await provider.readPicThumb?.(fullHash);
}
if (!buffer) return null;
return {
buffer: Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer),
w: row.w,
h: row.h,
fullHash,
};
}
const result = await provider.query(
'SELECT TOP 1 w, h, size, hash, thumbw, thumbh, thumbhash, fullbinary, thumbbinary FROM pic WHERE hash = @hash OR thumbhash = @hash OR hash = @baseHash OR thumbhash = @baseHash',
isSqlite
? 'SELECT w, h, size, hash, thumbw, thumbh, thumbhash FROM pic WHERE hash = @hash OR thumbhash = @hash OR hash = @baseHash OR thumbhash = @baseHash LIMIT 1'
: 'SELECT TOP 1 w, h, size, hash, thumbw, thumbh, thumbhash FROM pic WHERE hash = @hash OR thumbhash = @hash OR hash = @baseHash OR thumbhash = @baseHash',
{ hash: cleanHash, baseHash }
);
const row = result.rows[0];
@@ -180,14 +151,21 @@ export async function getPosImageByHash(hash, { width = 200, height = 200 } = {}
const fullHash = row.hash;
const useThumb = width <= 200 && height <= 200;
const rawBuffer = useThumb
? (row.thumbbinary || row.fullbinary)
: (row.fullbinary || row.thumbbinary);
let buffer = null;
if (!rawBuffer) return null;
if (useThumb) {
buffer = await provider.readPicThumb?.(fullHash);
}
if (!buffer) {
buffer = await provider.readPicFull?.(fullHash);
}
if (!buffer && !useThumb) {
buffer = await provider.readPicThumb?.(fullHash);
}
if (!buffer) return null;
return {
buffer: Buffer.isBuffer(rawBuffer) ? rawBuffer : Buffer.from(rawBuffer),
buffer: Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer),
w: row.w,
h: row.h,
fullHash,

View File

@@ -127,6 +127,7 @@ function getMssqlConfig() {
user,
password,
port,
storageDir: env.storageDir,
pool: {
max: 10,
min: 0,
@@ -153,7 +154,7 @@ export async function getStore() {
if (env.dbProvider === 'sqlite' || env.dbProvider === 'better-sqlite3') {
provider = new BetterSqlite3Provider(env.sqlite);
} else {
provider = new MssqlProvider(getMssqlConfig());
provider = new MssqlProvider(getMssqlConfig(), { storageDir: env.storageDir });
}
await provider.initialize();
store = wrapStoreWithTiming(await new LibDashStore(provider));