Skip to content

Commit

Permalink
Merge branch 'fix/vcard-stale-profile' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuatz committed Jul 21, 2020
2 parents 02607cf + 02f39fe commit 4b68f17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
12 changes: 6 additions & 6 deletions build-scripts/prep-browserext.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ const packageJson = require('../package.json');
const manifestJson = require('../browser-ext/manifest.json');

const browserExtSrcDir = `${__dirname}/../browser-ext/`;
const mainJs = `${__dirname}/../build/main.js`;
const buildDir = `${__dirname}/../build-browserext/`;
const buildDir = `${__dirname}/../build/`;
const browserBuildDir = `${__dirname}/../build-browserext/`;

// Clean out build dir
fse.emptyDirSync(buildDir);
fse.emptyDirSync(browserBuildDir);

// Copy all files from browser extension folder to build
fse.copySync(browserExtSrcDir, buildDir);
fse.copySync(browserExtSrcDir, browserBuildDir);

// Copy version number over to manifest, and write it out to build dir
manifestJson.version = packageJson.version;
fse.writeFileSync(`${buildDir}manifest.json`, JSON.stringify(manifestJson, null, 4));
fse.writeFileSync(`${browserBuildDir}manifest.json`, JSON.stringify(manifestJson, null, 4));

// Copy main js file, after babel, over to build
fse.copyFileSync(mainJs, `${buildDir}main.js`);
fse.copySync(buildDir, browserBuildDir);
23 changes: 12 additions & 11 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ window.LinkedinToResumeJson = (() => {
/** @type {ParseProfileSchemaResultSummary} */
const resultSummary = {
profileObj,
pageUrl: _this.getUrlWithoutQuery(),
pageUrl: null,
parseSuccess: false,
sections: {
basics: 'fail',
Expand Down Expand Up @@ -732,7 +732,7 @@ window.LinkedinToResumeJson = (() => {
resultSummary.sections.publications = publicationEntries.length ? 'success' : 'empty';

if (_this.debug) {
console.group('parseProfileSchemaJSON complete:');
console.group(`parseProfileSchemaJSON complete: ${document.location.pathname}`);
console.log({
db,
_outputJson,
Expand All @@ -743,6 +743,7 @@ window.LinkedinToResumeJson = (() => {

_this.parseSuccess = true;
resultSummary.parseSuccess = true;
resultSummary.pageUrl = _this.getUrlWithoutQuery();
} catch (e) {
if (_this.debug) {
console.group('Error parsing profile schema');
Expand Down Expand Up @@ -1164,7 +1165,6 @@ window.LinkedinToResumeJson = (() => {
}

// Get directly via API
// ....
const fullProfileView = await this.voyagerFetch(_voyagerEndpoints.fullProfileView);
// Try to use the same parser that I use for embedded
const profileParserResult = await parseProfileSchemaJSON(this, fullProfileView);
Expand Down Expand Up @@ -1374,7 +1374,7 @@ window.LinkedinToResumeJson = (() => {
* Get the profile ID / User ID of the user by parsing URL first, then page.
*/
LinkedinToResumeJson.prototype.getProfileId = function getProfileId() {
let profileId;
let profileId = '';
const linkedProfileRegUrl = /linkedin.com\/[^\/]*\/([^\/]+)\/[^\/]*$/im;
const linkedProfileRegApi = /voyager\/api\/.*\/profiles\/([^\/]+)\/.*/im;
if (linkedProfileRegUrl.test(document.location.href)) {
Expand All @@ -1387,12 +1387,8 @@ window.LinkedinToResumeJson = (() => {
profileId = linkedProfileRegApi.exec(document.body.innerHTML)[1];
}

if (profileId) {
// In case username contains special characters
return decodeURI(profileId);
}

return false;
// In case username contains special characters
return decodeURI(profileId);
};

/**
Expand Down Expand Up @@ -1458,6 +1454,8 @@ window.LinkedinToResumeJson = (() => {
const profileDb = buildDbFromLiSchema(fullProfileView);
const profileViewUrnPatt = /urn:li:fs_profileView:(.+)$/i;
this.profileUrnId = profileDb.tableOfContents['entityUrn'].match(profileViewUrnPatt)[1];
} else {
this.debugConsole.warn('Could not scrape profileUrnId from DOM, but fetch is disallowed. Might be using a stale ID!');
}

return this.profileUrnId;
Expand Down Expand Up @@ -1657,7 +1655,10 @@ window.LinkedinToResumeJson = (() => {
*/
LinkedinToResumeJson.prototype.formatVoyagerUrl = async function formatVoyagerUrl(fetchEndpoint) {
// Macro support
let endpoint = fetchEndpoint.replace(/{profileId}/g, this.profileId);
let endpoint = fetchEndpoint;
if (endpoint.includes('{profileId}')) {
endpoint = fetchEndpoint.replace(/{profileId}/g, this.getProfileId());
}
if (endpoint.includes('{profileUrnId}')) {
const profileUrnId = await this.getProfileUrnId();
endpoint = endpoint.replace(/{profileUrnId}/g, profileUrnId);
Expand Down

0 comments on commit 4b68f17

Please sign in to comment.