Skip to content

Commit

Permalink
simplify getSize workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
guiann committed Dec 20, 2024
1 parent 48d18b3 commit 3a565d3
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions modules/retailspotBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
const sizes = getSize(getSizeArray(bid));
const sizes = getSize(bid);
const sizeValid = sizes.width > 0 && sizes.height > 0;

return deepAccess(bid, 'params.placement') && sizeValid;
Expand Down Expand Up @@ -99,40 +99,40 @@ export const spec = {
}
}

function getSizeArray(bid) {
let inputSize = bid.sizes || [];

if (bid.mediaTypes && bid.mediaTypes.banner) {
/* Get parsed size from request size */
function getSize(bid) {
let inputSize = bid.sizes || [];

if (bid.mediaTypes?.banner) {
inputSize = bid.mediaTypes.banner.sizes || [];
}

// handle size in bid.params in formats: [w, h] and [[w,h]].
if (bid.params && Array.isArray(bid.params.size)) {
// Size can be [w, h] or array of sizes : [[w,h]].
if (Array.isArray(bid.params?.size)) {
inputSize = bid.params.size;
if (!Array.isArray(inputSize[0])) {
inputSize = [inputSize]
}
}

return parseSizesInput(inputSize);
}

/* Get parsed size from request size */
function getSize(sizesArray) {
const sizesArray = parseSizesInput(inputSize);
const parsed = {};
// the main requested size is the first one

// Use the first size as the main requested one
const size = sizesArray[0];

// size is ready
if (typeof size !== 'string') {
return parsed;
}

const parsedSize = size.toUpperCase().split('X');
// size is given as string "wwwxhhh" or "www*hhh"
const parsedSize = size.includes('*') ? size.split('*') : size.toUpperCase().split('X');
const width = parseInt(parsedSize[0], 10);
if (width) {
parsed.width = width;
}

const height = parseInt(parsedSize[1], 10);
if (height) {
parsed.height = height;
Expand Down

0 comments on commit 3a565d3

Please sign in to comment.