23 lines
805 B
JavaScript
23 lines
805 B
JavaScript
/**
|
|
* @module routes/hashRoutes
|
|
*/
|
|
|
|
import { Router } from 'express';
|
|
import { asyncHandler, AppError } from '../errors.js';
|
|
import { lookupHash } from '../services/timestampService.js';
|
|
|
|
export const hashRoutes = Router();
|
|
|
|
hashRoutes.get(
|
|
'/:sha256',
|
|
asyncHandler(async (req, res) => {
|
|
const { sha256 } = req.params;
|
|
if (!sha256 || !/^[a-fA-F0-9]{64}$/.test(sha256)) {
|
|
throw new AppError('sha256 must be 64 hex chars', { status: 400, code: 'VALIDATION_ERROR' });
|
|
}
|
|
const includeAttached = req.query.includeAttached === 'true' || req.query.includeAttached === '1';
|
|
const includeTree = req.query.includeTree === 'true' || req.query.includeTree === '1';
|
|
const result = await lookupHash(req.auth, sha256, { includeAttached, includeTree });
|
|
res.json(result);
|
|
}),
|
|
);
|