From 2bad62bb6be5711a1cb5aa1378d21a2c334c9956 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Fri, 20 Sep 2024 20:01:28 -0400 Subject: [PATCH 1/2] fix: head store controller --- src/controllers/merkleTreeController.ts | 57 +++++++++++++------------ 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/controllers/merkleTreeController.ts b/src/controllers/merkleTreeController.ts index c6802cf..4e40cf1 100644 --- a/src/controllers/merkleTreeController.ts +++ b/src/controllers/merkleTreeController.ts @@ -50,57 +50,56 @@ export const storeStatus = async ( // Controller to handle HEAD requests for /stores/:storeId export const headStore = async (req: Request, res: Response): Promise => { try { + console.log("Received request in headStore controller."); + const publicKey = req.headers["x-public-key"] as string; + console.log("Public Key:", publicKey); if (!publicKey) { + console.log("Missing x-public-key header."); throw new HttpError(400, "Missing x-public-key header"); } const userNonce = await generateNonce(publicKey); + console.log("Generated User Nonce:", userNonce); const { storeId } = req.params; + console.log("Store ID:", storeId); + const hasRootHash = req.query.hasRootHash as string; + console.log("Has Root Hash Query:", hasRootHash); if (!storeId) { + console.log("Missing path parameters."); throw new HttpError(400, "Missing path parameters"); } const dataStore = DataStore.from(storeId); + console.log("Data Store initialized for Store ID:", storeId); if (hasRootHash) { const rootHistory = await dataStore.getRootHistory(); + console.log("Root History:", rootHistory); + + const hasRootHashInHistory = rootHistory?.some( + // @ts-ignore + (history) => history.root_hash === hasRootHash && history.synced + ); + console.log(`Root hash ${hasRootHash} in history and synced:`, hasRootHashInHistory); + res.setHeader( "X-Has-RootHash", - rootHistory?.some( - // @ts-ignore - (history) => history.root_hash === hasRootHash && history.synced - ) - ? "true" - : "false" + hasRootHashInHistory ? "true" : "false" ); } - const manifestPath = path.join( - digFolderPath, - "stores", - storeId, - "manifest.dat" - ); - - if (!fs.existsSync(manifestPath)) { - res - .set({ - "x-store-id": storeId, - "x-upload-type": "direct", - ...(userNonce && { "x-nonce": userNonce }), - }) - .status(200) - .end(); - return; - } + const storeList = getStoresList(); + const hasStore = storeList.includes(storeId); + console.log("Store list:", storeList); + console.log("Has Store:", hasStore); - const manifestData = fs.readFileSync(manifestPath, "utf-8"); - if (!manifestData) { + if (!hasStore) { + console.log("Store not found, setting headers and responding."); res .set({ "x-store-id": storeId, @@ -112,8 +111,11 @@ export const headStore = async (req: Request, res: Response): Promise => { return; } - const hashes = manifestData.split("\n").filter((line) => line.length > 0); + const rootHistory = await dataStore.getRootHistory(); + const hashes = rootHistory.map((history) => history.root_hash); const lastHash = hashes.length > 0 ? hashes[hashes.length - 1] : null; + console.log("Root Hashes:", hashes); + console.log("Last Hash:", lastHash); res .set({ @@ -135,6 +137,7 @@ export const headStore = async (req: Request, res: Response): Promise => { } }; + // Controller to handle GET requests for /stores/:storeId export const getStore = async (req: Request, res: Response) => { try { From 7bab5e9281ec25825aaa3f6649a9575d8b729dda Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Fri, 20 Sep 2024 20:01:47 -0400 Subject: [PATCH 2/2] chore(release): 0.0.1-alpha.29 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d917b1..7491a6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.1-alpha.29](https://github.com/DIG-Network/dig-propagation-server/compare/v0.0.1-alpha.28...v0.0.1-alpha.29) (2024-09-21) + + +### Bug Fixes + +* head store controller ([2bad62b](https://github.com/DIG-Network/dig-propagation-server/commit/2bad62bb6be5711a1cb5aa1378d21a2c334c9956)) + ### [0.0.1-alpha.28](https://github.com/DIG-Network/dig-propagation-server/compare/v0.0.1-alpha.27...v0.0.1-alpha.28) (2024-09-20) ### [0.0.1-alpha.27](https://github.com/DIG-Network/dig-propagation-server/compare/v0.0.1-alpha.26...v0.0.1-alpha.27) (2024-09-20) diff --git a/package-lock.json b/package-lock.json index d882738..f1ccbf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "dig-propagation-server", - "version": "0.0.1-alpha.28", + "version": "0.0.1-alpha.29", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dig-propagation-server", - "version": "0.0.1-alpha.28", + "version": "0.0.1-alpha.29", "license": "ISC", "dependencies": { "@dignetwork/dig-sdk": "^0.0.1-alpha.52", diff --git a/package.json b/package.json index 019d795..51b3e55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dig-propagation-server", - "version": "0.0.1-alpha.28", + "version": "0.0.1-alpha.29", "description": "", "type": "commonjs", "main": "./dist/index.js",