Skip to content

Commit

Permalink
attempt to fix avatar and catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
singharaj-usai committed Oct 18, 2024
1 parent bca00c6 commit 0e6e43f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 88 deletions.
56 changes: 28 additions & 28 deletions client/js/admin/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,34 @@ function displayRecentAssets(assets) {

const assetsTable = `
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Type</th>
<th>Creator</th>
<th>Price</th>
<th>Sales</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
${assets.map((asset) => `
<tr>
<td>${asset.assetId || 'N/A'}</td>
<td>${asset.Name || 'N/A'}</td>
<td>${asset.AssetType || 'N/A'}</td>
<td>${asset.creator && asset.creator.username ? asset.creator.username : 'Unknown'}</td>
<td>${asset.Price !== undefined ? asset.Price : 'N/A'}</td>
<td>${asset.Sales !== undefined ? asset.Sales : 'N/A'}</td>
<td>
<button class="btn btn-warning btn-xs edit-asset" data-asset-id="${asset._id}">Edit</button>
<button class="btn btn-danger btn-xs delete-asset" data-asset-id="${asset._id}">Delete</button>
${asset.AssetType !== 'Image' ? `<button class="btn btn-secondary btn-xs redraw-asset" data-asset-id="${asset._id}">Redraw</button>` : ''}
</td>
</tr>
`).join('')}
</tbody>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Type</th>
<th>Creator</th>
<th>Price</th>
<th>Sales</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
${assets.map((asset) => `
<tr>
<td>${asset.assetId || 'N/A'}</td>
<td>${asset.Name || 'N/A'}</td>
<td>${asset.AssetType || 'N/A'}</td>
<td>${asset.creator && asset.creator.username ? asset.creator.username : 'Unknown'}</td>
<td>${asset.Price !== undefined ? asset.Price : 'N/A'}</td>
<td>${asset.Sales !== undefined ? asset.Sales : 'N/A'}</td>
<td>
<button class="btn btn-warning btn-xs edit-asset" data-asset-id="${asset._id}">Edit</button>
<button class="btn btn-danger btn-xs delete-asset" data-asset-id="${asset._id}">Delete</button>
${asset.AssetType !== 'Image' ? `<button class="btn btn-secondary btn-xs redraw-asset" data-asset-id="${asset._id}">Redraw</button>` : ''}
</td>
</tr>
`).join('')}
</tbody>
</table>
`;

Expand Down
39 changes: 13 additions & 26 deletions client/js/admin/games.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,22 @@ function displayGames(games) {

games.forEach((game) => {
gamesList.append(`
<div class="col-md-4 col-sm-6 mb-4">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">${escapeHtml(game.title)}</h3>
</div>
<div class="panel-body">
<div style="width: 100%; padding-top: 56.25%; position: relative; overflow: hidden;">
<img src="${
game.thumbnailUrl ||
'/images/default-game-thumbnail.png'
}" alt="${escapeHtml(
game.title
)} thumbnail" class="img-responsive" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover;">
<div class="col-md-4 col-sm-6 mb-4">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">${escapeHtml(game.title)}</h3>
</div>
<div class="panel-body">
<div style="width: 100%; padding-top: 56.25%; position: relative; overflow: hidden;">
<img src="${game.thumbnailUrl || '/images/default-game-thumbnail.png'}" alt="${escapeHtml(game.title)} thumbnail" class="img-responsive" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover;">
</div>
<p><strong>Creator:</strong> ${escapeHtml(
game.creator.username
)}</p>
<p><strong>Created:</strong> ${new Date(
game.createdAt
).toLocaleString()}</p>
<p><strong>Description:</strong> ${escapeHtml(
game.description || 'No description provided.'
)}</p>
<p><strong>Creator:</strong> ${escapeHtml(game.creator.username)}</p>
<p><strong>Created:</strong> ${new Date(game.createdAt).toLocaleString()}</p>
<p><strong>Description:</strong> ${escapeHtml(game.description || 'No description provided.')}</p>
</div>
<div class="panel-footer">
<button class="btn btn-danger btn-block delete-game" data-game-id="${
game._id
}">
<i class="glyphicon glyphicon-trash"></i> Delete Game
<button class="btn btn-danger btn-block delete-game" data-game-id="${game._id}">
<i class="glyphicon glyphicon-trash"></i> Delete Game
</button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/js/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function displayShirts(shirts) {
}" style="max-height: 150px;">
<hr>
<p><strong>Creator:</strong> ${
shirt.creator ? shirt.creator.username : 'Unknown'
shirt.creator && shirt.creator.username ? shirt.creator.username : 'Unknown'
}</p>
<p><strong>Price:</strong> ${shirt.Price} currency</p>
<p><strong>For Sale:</strong> ${
Expand Down
54 changes: 28 additions & 26 deletions server/functions/api/routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,6 @@ router.get('/assets/recent', authenticateToken, async (req, res) => {
}
});

// redraw the specific asset
router.post('/assets/:id/redraw', authenticateToken, async (req, res) => {
const assetId = req.params.id;

try {
const asset = await Asset.findById(assetId).populate('creator', 'username');
if (!asset) {
return res.status(404).json({ error: 'Asset not found' });
}

if (asset.AssetType === 'Image') {
return res.status(400).json({ error: 'Image assets cannot be redrawn' });
}

try {
await thumbnailQueue.addToQueue(asset.assetId, asset.AssetType);
res.json({ message: 'Asset redraw queued successfully' });
} catch (queueError) {
console.error('Error adding to thumbnail queue:', queueError);
res.status(500).json({ error: 'Error queuing asset redraw' });
}
} catch (error) {
console.error('Error processing asset redraw:', error);
res.status(500).json({ error: 'Internal server error' });
}
});

// get the asset by id
router.get('/assets/:id', authenticateToken, async (req, res) => {
Expand Down Expand Up @@ -180,6 +154,34 @@ router.get('/assets/:id', authenticateToken, async (req, res) => {
}
});

// redraw the specific asset
router.post('/assets/:id/redraw', authenticateToken, async (req, res) => {
const assetId = req.params.id;

try {
const asset = await Asset.findById(assetId).populate('creator', 'username');
if (!asset) {
return res.status(404).json({ error: 'Asset not found' });
}

if (asset.AssetType === 'Image') {
return res.status(400).json({ error: 'Image assets cannot be redrawn' });
}

try {
await thumbnailQueue.addToQueue(asset.assetId, asset.AssetType);
res.json({ message: 'Asset redraw queued successfully' });
} catch (queueError) {
console.error('Error adding to thumbnail queue:', queueError);
res.status(500).json({ error: 'Error queuing asset redraw' });
}
} catch (error) {
console.error('Error processing asset redraw:', error);
res.status(500).json({ error: 'Internal server error' });
}
});


// update asset
router.put('/assets/:id', authenticateToken, async (req, res) => {
const assetId = req.params.id;
Expand Down
21 changes: 14 additions & 7 deletions server/functions/api/routes/shirt.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ router.get('/', async (req, res) => {
const shirts = await Shirt.find().populate('creator', 'username');
res.json(shirts);
} catch (error) {
console.error('Error fetching shirts:', error);
res.status(500).json({ error: error.message });
}
});
Expand Down Expand Up @@ -186,6 +187,12 @@ router.post(
});
}

const user = await User.findOne({ userId: req.user.userId });
if (!user) {
return res.status(404).json({ error: 'User not found.' });
}


const assetHash = generateAssetId();
const assetId = await getNextAssetId();

Expand All @@ -212,7 +219,7 @@ router.post(
const asset = new Asset({
assetId: assetId,
FileLocation: assetLocation,
creator: req.user.userId,
creator: user._id, // Use the user's ObjectId here
AssetType: 'Image',
Name: filter.clean(title),
Description: filter.clean(description),
Expand Down Expand Up @@ -251,7 +258,7 @@ router.post(
const shirt = new Asset({
assetId: shirtassetId,
FileLocation: shirtassetLocation,
creator: req.user.userId,
creator: user._id, // Use the user's ObjectId here
AssetType: 'Shirt',
Name: filter.clean(title),
Description: filter.clean(description),
Expand Down Expand Up @@ -301,9 +308,9 @@ router.delete('/:id', authenticateToken, async (req, res) => {

router.get('/catalog', async (req, res) => {
try {
const shirts = await Asset.find({ AssetType: 'Shirt', IsForSale: 1 }).sort({
createdAt: -1,
});
const shirts = await Asset.find({ AssetType: 'Shirt', IsForSale: 1 })
.populate('creator', 'username')
.sort({ createdAt: -1 })
res.json(shirts);
} catch (error) {
console.error('Error fetching catalog shirts:', error);
Expand Down Expand Up @@ -401,11 +408,11 @@ router.get('/user/id/:id', authenticateToken, async (req, res) => {
const createdShirts = await Asset.find({
creator: userId,
AssetType: 'Shirt',
}).sort({ createdAt: -1 });
}).populate('creator', 'username').sort({ createdAt: -1 });
const ownedShirts = await Asset.find({
_id: { $in: user.inventory },
AssetType: 'Shirt',
}).sort({ createdAt: -1 });
}).populate('creator', 'username').sort({ createdAt: -1 });
const allShirts = [...createdShirts, ...ownedShirts];
const uniqueShirts = Array.from(
new Set(allShirts.map((s) => s._id.toString()))
Expand Down

0 comments on commit 0e6e43f

Please sign in to comment.