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.29 #27

Merged
merged 2 commits into from
Sep 21, 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.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)
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.28",
"version": "0.0.1-alpha.29",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand Down
57 changes: 30 additions & 27 deletions src/controllers/merkleTreeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
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,
Expand All @@ -112,8 +111,11 @@ export const headStore = async (req: Request, res: Response): Promise<void> => {
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({
Expand All @@ -135,6 +137,7 @@ export const headStore = async (req: Request, res: Response): Promise<void> => {
}
};


// Controller to handle GET requests for /stores/:storeId
export const getStore = async (req: Request, res: Response) => {
try {
Expand Down
Loading