Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make npmAvatar primary src #331

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"@nodesecure/npm-registry-sdk": "^2.0.0",
"@nodesecure/ossf-scorecard-sdk": "^3.1.0",
"@nodesecure/rc": "^1.5.0",
"@nodesecure/scanner": "^5.2.1",
"@nodesecure/scanner": "^5.3.0",
"@nodesecure/utils": "^1.2.0",
"@nodesecure/vuln": "^1.7.0",
"@openally/result": "^1.2.0",
Expand Down
14 changes: 10 additions & 4 deletions public/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ export function parseRepositoryUrl(repository = {}, defaultValue = null) {
}
}

export function createAvatarImageElement(email = null) {
function createImageElement(baseUrl, id = null){
const imageElement = document.createElement("img");
if (email === null || email === "") {
if (id === null || id === "") {
imageElement.src = `${avatarURL}`;
}
else {
imageElement.src = `https://unavatar.io/${email}`;
imageElement.src = `${baseUrl}/${id}`;
imageElement.onerror = () => {
imageElement.src = `${avatarURL}`;
};
Expand All @@ -134,6 +134,12 @@ export function createAvatarImageElement(email = null) {
return imageElement;
}

export function createAvatarImageElementForAuthor(author = {}) {
return author.npmAvatar
? createImageElement("https://www.npmjs.com", author.npmAvatar)
: createImageElement("https://unavatar.io", author.email);
}

export function createAvatar(name, desc) {
const pElement = createDOMElement("p", {
classList: ["count"], text: desc.count
Expand All @@ -143,7 +149,7 @@ export function createAvatar(name, desc) {
classList: ["avatar"], childs: [pElement, aElement]
});

const imgEl = createAvatarImageElement(desc.email);
const imgEl = createAvatarImageElementForAuthor({ email: desc.email });
imgEl.alt = name;
aElement.appendChild(imgEl);

Expand Down
2 changes: 1 addition & 1 deletion public/components/package/pannels/overview/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class Overview {
for (const author of metadata.maintainers) {
const divElement = utils.createDOMElement("div", {
childs: [
utils.createAvatarImageElement(author.email),
utils.createAvatarImageElementForAuthor(author),
utils.createDOMElement("p", {
text: author.name
}),
Expand Down
4 changes: 2 additions & 2 deletions public/components/views/home/maintainers/maintainers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Maintainers {
const person = utils.createDOMElement("div", {
className: "person",
childs: [
utils.createAvatarImageElement(email),
utils.createAvatarImageElementForAuthor(data),
Maintainers.whois(name, email),
hasURL ? utils.createDOMElement("i", { className: "icon-link" }) : null,
utils.createDOMElement("div", {
Expand Down Expand Up @@ -96,7 +96,7 @@ export class PopupMaintainer {
const clone = templateElement.content.cloneNode(true);

clone.querySelector(".avatar").appendChild(
utils.createAvatarImageElement(email)
utils.createAvatarImageElementForAuthor(this.data)
);
clone.querySelector(".name").textContent = this.name;
const emailElement = clone.querySelector(".email");
Expand Down
9 changes: 7 additions & 2 deletions workspaces/vis-network/src/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default class NodeSecureDataSet extends EventTarget {
this.rawNodesData = [];

for (const [packageName, descriptor] of dataEntries) {
const contributors = [descriptor.metadata.author, ...descriptor.metadata.maintainers, ...descriptor.metadata.publishers]
for (const [currVersion, opt] of Object.entries(descriptor.versions)) {
const { id, usedBy, flags, size, license, author, composition, warnings, links } = opt;

Expand All @@ -86,7 +87,7 @@ export default class NodeSecureDataSet extends EventTarget {

this.computeExtension(composition.extensions);
this.computeLicense(license);
this.computeAuthor(author, `${packageName}@${currVersion}`);
this.computeAuthor(author, `${packageName}@${currVersion}`, contributors);

if (flags.includes("hasIndirectDependencies")) {
this.indirectDependencies++;
Expand Down Expand Up @@ -150,10 +151,11 @@ export default class NodeSecureDataSet extends EventTarget {
}
}

computeAuthor(author, spec) {
computeAuthor(author, spec, contributors = []) {
if (author === null) {
return;
}
const contributor = contributors.find((contributor) => contributor.email === author.email && contributor.npmAvatar !== null);

if (this.authors.has(author.name)) {
this.authors.get(author.name).packages.add(spec);
Expand All @@ -164,6 +166,9 @@ export default class NodeSecureDataSet extends EventTarget {
Object.assign({}, author, { packages: new Set([spec]) })
);
}
if (contributor && contributor.npmAvatar) {
this.authors.get(author.name).npmAvatar = contributor.npmAvatar;
}
}

build() {
Expand Down