21 lines
789 B
JavaScript
21 lines
789 B
JavaScript
import { GET_CATEGORY_ID_BY_HASH as MSSQL_GET } from '../../providers/mssql/queries/pic.js';
|
|
import { GET_CATEGORY_ID_BY_HASH as SQLITE_GET } from '../../providers/sqlite3/queries/pic.js';
|
|
import resolveCategoryAccess from '../category/resolveCategoryAccess.js';
|
|
import makeRunner from '../runner.js';
|
|
|
|
export default function resolvePicAccess(provider) {
|
|
const access = resolveCategoryAccess(provider);
|
|
const sql = provider?.dialect === 'sqlite3' ? SQLITE_GET : MSSQL_GET;
|
|
|
|
return async (googleAuthId, fullHash, tx) => {
|
|
const result = await makeRunner(provider, tx).query(sql, { hash: fullHash });
|
|
|
|
const categoryId = result.rows[0]?.categoryId;
|
|
if (!categoryId) {
|
|
throw new Error('Image not found');
|
|
}
|
|
|
|
await access(googleAuthId, categoryId, tx);
|
|
};
|
|
}
|