diff --git a/CHANGELOG.md b/CHANGELOG.md index 031f71c..a1f9540 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.41](https://github.com/DIG-Network/dig-propagation-server/compare/v0.0.1-alpha.40...v0.0.1-alpha.41) (2024-09-22) + + +### Features + +* upload dat file as part up upload session ([4b97d08](https://github.com/DIG-Network/dig-propagation-server/commit/4b97d08296c39d337221b8f73d50149b618ffa2f)) + ### [0.0.1-alpha.40](https://github.com/DIG-Network/dig-propagation-server/compare/v0.0.1-alpha.39...v0.0.1-alpha.40) (2024-09-22) diff --git a/package-lock.json b/package-lock.json index dcd0aa9..ef7e409 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "dig-propagation-server", - "version": "0.0.1-alpha.40", + "version": "0.0.1-alpha.41", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dig-propagation-server", - "version": "0.0.1-alpha.40", + "version": "0.0.1-alpha.41", "license": "ISC", "dependencies": { "@dignetwork/dig-sdk": "^0.0.1-alpha.57", diff --git a/package.json b/package.json index 513faf6..f96aeff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dig-propagation-server", - "version": "0.0.1-alpha.40", + "version": "0.0.1-alpha.41", "description": "", "type": "commonjs", "main": "./dist/index.js", diff --git a/src/controllers/merkleTreeController.ts b/src/controllers/merkleTreeController.ts index 8fd9907..6272077 100644 --- a/src/controllers/merkleTreeController.ts +++ b/src/controllers/merkleTreeController.ts @@ -212,24 +212,17 @@ export const startUploadSession = async ( session.resetTtl(); // Reset TTL on each chunk of data }); - // Extract the file and its metadata from the FormData body - const contentDisposition = req.headers["content-disposition"] || ""; - const matches = contentDisposition.match(/filename="(.+?)"/); - if (!matches) { - throw new HttpError(400, "Missing filename in the upload request."); - } - - const filename = matches[1]; - if (!/^[a-fA-F0-9]{64}\.dat$/.test(filename)) { - throw new HttpError(400, "Invalid rootHash format in the filename."); + const rootHash = req.query.roothash as string; + if (!rootHash || !/^[a-fA-F0-9]{64}$/.test(rootHash)) { + throw new HttpError(400, "Invalid or missing rootHash."); } - const rootHash = filename.split(".")[0]; // Extract rootHash from the file name - const tmpDatFilePath = path.join(session.tmpDir, filename); + // Create the file path for saving the uploaded .dat file + const tmpDatFilePath = path.join(session.tmpDir, `${rootHash}.dat`); + const fileStream = fs.createWriteStream(tmpDatFilePath); // Stream the file from the request body into the temp file - const fileWriteStream = fs.createWriteStream(tmpDatFilePath); - await streamPipeline(req.pipe(passThrough), fileWriteStream); + await streamPipeline(req.pipe(passThrough), fileStream); // Now validate the file once it's saved await validateDataFile(tmpDatFilePath, storeId); @@ -317,6 +310,7 @@ export const uploadFile = async ( } // Validate the key ownership signature using the nonce + const isSignatureValid = await Wallet.verifyKeyOwnershipSignature( nonce, keyOwnershipSig,