@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
108 lines • 6.19 kB
JavaScript
/**
* 2024-09-06: Migrated from same folder fps-library-v2\src\pnpjs\SourceItems
*/
import { startPerformOpV2, updatePerformanceEndV2 } from "../Performance/functions";
export const TypicalPageUrlChecks = ['CanvasContent1', 'LayoutWebpartsContent', 'BannerImageUrl'];
/**
*
* @param items
* @returns
*/
export function addPagesFileGuidSearch(stateSource, urlFieldChecks = TypicalPageUrlChecks) {
const performanceSettings = { label: `addPagesFileGuidSearch urlFields:${urlFieldChecks.join(', ')}`, updateMiliseconds: true, includeMsStr: true, op: 'analyze' };
let processOp = performanceSettings ? startPerformOpV2(performanceSettings) : null;
const docIds = []; // example: "73b5f88a-dab7-43bb-b216-dc041cd1c412&guidWeb=cccdb05d-1f6e-46b6-9397-002fe80af5bf&guidFile=df16fe3c-891b-4b90-bc6c-4c739b5d7980"
const siteIds = []; // Just the site guid [0]: 73b5f88a-dab7-43bb-b216-dc041cd1c412
const webIds = []; // Just the web guid [1]: cccdb05d-1f6e-46b6-9397-002fe80af5bf
const fileIds = []; // Just the file guid [2]: df16fe3c-891b-4b90-bc6c-4c739b5d7980
const fileNoDashIds = []; // Just the file guid [2] WITHOUT Dashes: df16fe3c891b4b90bc6c4c739b5d7980
const goofyFileIds = []; // All the ones that have extra chars
const BannerGuidIds = []; // All the Ids where the BannerImageUrl has a guidFile string
const LayoutGuidIds = []; // All the Ids where the LayoutWebpartsContent has a guidFile string
const CanvasContent1GuidIds = []; // All the Ids where the CanvasContent1 has a guidFile string
stateSource.items.map((item, idx) => {
// This should reset for every item
const PagePalSearch = [];
if (item.Id)
PagePalSearch.push(item.Id);
// 2024-09-06: Added to remove typescript error
if (!item.FPSItem.Search)
item.FPSItem.Search = {};
if (!item.FPSItem.Search.meta)
item.FPSItem.Search.meta = [];
if (item.BannerImageUrl) {
const Ids = item.BannerImageUrl.Url.split('guidSite=')[1];
if (Ids) {
PagePalSearch.push(...[Ids, `HasDocId`]);
item.FPSItem.Search.meta.push(`HasDocId`);
const Ids3 = Ids.replace('&guidFile', '').replace('&guidWeb', '').split('=');
// For this part, have to remove the '-' when comparing because sometimes Ids have a '-' and sometimes not.
if (docIds.indexOf(Ids.replace(/-/g, '')) < 0)
docIds.push(Ids);
if (siteIds.indexOf(Ids3[0]) < 0)
siteIds.push(Ids3[0]);
if (webIds.indexOf(Ids3[1]) < 0)
webIds.push(Ids3[1]);
/**
* Get all the parts after the 3rd = and put them together.
* Have to do that because the rest somethings looks like this:
* &guidFile=51c7e94ec0704fc09cb8e0778b1be00a&ext=png&ow=604&oh=306
*/
const fullFileId = Ids3.slice(2).join('');
// Found sometimes fileIds have &ext at the end of the quids
if (fullFileId.indexOf('&ext') > 0)
goofyFileIds.push(fullFileId);
// Added this to definatively check if that file id was seen before even with different dash pattern
const FileIdNoDashes = fullFileId.replace(/-/g, '');
if (!item.FPSItem.Search.metaB)
item.FPSItem.Search.metaB = [];
// This will be used downstream to put the replacement file url
if (!item.FPSItem.Search.metaC)
item.FPSItem.Search.metaC = [];
BannerGuidIds.push([idx, item.Id,]);
// Add the FileId from BannerImageUrl directly to the Search.metaB for easier handling downstream
item.FPSItem.Search.metaB.push(FileIdNoDashes);
if (fileNoDashIds.indexOf(FileIdNoDashes) < 0) {
fileIds.push(fullFileId);
fileNoDashIds.push(FileIdNoDashes);
}
}
}
urlFieldChecks.map(checkProps => {
if (item[checkProps]) {
const valAsStr = typeof item[checkProps] === 'string' ? item[checkProps] : JSON.stringify(item[checkProps]);
// 2024-09-06: Added to remove typescript error
if (item.FPSItem.Search === undefined)
item.FPSItem.Search = {};
item.FPSItem.Search.meta.push(valAsStr);
PagePalSearch.push(valAsStr);
}
});
if (item.CanvasContent1 && item.CanvasContent1.indexOf('guidFile') > -1) {
CanvasContent1GuidIds.push([idx, item.Id,]);
}
if (item.LayoutWebpartsContent && item.LayoutWebpartsContent.indexOf('guidFile') > -1) {
LayoutGuidIds.push([idx, item.Id,]);
}
if (PagePalSearch.length > 0) {
const PagePalSearchStr = PagePalSearch.join(' || ');
item.FPSItem.Search.searchText += ` || ${PagePalSearchStr}`;
item.FPSItem.Search.searchTextLC += ` || ${PagePalSearchStr.toLocaleLowerCase()}`;
}
});
stateSource.metaAny1 = CanvasContent1GuidIds;
stateSource.metaAny2 = LayoutGuidIds;
stateSource.metaAny3 = BannerGuidIds;
stateSource.metaA = goofyFileIds;
stateSource.metaB = fileNoDashIds;
stateSource.metaD = docIds;
stateSource.metaS = siteIds;
stateSource.metaW = webIds;
stateSource.metaF = fileIds;
// Historically processOp on Templates/SPFx has always between .....275 to 350 but typically below 300
// 2024-09-06: Added op: processOp as IPerformanceOp to remove typescript error
processOp = updatePerformanceEndV2({ op: processOp, updateMiliseconds: performanceSettings.updateMiliseconds, count: stateSource.items.length });
console.log(`${processOp === null || processOp === void 0 ? void 0 : processOp.label}`, processOp);
return stateSource;
}
//# sourceMappingURL=addPagesFileGuidSearch.js.map