Skip to content

Commit

Permalink
Refactored asset page
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Jan 14, 2024
1 parent c9ffd64 commit 579983a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ app.use((req, res, next) => {
const html = xidb.getProfilePage(xid);
return res.status(200).send(html);
}
else {
else if (type === 'asset') {
const html = xidb.getAssetPage(xid);
return res.status(200).send(html);
}
else if (type === 'nft') {
const nftLink = `/data/assets/${xid}/index.html`;
console.log(`Redirecting to ${nftLink}`);
return res.redirect(nftLink);
Expand Down
16 changes: 14 additions & 2 deletions xidb.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,26 @@ function getProfilePage(xid, config = realConfig) {
agentData.link = `${config.link}/profile/${xid}`;
agentData.image = `${config.link}${agentData.pfp}`;

console.log(JSON.stringify(agentData, null, 4));

const templatePath = path.join(config.data, 'profile.ejs');
const template = fs.readFileSync(templatePath, 'utf8');
const html = ejs.render(template, agentData);

return html;
}

function getAssetPage(xid, config = realConfig) {
const assetData = asset.getAsset(xid, config);

assetData.asset.link = `${config.link}/asset/${xid}`;
assetData.asset.image = `${config.link}/data/assets/${xid}/${assetData.file.fileName}`;

const templatePath = path.join(config.data, 'asset.ejs');
const template = fs.readFileSync(templatePath, 'utf8');
const html = ejs.render(template, assetData);

return html;
}

function getNft(xid, config = realConfig) {
const jsonPath = path.join(config.assets, xid, 'nft.json');

Expand Down Expand Up @@ -1216,6 +1227,7 @@ module.exports = {
createCollection,
getAgentAndCollections,
getAllAgents,
getAssetPage,
getCollection,
getCollectionPage,
getListings,
Expand Down

0 comments on commit 579983a

Please sign in to comment.