diff --git a/.gitignore b/.gitignore index c075b4a..4a01d8c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules .dig dist -dig.config.json \ No newline at end of file +dig.config.json +.env diff --git a/CHANGELOG.md b/CHANGELOG.md index d449b7a..eb2c079 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ 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.98](https://github.com/DIG-Network/dig-content-server/compare/v0.0.1-alpha.97...v0.0.1-alpha.98) (2024-11-16) + + +### Features + +* add subdomain resolver ([d9c7647](https://github.com/DIG-Network/dig-content-server/commit/d9c76470c0444bcc6729eec43c9e5143c1592709)) +* update UDI handling ([9f1ca3b](https://github.com/DIG-Network/dig-content-server/commit/9f1ca3bc41103c55a7591a7d5ca681ecacc462d9)) + + +### Bug Fixes + +* strip off leading slash in parse udi ([f9846e0](https://github.com/DIG-Network/dig-content-server/commit/f9846e0d0bb11fdde55d6b9eccee8786597f0ef2)) +* udi subdomain ([776eea5](https://github.com/DIG-Network/dig-content-server/commit/776eea5fba9e75f012a8519f5c2706e52b9f840a)) +* udi subdomain ([498f2dc](https://github.com/DIG-Network/dig-content-server/commit/498f2dcc62c5bd4cfdd03e522d6aa022e665601d)) +* udi subdomain ([7761150](https://github.com/DIG-Network/dig-content-server/commit/7761150c0a1450848f35bd1b2220637025fba724)) +* udi subdomain ([1985abd](https://github.com/DIG-Network/dig-content-server/commit/1985abd506dc3b8a949aa164c91ff362a74f6e0b)) +* udi subdomain ([7354f9c](https://github.com/DIG-Network/dig-content-server/commit/7354f9c9b4662987f3e2a8164f4289b25e8cda2c)) +* udi subdomain ([2454d8c](https://github.com/DIG-Network/dig-content-server/commit/2454d8cbf988ca10e86fb16110ae762fc5a11ab6)) +* udi subdomain ([6122bf5](https://github.com/DIG-Network/dig-content-server/commit/6122bf5c25a28f63d3b131ceebe0eabfa2a21451)) +* udi subdomain ([0a4b2a2](https://github.com/DIG-Network/dig-content-server/commit/0a4b2a2c0672d46df8f08a5041d345e6cc776b47)) +* udi subdomain ([01660d5](https://github.com/DIG-Network/dig-content-server/commit/01660d5ecbb80ce3b6aa255a691294d53fb962a5)) + ### [0.0.1-alpha.97](https://github.com/DIG-Network/dig-content-server/compare/v0.0.1-alpha.96...v0.0.1-alpha.97) (2024-10-29) diff --git a/package-lock.json b/package-lock.json index 8be02c1..1121b5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,23 +1,25 @@ { "name": "dig-content-server", - "version": "0.0.1-alpha.97", + "version": "0.0.1-alpha.98", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dig-content-server", - "version": "0.0.1-alpha.97", + "version": "0.0.1-alpha.98", "license": "ISC", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.28", - "@dignetwork/dig-sdk": "^0.0.1-alpha.169", + "@dignetwork/dig-sdk": "^0.0.1-alpha.194", "add": "^2.0.6", "cheerio": "^1.0.0", "cookie-parser": "^1.4.6", "cors": "^2.8.5", + "dotenv": "^16.4.5", "express": "^4.19.2", "qs": "^6.13.0", - "superagent": "^10.1.0" + "superagent": "^10.1.0", + "urns": "^0.6.0" }, "bin": { "dig": "dist/index.js" @@ -245,13 +247,14 @@ } }, "node_modules/@dignetwork/dig-sdk": { - "version": "0.0.1-alpha.169", - "resolved": "https://registry.npmjs.org/@dignetwork/dig-sdk/-/dig-sdk-0.0.1-alpha.169.tgz", - "integrity": "sha512-lDrsTbNuDz1KXRkAmOy6D07S4pUpoqZPBdeYf94pKIOuFyOd79HgI2n+afpIJTdx6PjZbyKWCKpIQXDNQ258Fw==", + "version": "0.0.1-alpha.194", + "resolved": "https://registry.npmjs.org/@dignetwork/dig-sdk/-/dig-sdk-0.0.1-alpha.194.tgz", + "integrity": "sha512-yo7LgOYaGZ+xyTLWI/RtmIRoYAyzMVyePQp20d83TFTPqMf+/h3yjWzgqp3wDQf93JADOarBdkPZ8xEMZMqcIQ==", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.29", "@dignetwork/dig-sdk": "^0.0.1-alpha.158", "archiver": "^7.0.1", + "async-mutex": "^0.5.0", "axios": "^1.7.7", "bip39": "^3.1.0", "bottleneck": "^2.19.5", @@ -264,8 +267,9 @@ "crypto-js": "^4.2.0", "figures": "^6.1.0", "fs-extra": "^11.2.0", + "hi-base32": "^0.5.1", "ignore": "^5.3.2", - "inquirer": "^10.1.8", + "inquirer": "^10.2.2", "lodash": "^4.17.21", "merkletreejs": "^0.4.0", "nanospinner": "^1.1.0", @@ -274,8 +278,10 @@ "node-stun": "^0.1.2", "progress-stream": "^2.0.0", "proper-lockfile": "^4.1.2", + "redis": "^4.7.0", "superagent": "^10.0.0", - "unzipper": "^0.12.3" + "unzipper": "^0.12.3", + "urns": "^0.6.0" } }, "node_modules/@ethereumjs/rlp": { @@ -671,6 +677,65 @@ "node": ">=14" } }, + "node_modules/@redis/bloom": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@redis/bloom/-/bloom-1.2.0.tgz", + "integrity": "sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg==", + "license": "MIT", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/client": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@redis/client/-/client-1.6.0.tgz", + "integrity": "sha512-aR0uffYI700OEEH4gYnitAnv3vzVGXCFvYfdpu/CJKvk4pHfLPEy/JSZyrpQ+15WhXe1yJRXLtfQ84s4mEXnPg==", + "license": "MIT", + "dependencies": { + "cluster-key-slot": "1.1.2", + "generic-pool": "3.9.0", + "yallist": "4.0.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/@redis/graph": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@redis/graph/-/graph-1.1.1.tgz", + "integrity": "sha512-FEMTcTHZozZciLRl6GiiIB4zGm5z5F3F6a6FZCyrfxdKOhFlGkiAqlexWMBzCi4DcRoyiOsuLfW+cjlGWyExOw==", + "license": "MIT", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/json": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@redis/json/-/json-1.0.7.tgz", + "integrity": "sha512-6UyXfjVaTBTJtKNG4/9Z8PSpKE6XgSyEb8iwaqDcy+uKrd/DGYHTWkUdnQDyzm727V7p21WUMhsqz5oy65kPcQ==", + "license": "MIT", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/search": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@redis/search/-/search-1.2.0.tgz", + "integrity": "sha512-tYoDBbtqOVigEDMAcTGsRlMycIIjwMCgD8eR2t0NANeQmgK/lvxNAvYyb6bZDD4frHRhIHkJu2TBRvB0ERkOmw==", + "license": "MIT", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, + "node_modules/@redis/time-series": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@redis/time-series/-/time-series-1.1.0.tgz", + "integrity": "sha512-c1Q99M5ljsIuc4YdaCwfUEXsofakb9c8+Zse2qxTadu8TalLXuAESzLvFAvNVbkmSlvlzIQOLpBCmWI9wTOt+g==", + "license": "MIT", + "peerDependencies": { + "@redis/client": "^1.0.0" + } + }, "node_modules/@scure/base": { "version": "1.1.9", "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.9.tgz", @@ -1112,6 +1177,15 @@ "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==" }, + "node_modules/async-mutex": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.5.0.tgz", + "integrity": "sha512-1A94B18jkJ3DYq284ohPxoXbfTA5HsQ7/Mf4DEhcyLx3Bz27Rh59iScbB6EPiP+B+joue6YCxcMXSbFC1tZKwA==", + "license": "MIT", + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -1710,6 +1784,15 @@ "node": ">=0.8" } }, + "node_modules/cluster-key-slot": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.2.tgz", + "integrity": "sha512-RMr0FhtfXemyinomL4hrWcYJxmX6deFdCxpJzhDttxgO1+bcCnkk+9drydLVDmAMG7NE6aN/fl4F7ucU/90gAA==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -2535,6 +2618,18 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dotgitignore": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/dotgitignore/-/dotgitignore-2.1.0.tgz", @@ -3083,6 +3178,15 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/generic-pool": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.9.0.tgz", + "integrity": "sha512-hymDOu5B53XvN4QT9dBmZxPX4CWhBPPLguTZ9MMFeFa/Kg0xWVfylOVNlJji/E7yTZWFd/q9GO5TxDLq156D7g==", + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -3399,6 +3503,12 @@ "node": ">=8" } }, + "node_modules/hi-base32": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/hi-base32/-/hi-base32-0.5.1.tgz", + "integrity": "sha512-EmBBpvdYh/4XxsnUybsPag6VikPYnN30td+vQk+GI3qpahVEG9+gTkG0aXVxTjBqQ5T6ijbWIu77O+C5WFWsnA==", + "license": "MIT" + }, "node_modules/hosted-git-info": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-4.1.0.tgz", @@ -5119,6 +5229,23 @@ "node": ">=8" } }, + "node_modules/redis": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/redis/-/redis-4.7.0.tgz", + "integrity": "sha512-zvmkHEAdGMn+hMRXuMBtu4Vo5P6rHQjLoHftu+lBqq8ZTA3RCVC/WzD790bkKKiNFp7d5/9PcSD19fJyyRvOdQ==", + "license": "MIT", + "workspaces": [ + "./packages/*" + ], + "dependencies": { + "@redis/bloom": "1.2.0", + "@redis/client": "1.6.0", + "@redis/graph": "1.1.1", + "@redis/json": "1.0.7", + "@redis/search": "1.2.0", + "@redis/time-series": "1.1.0" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -6026,6 +6153,12 @@ "node-int64": "^0.4.0" } }, + "node_modules/urns": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/urns/-/urns-0.6.0.tgz", + "integrity": "sha512-KqXGkRiq76KDvw+wHusJL0fSVltnF3Teqf1BK4f1xK3p1u1NAYYBQRsP89nw5CV/y+egjehITVPLh6upfqFdLg==", + "license": "MIT" + }, "node_modules/utf8": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz", @@ -6196,8 +6329,7 @@ "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/yargs": { "version": "16.2.0", diff --git a/package.json b/package.json index 8d5349b..fceabdc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dig-content-server", - "version": "0.0.1-alpha.97", + "version": "0.0.1-alpha.98", "description": "", "type": "commonjs", "main": "./dist/index.js", @@ -26,14 +26,16 @@ ], "dependencies": { "@dignetwork/datalayer-driver": "^0.1.28", - "@dignetwork/dig-sdk": "^0.0.1-alpha.169", + "@dignetwork/dig-sdk": "^0.0.1-alpha.194", "add": "^2.0.6", "cheerio": "^1.0.0", "cookie-parser": "^1.4.6", "cors": "^2.8.5", + "dotenv": "^16.4.5", "express": "^4.19.2", "qs": "^6.13.0", - "superagent": "^10.1.0" + "superagent": "^10.1.0", + "urns": "^0.6.0" }, "devDependencies": { "@types/cookie-parser": "^1.4.7", diff --git a/src/controllers/storeController.ts b/src/controllers/storeController.ts index e084346..74a9908 100644 --- a/src/controllers/storeController.ts +++ b/src/controllers/storeController.ts @@ -10,6 +10,7 @@ import { DataStore, DigChallenge, DigNetwork, + Udi } from "@dignetwork/dig-sdk"; import { formatBytes } from "../utils/formatBytes"; import { @@ -80,13 +81,14 @@ export const getStoresIndex = async (req: Request, res: Response) => { const rows = await Promise.all( storeList.map(async (storeId: string) => { const dataStore = DataStore.from(storeId); - const { latestStore: state} = await dataStore.fetchCoinInfo(); + const { latestStore: state } = await dataStore.fetchCoinInfo(); const formattedBytes = formatBytes(Number(state.metadata.bytes)); + const udi = new Udi(chainName, storeId); return renderIndexView( - chainName || "chia", - storeId, + udi, state, - formattedBytes + formattedBytes, + req.headers.host as string ); }) ); @@ -113,14 +115,12 @@ export const getKeysIndex = async (req: Request, res: Response) => { storeId, rootHash ); - + const udi = new Udi(chainName, storeId, rootHash); return res .status(400) .send( renderStoreNotFoundView( - storeId, - rootHash, - chainName, + udi, peerRedirect?.IpAddress ) ); @@ -188,6 +188,9 @@ export const getKeysIndex = async (req: Request, res: Response) => { }; try { + // Prepare the script tag to inject + // const baseUrl = `${chainName}:${storeId}:${rootHash}`; + // Read the stream and get the index.html content const indexContent = await streamToString(stream); @@ -230,7 +233,8 @@ export const getKeysIndex = async (req: Request, res: Response) => { const keys = datalayer.listKeys(rootHash); const links = keys.map((key: string) => { const utf8Key = hexToUtf8(key); - const link = `/${chainName}.${storeId}.${rootHash}/${utf8Key}`; + const udi = new Udi(chainName, storeId, rootHash, utf8Key); + const link = `/${udi.toUrn()}`; return { utf8Key, link }; }); @@ -377,7 +381,7 @@ export const getKey = async (req: Request, res: Response) => { res.setHeader("X-Store-Id", storeId); res.setHeader("X-Key-Exists", "true"); res.setHeader("Content-Type", "application/json"); - + return res.json({ clsp: clspCode, params: params, diff --git a/src/index.ts b/src/index.ts index a177e6a..76cd618 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import 'dotenv/config' import { startContentServer } from "./server"; startContentServer(); \ No newline at end of file diff --git a/src/middleware/parseUdi.ts b/src/middleware/parseUdi.ts index 04044dc..6beaa0e 100644 --- a/src/middleware/parseUdi.ts +++ b/src/middleware/parseUdi.ts @@ -1,34 +1,9 @@ import { Request, Response, NextFunction } from "express"; import { renderUnknownChainView } from "../views"; -import { DataStore } from "@dignetwork/dig-sdk"; -import { app } from "../app"; +import { DataStore, Udi } from "@dignetwork/dig-sdk"; const validChainNames = ["chia"]; // List of valid chain names -function removeDuplicatePathPart(path: string): string { - // Split the path into segments, ignoring leading/trailing slashes - const parts = path.split('/').filter(part => part.length > 0); - - // Check if the path has at least two segments - if (parts.length >= 2) { - const firstPart = parts[0]; - const secondPart = parts[1]; - - // Check if the first two parts are identical and at least 64 characters long - if (firstPart === secondPart && firstPart.length >= 64) { - // Remove the duplicate second part - parts.splice(1, 1); - } - } - - const modifiedPath = '/' + parts.join('/'); - console.log('Original path:', path); - console.log('Modified path:', modifiedPath); - - // Reconstruct the path with a leading slash - return modifiedPath; -} - export const parseUdi = async ( req: Request, res: Response, @@ -40,155 +15,42 @@ export const parseUdi = async ( return next(); } - // Extract the path and query string separately - const [path, queryString] = req.originalUrl.split("?"); - - // Apply removeDuplicatePathPart to the request path - const modifiedPath = removeDuplicatePathPart(path); - - // Re-append the query string if it exists - const modifiedUrl = queryString ? `${modifiedPath}?${queryString}` : modifiedPath; + // strip off the query string as that is not part of the udi + const [path] = req.originalUrl.replace(/^\//, "").split("?"); + console.log('path:', path); + const udi = Udi.fromUrn(path); - const referrer = req.get("Referer") || ""; - let cookieData = req.cookies.udiData || null; - - let chainName: string | null = null; - let storeId: string = ""; - let rootHash: string | null = null; - - // Use modifiedPath instead of req.originalUrl - const pathSegments = modifiedPath.split("/").filter(segment => segment.length > 0); - - // Extract the first path part as the storeId (assumed app identifier) - const pathSegment = pathSegments[0] || ""; // Expecting storeId to be the first path segment - const originalPathSegments = pathSegments.slice(1); // Remove the first segment, which is the storeId part - let appendPath = - originalPathSegments.length > 0 - ? `/${originalPathSegments.join("/")}` - : ""; - - // Split the pathSegment by periods to extract potential components - const parts = pathSegment.split("."); - - if (parts.length === 1 && parts[0].length !== 64) { - appendPath = `/${parts[0]}${appendPath}`; - } - - if (parts.length === 3) { - chainName = parts[0]; - storeId = parts[1]; - rootHash = parts[2]; // rootHash provided in the URL - } else if (parts.length === 2) { - if (parts[0].length === 64) { - storeId = parts[0]; - rootHash = parts[1]; // rootHash provided in the URL - } else { - chainName = parts[0]; - storeId = parts[1]; - } - } else if (parts.length === 1) { - storeId = parts[0]; + // Validate the chainName + if (!validChainNames.includes(udi.chainName)) { + console.warn("Invalid chain name:", udi.chainName); + return res.status(400).send(renderUnknownChainView(udi)); } // Log extracted values - console.log( - "Extracted values - Chain Name:", - chainName, - "Store ID:", - storeId, - "Root Hash:", - rootHash - ); + console.log(`Extracted urn:`, udi.toUrn()); - // Validate storeId length - if (!storeId || storeId.length !== 64) { - if (cookieData) { - const { chainName: cookieChainName, storeId: cookieStoreId } = cookieData; - - console.warn("Invalid storeId, redirecting to referrer:", referrer); - return res.redirect( - 302, - `/${cookieChainName}.${cookieStoreId}` + appendPath - ); - } - - if (referrer) { - console.warn("Invalid storeId, redirecting to referrer:", referrer); - return res.redirect(302, referrer + appendPath); - } - return res.status(400).send("Invalid or missing storeId."); - } - - // Fallback to cookie only if storeId matches the cookie's storeId - if (!chainName || !rootHash) { - if (cookieData) { - const { - chainName: cookieChainName, - storeId: cookieStoreId, - rootHash: cookieRootHash, - } = cookieData; - - // Only use cookie data if the storeId matches - if (!storeId || cookieStoreId === storeId || cookieRootHash === rootHash) { - console.log("Using cookie data as storeId matches:", storeId); - chainName = chainName || cookieChainName; - rootHash = rootHash || cookieRootHash; - } else { - console.log("StoreId changed, ignoring cookie data."); - } - } - } - - const dataStore = DataStore.from(storeId); - - // Early exit: If both chainName and rootHash are missing, fetch rootHash and redirect with both added - if (!chainName && !rootHash) { - console.log("Both chainName and rootHash omitted, fetching rootHash..."); - const storeInfo = await dataStore.fetchCoinInfo(); - rootHash = storeInfo.latestStore.metadata.rootHash.toString("hex"); - - const redirect = `/chia.${storeId}.${rootHash}${appendPath}${queryString ? '?' + queryString : ''}`; - console.log("Redirecting to:", redirect); - return res.redirect(302, redirect); - } - - // If chainName is missing, assume "chia" - if (!chainName) { - console.log("ChainName omitted, defaulting to 'chia'."); - return res.redirect(302, `/chia.${pathSegment}${appendPath}${queryString ? '?' + queryString : ''}`); - } - - // Validate the chainName - if (!validChainNames.includes(chainName)) { - console.warn("Invalid chain name:", chainName); - return res.status(400).send(renderUnknownChainView(storeId, chainName)); - } + const dataStore = DataStore.from(udi.storeId); + let rootHash = udi.rootHash; // If rootHash is missing, fetch the latest one if (!rootHash) { console.log("RootHash omitted, fetching the latest rootHash..."); const storeInfo = await dataStore.fetchCoinInfo(); - rootHash = storeInfo.latestStore.metadata.rootHash.toString("hex"); + rootHash = storeInfo.latestStore.metadata.rootHash.toString('hex'); } // Attach extracted components to the request object // @ts-ignore - req.chainName = chainName; + req.chainName = udi.chainName; // @ts-ignore - req.storeId = storeId; + req.storeId = udi.storeId; // @ts-ignore req.rootHash = rootHash; + //@ts-ignore + req.udi = udi; - res.cookie( - "udiData", - { chainName, storeId, rootHash }, - { - httpOnly: true, - secure: false, - maxAge: 1 * 60 * 1000, // Cookie expires after 5 minutes - expires: new Date(Date.now() + 1 * 60 * 1000), - } - ); + //@ts-ignore + console.log('!!!!', req.chainName, req.storeId, req.rootHash); next(); } catch (error) { diff --git a/src/views/indexView.ts b/src/views/indexView.ts index adc5a49..a1bf0f5 100644 --- a/src/views/indexView.ts +++ b/src/views/indexView.ts @@ -1,44 +1,65 @@ +import { Udi } from "@dignetwork/dig-sdk"; +import { Request } from "express"; + export const renderIndexView = ( - chainName: string, - storeId: string, + udi: Udi, state: any, - formattedBytes: string + formattedBytes: string, + host: string ) => { + const urn = udi.toUrn(); const isSyncing = !state; // Check if state is null - const toastId = `toast-${storeId}`; // Unique ID for the toast + const toastId = `toast-${udi.storeId}`; // Unique ID for the toast return `

- ${isSyncing ? "Syncing..." : (state.metadata.label || "No Label")} - ${isSyncing ? '' : ""} + ${isSyncing ? "Syncing..." : state.metadata.label || "No Label"} + ${ + isSyncing + ? '' + : "" + }

- ${isSyncing ? "Syncing data, please wait..." : (state.metadata.description || "No Description Available")} + ${ + isSyncing + ? "Syncing data, please wait..." + : state.metadata.description || "No Description Available" + }

- Store ID: ${storeId} - + Store: ${urn} + +

+ View as Webapp +

${isSyncing ? "Syncing..." : formattedBytes} - ${isSyncing ? '' : ""} + ${ + isSyncing + ? '' + : "" + }