Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v0.0.1 alpha.41 #38

Merged
merged 2 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
22 changes: 8 additions & 14 deletions src/controllers/merkleTreeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -317,6 +310,7 @@ export const uploadFile = async (
}

// Validate the key ownership signature using the nonce

const isSignatureValid = await Wallet.verifyKeyOwnershipSignature(
nonce,
keyOwnershipSig,
Expand Down
Loading