61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
/**
|
|
* @module routes/timestampRoutes
|
|
*/
|
|
|
|
import { Router } from 'express';
|
|
import { asyncHandler, AppError } from '../errors.js';
|
|
import {
|
|
createTimestamp,
|
|
createTimestampAndWait,
|
|
createBatchTimestamp,
|
|
} from '../services/timestampService.js';
|
|
|
|
export const timestampRoutes = Router();
|
|
|
|
timestampRoutes.post(
|
|
'/',
|
|
asyncHandler(async (req, res) => {
|
|
const { data, hashAlg, sha256, publicMetadata, privateMetadata } = req.body ?? {};
|
|
if (!data && !sha256) {
|
|
throw new AppError('data or sha256 is required', { status: 400, code: 'VALIDATION_ERROR' });
|
|
}
|
|
const result = await createTimestamp(req.auth, {
|
|
data,
|
|
hashAlg,
|
|
sha256,
|
|
publicMetadata,
|
|
privateMetadata,
|
|
});
|
|
res.status(202).json(result);
|
|
}),
|
|
);
|
|
|
|
timestampRoutes.post(
|
|
'/wait',
|
|
asyncHandler(async (req, res) => {
|
|
const { data, hashAlg, sha256, publicMetadata, privateMetadata } = req.body ?? {};
|
|
if (!data && !sha256) {
|
|
throw new AppError('data or sha256 is required', { status: 400, code: 'VALIDATION_ERROR' });
|
|
}
|
|
const result = await createTimestampAndWait(req.auth, {
|
|
data,
|
|
hashAlg,
|
|
sha256,
|
|
publicMetadata,
|
|
privateMetadata,
|
|
});
|
|
res.json(result);
|
|
}),
|
|
);
|
|
|
|
timestampRoutes.post(
|
|
'/batch',
|
|
asyncHandler(async (req, res) => {
|
|
const { items } = req.body ?? {};
|
|
if (!Array.isArray(items) || items.length === 0) {
|
|
throw new AppError('items array is required', { status: 400, code: 'VALIDATION_ERROR' });
|
|
}
|
|
const result = await createBatchTimestamp(req.auth, { items });
|
|
res.status(202).json(result);
|
|
}),
|
|
);
|