games_app/backend/dist-test-faq/repositories/fileIntegrityRepository.js

30 lines
1.5 KiB
JavaScript

"use strict";
/**
* Persists SHA-256 baselines for uploaded file directories (FIM).
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.listSnapshots = listSnapshots;
exports.upsertSnapshot = upsertSnapshot;
exports.deleteSnapshot = deleteSnapshot;
exports.deleteAllForRoot = deleteAllForRoot;
const connection_1 = require("../db/connection");
async function listSnapshots(rootKey) {
return (0, connection_1.query)(`SELECT root_key, relative_path, content_sha256, size_bytes::text, updated_at
FROM file_integrity_snapshots
WHERE root_key = $1`, [rootKey]);
}
async function upsertSnapshot(input) {
await (0, connection_1.query)(`INSERT INTO file_integrity_snapshots (root_key, relative_path, content_sha256, size_bytes, updated_at)
VALUES ($1, $2, $3, $4, NOW())
ON CONFLICT (root_key, relative_path)
DO UPDATE SET content_sha256 = EXCLUDED.content_sha256,
size_bytes = EXCLUDED.size_bytes,
updated_at = NOW()`, [input.rootKey, input.relativePath, input.contentSha256, input.sizeBytes]);
}
async function deleteSnapshot(rootKey, relativePath) {
await (0, connection_1.query)(`DELETE FROM file_integrity_snapshots WHERE root_key = $1 AND relative_path = $2`, [rootKey, relativePath]);
}
async function deleteAllForRoot(rootKey) {
await (0, connection_1.query)(`DELETE FROM file_integrity_snapshots WHERE root_key = $1`, [rootKey]);
}
//# sourceMappingURL=fileIntegrityRepository.js.map