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.47 #43

Merged
merged 2 commits into from
Sep 24, 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.47](https://github.com/DIG-Network/dig-content-server/compare/v0.0.1-alpha.46...v0.0.1-alpha.47) (2024-09-24)


### Features

* test new udi scheme ([cdffa32](https://github.com/DIG-Network/dig-content-server/commit/cdffa32a0962f1a1b015466788f4e5c581afdb35))

### [0.0.1-alpha.46](https://github.com/DIG-Network/dig-content-server/compare/v0.0.1-alpha.45...v0.0.1-alpha.46) (2024-09-24)


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-content-server",
"version": "0.0.1-alpha.46",
"version": "0.0.1-alpha.47",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
18 changes: 10 additions & 8 deletions src/controllers/storeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,18 @@ export const getKeysIndex = async (req: Request, res: Response) => {

// Controller for handling the /:storeId/* route
export const getKey = async (req: Request, res: Response) => {
// @ts-ignore
let { chainName, storeId, rootHash, key: catchall } = req;
// Extract variables from the request object
let { storeId, rootHash, key: catchall } = req as any;

const key = Buffer.from(decodeURIComponent(catchall), "utf-8").toString(
"hex"
);
// Remove leading slash if present
const keyPath = catchall.startsWith('/') ? catchall.substring(1) : catchall;

// Decode and convert the key to hex
const key = Buffer.from(decodeURIComponent(keyPath), "utf-8").toString("hex");

try {
// Extract the challenge from query parameters
const challengeHex = req.query.challenge as string; // Expecting a hex string here
const challengeHex = req.query.challenge as string | undefined; // Expecting a hex string here

// If rootHash is not provided, fetch it from DataStore
if (!rootHash) {
Expand All @@ -195,7 +197,7 @@ export const getKey = async (req: Request, res: Response) => {

if (!datalayer.hasKey(key, rootHash)) {
res.setHeader("X-Key-Exists", "false");
return getKeysIndex(req, res);
return getKeysIndex(req, res); // Display index if key doesn't exist
}

// If a challenge hex is present, deserialize and create a challenge response
Expand Down Expand Up @@ -236,7 +238,7 @@ export const getKey = async (req: Request, res: Response) => {

// Otherwise, stream the file and return proof of inclusion
const stream = datalayer.getValueStream(key, rootHash);
const fileExtension = extname(catchall).toLowerCase();
const fileExtension = extname(keyPath).toLowerCase(); // Use keyPath instead of catchall
const sha256 = datalayer.getSHA256(key, rootHash);

if (!sha256) {
Expand Down
Loading