Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #148 from capsule-corp-ternoa/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
Leouarz authored Dec 15, 2021
2 parents f20fbd0 + e9c058d commit ae52cac
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nft-marketplace-api",
"version": "1.2.0",
"version": "1.2.1",
"description": "ternoa nft marketplace server",
"main": "dist/index.js",
"scripts": {
Expand Down
61 changes: 48 additions & 13 deletions src/api/helpers/nftHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function populateNFT(
seriesData: CustomResponse<INFT>,
query: NFTsQuery
): Promise<ICompleteNFT | INFT> {
const [serieData, creatorData, ownerData, info, categories, locked] =
const [serieData, creatorData, ownerData, info, categories, seriesLocked] =
await Promise.all([
populateSerieData(NFT, seriesData, query),
populateNFTCreator(NFT),
Expand All @@ -36,7 +36,7 @@ export async function populateNFT(
populateNFTCategories(NFT),
populateNFTSeriesObject(NFT.serieId)
]);
return { ...NFT, ...serieData, creatorData, ownerData, ...info, categories, locked};
return { ...NFT, ...serieData, creatorData, ownerData, ...info, categories, seriesLocked};
}

export async function populateSerieData(
Expand Down Expand Up @@ -204,17 +204,15 @@ export async function populateNFTIpfs(NFT: INFT): Promise<any> {
}
if (info.properties) {
// set url format
info.properties.preview.ipfs = isURL(info.properties.preview.ipfs)
? info.properties.preview.ipfs
: `${ipfsGatewayUri}/${info.properties.preview.ipfs}`;
info.properties.cryptedMedia.ipfs = isURL(
info.properties.cryptedMedia.ipfs
)
? info.properties.cryptedMedia.ipfs
: `${ipfsGatewayUri}/${info.properties.cryptedMedia.ipfs}`;
info.image = isURL(info.image)
? info.image
: `${ipfsGatewayUri}/${info.image}`;
info.properties.preview.ipfs = isURL(info.properties.preview.ipfs) ? info.properties.preview.ipfs : `${ipfsGatewayUri}/${info.properties.preview.ipfs}`;
info.properties.cryptedMedia.ipfs = isURL(info.properties.cryptedMedia.ipfs) ? info.properties.cryptedMedia.ipfs : `${ipfsGatewayUri}/${info.properties.cryptedMedia.ipfs}`;
const imageHash = isURL(info.image) ? `${info.image.split('/')[info.image.split('/').length - 1]}` : `${info.image}`
const thumbnailHash = getHappyTiimeThumbnails(imageHash)
if (thumbnailHash){
info.image = `${ipfsGatewayUri}/${thumbnailHash}`;
}else{
info.image = isURL(info.image) ? info.image : `${ipfsGatewayUri}/${info.image}`;
}
}
return info;
} else {
Expand Down Expand Up @@ -259,3 +257,40 @@ export async function populateNFTCategories(NFT: INFT): Promise<ICategory[]> {
return null;
}
}

/**
* Populates an NFT object with series object from indexer
* @param seriesId - Series Id of NFT
* @returns True if series is locked, false if unlocked, null if can't get data
*/
export function getHappyTiimeThumbnails(videoHash: string): string | null {
switch(videoHash){
case "QmanaNsDaBYuDy1Z3joTcfBAB4zieu2R9VAHwxaGEzcAnb":
return "QmRSWzv3jgTppCsDHjTdgY2aVPpMD66D28Dbyj3N65Nnfh"
case "QmdSNPssUEAVG9jkBQAXCBrNM5zSgofXkrdkD83DqxCxhZ":
return "QmfQCe5hgcngZkFcbS6rktaiPZ4U1ZiBiuJHbA73CJfi2P"
case "QmQde4iLJyuLKQwPmfeFMr7AdS5wDv1haCxsbv1RgfURBC":
return "QmRJJ9ghsoz6aNSnet1bPNJE8RrAC74oNoiQhQ3cYxHhwM"
case "QmSREPYVpK73oBoJR15kUREDiJf9X2okjgFqyze8UNu4WX":
return "QmQbFAxq59Yastjvfh9CWmrekhvZaHJfGN4vPYaPH52rXA"
case "QmTL4Uraj8mRREETwgv1hNo3pzJZ2WzuxYqnEDQueLjjAa":
return "QmXHfwE4paGT7MnW5Fv9ZcuYDn6M1B4PCxFtpgmSbUE9VB"
case "QmU9McQUt7VbHaq3CBcn7DJSFMPzjHRarWV6JNHGf4Nq3k":
return "QmXQfKSkUdEzPn7UgXmTkpAf6TDNys2vjVCcTWTj42jmet"
case "QmUboC1BcvwBPQBGk6QSphrAmBHzt1SQwZcVSYGhxzT7Lr":
return "QmTBwSFBytRkwCednLhfsW6DG4ZCNSzo5ZigRQXsAGts4W"
case "QmUrEXCCF7Bj2sXo929y1HMTMXmXkpLgtusU9LYu9qNUhA":
return "QmWL7DzDimUrPpk4VCu84qkaH1RJhZhkcEVgDG784w2bsk"
case "QmWeB6raYMksDPpd6oQhJ4BAb5AzP3zwWnQKNeXA8nEPyw":
return "QmUURuK76k7HDiMeZAw1rXkmhESMLtha7VMHsDiSRxZFPi"
case "QmXF5ESZm91fvQeE1Mc9sW93s4ptHhnrN8bF4MCv1eYtc8":
return "QmQ4fsPE8F2YtpEVs45sfsb9tfnb3NDtFqnoMfZx6UhgPH"
case "QmY34PMF2rVJvUcn1x2ibfVGYeHNFFYXeukhYneiihEV2o":
return "QmQDCQmFXPDJGfjkRnQ37ao4L1ZuFEUR2EdMFbk4QyH1fW"
case "QmZJSSjVXocxSTYysw12Rm58LMAB5czHtRuf9QaUyDwMAN":
return "QmbQRRJ9grn6kCGRp4SYE7Z2ZUvs95mLCN1Dg4iN5Jt6Qw"
default:
return null
}
}

2 changes: 1 addition & 1 deletion src/api/services/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class NFTService {
*/
async getNFTs(query: NFTsQuery): Promise<CustomResponse<INFT>> {
try {
const likesData: AggregatePaginateResult<{_id: string, count: number}> | null = null
// const likesData: AggregatePaginateResult<{_id: string, count: number}> | null = null
// Categories
if (query.filter?.categories){
const withNoCategories = query.filter.categories.includes("none")
Expand Down
5 changes: 3 additions & 2 deletions src/api/validators/nftValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type NFTsQuery = {
priceFilter?: string
priceTiime?: string
priceTiimeFilter?: string
locked?: boolean
seriesLocked?: boolean
isCapsule?: boolean
noSeriesData?: boolean
}
Expand All @@ -46,6 +46,7 @@ export const validationGetNFTs = (query: any) => {
ids: Joi.array().items(Joi.number().integer().min(0)),
idsToExclude: Joi.array().items(Joi.number().integer().min(0)),
liked: Joi.string(),
series: Joi.array().items(Joi.string()),
marketplaceId: Joi.number().integer().min(0),
listed: Joi.boolean(),
categories: Joi.array().items(Joi.string()),
Expand All @@ -55,7 +56,7 @@ export const validationGetNFTs = (query: any) => {
priceFilter: Joi.string(),
priceTiime: Joi.string(),
priceTiimeFilter: Joi.string(),
locked: Joi.boolean(),
seriesLocked: Joi.boolean(),
isCapsule: Joi.boolean(),
noSeriesData: Joi.boolean(),
}),
Expand Down
12 changes: 10 additions & 2 deletions src/socket.io/buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ export default (io: Namespace) => {
socket.disconnect();
} else {
await socket.join(session);
L.info('socked ' + socket.id + ' joined to session ' + session) + ' room size=' + io.adapter.rooms.get(session as string).size;
socket.on('disconnect', async (_r) => {
const socketRooms = await io.adapter.fetchSockets({
rooms: new Set(session),
});
socketRooms.forEach(async socketRoom => {
await socketRoom.disconnect();
L.info('socked ' + socket.id + ' in session ' + session + ' was disconnected by server due to another room socket was disconnected.');
});
});
L.info('socked ' + socket.id + ' joined to session ' + session) + ' room size='+io.adapter.rooms.get(session as string).size;
socket.on("NFT_BUY", (data, callback) => {
const validCallback = callback && typeof callback === "function";
// send mobile app response to nft marketplace
socket.to(`${session}`).emit("NFT_BUY", data);
// confirm success to mobile app
validCallback && callback({ ok: true });
});
socket.on('NFT_BUY_RECEIVED', (data, callback) => {
Expand Down
19 changes: 15 additions & 4 deletions src/socket.io/creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ export default (io: Namespace) => {
} else {
await socket.join(session);
L.info('socked ' + socket.id + ' joined to session ' + session) + ' room size=' + io.adapter.rooms.get(session as string).size;
socket.on('disconnect', async (_r) => {
const socketRooms = await io.adapter.fetchSockets({
rooms: new Set(session),
});
L.info(`on DISCONNECT: eval socket room size = ${socketRooms.length} - room = ${session} - disconnected socket id = ${socket.id}`);
socketRooms.forEach(async socketRoom => {
await socketRoom.disconnect();
L.info('socked ' + socket.id + ' in session ' + session + ' was disconnected by server due to another room socket was disconnected.');
});
});
socket.on('PGPS_READY', (data, callback) => {
const validCallback = callback && typeof callback === "function";
socket.to(`${session}`).emit("PGPS_READY", data);
Expand Down Expand Up @@ -44,25 +54,26 @@ export default (io: Namespace) => {
socket.on("MINTING_NFT", (data, callback) => {
const validCallback = callback && typeof callback === "function";
socket.to(`${session}`).emit("MINTING_NFT", data);
// confirm success to mobile app
validCallback && callback({ ok: true });
});
socket.on("MINTING_NFT_RECEIVED", (data, callback) => {
const validCallback = callback && typeof callback === "function";
socket.to(`${session}`).emit("MINTING_NFT_RECEIVED", data);
// confirm success to mobile app
validCallback && callback({ ok: true });
});
socket.on("MINTING_NFT_ERROR", (data, callback) => {
const validCallback = callback && typeof callback === "function";
socket.to(`${session}`).emit("MINTING_NFT_ERROR", data);
validCallback && callback({ ok: true });
});
socket.on("UPLOAD_REMAINING_TIME", (data, callback) => {
const validCallback = callback && typeof callback === "function";
socket.to(`${session}`).emit("UPLOAD_REMAINING_TIME", data);
// confirm success to mobile app
validCallback && callback({ ok: true });
});
socket.on("WALLET_READY", (data, callback) => {
const validCallback = callback && typeof callback === "function";
socket.to(`${session}`).emit("WALLET_READY", data);
// confirm success to mobile app
validCallback && callback({ ok: true });
});
io.to(socket.id).emit("CONNECTION_SUCCESS", {
Expand Down
10 changes: 10 additions & 0 deletions src/socket.io/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ export default (io: Namespace) => {
socket.disconnect();
} else {
await socket.join(session);
L.info('socked ' + socket.id + ' joined to session ' + session) + ' room size=' + io.adapter.rooms.get(session as string).size;
socket.on('disconnect', async (_r) => {
const socketRooms = await io.adapter.fetchSockets({
rooms: new Set(session),
});
socketRooms.forEach(async socketRoom => {
await socketRoom.disconnect();
L.info('socked ' + socket.id + ' in session ' + session + ' was disconnected by server due to another room socket was disconnected.');
});
});
L.info('socked ' + socket.id + ' joined to session ' + session) + ' room size='+io.adapter.rooms.get(session as string).size;
socket.on("SEND_WALLET_ID", async ({ walletId: sentWalledId }, callback) => {
L.info('SEND_WALLET_ID event :' + sentWalledId);
Expand Down
12 changes: 10 additions & 2 deletions src/socket.io/updateProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ export default (io: Namespace) => {
socket.disconnect();
} else {
await socket.join(session);
L.info('socked ' + socket.id + ' joined to session ' + session) + ' room size=' + io.adapter.rooms.get(session as string).size;
socket.on('disconnect', async (_r) => {
const socketRooms = await io.adapter.fetchSockets({
rooms: new Set(session),
});
socketRooms.forEach(async socketRoom => {
await socketRoom.disconnect();
L.info('socked ' + socket.id + ' in session ' + session + ' was disconnected by server due to another room socket was disconnected.');
});
});
L.info('socked ' + socket.id + ' joined to session ' + session) + ' room size='+io.adapter.rooms.get(session as string).size;
socket.on("PROFILE_UPDATED", (data, callback) => {
const validCallback = callback && typeof callback === "function";
// send mobile app response to nft marketplace
socket.to(`${session}`).emit("PROFILE_UPDATED", data);
// confirm success to mobile app
validCallback && callback({ ok: true });
});
socket.on('PROFILE_UPDATED_RECEIVED', (data, callback) => {
Expand Down

0 comments on commit ae52cac

Please sign in to comment.