@huggingface/space-header
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -156,5 +156,6 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/inject_fonts.ts | ||
// src/header/components/content/avatar.ts | ||
var Avatar = (username) => { | ||
var Avatar = (username, type = "user") => { | ||
const route = type === "user" ? "users" : "organizations"; | ||
const element = document.createElement("img"); | ||
element.src = `https://huggingface.co/api/users/${username}/avatar`; | ||
element.src = `https://huggingface.co/api/${route}/${username}/avatar`; | ||
element.style.width = "0.875rem"; | ||
@@ -235,3 +236,5 @@ element.style.height = "0.875rem"; | ||
content.style.height = "40px"; | ||
content.appendChild(Avatar(space.author)); | ||
if (space.type !== "unknown") { | ||
content.appendChild(Avatar(space.author, space.type)); | ||
} | ||
content.appendChild(Username(space.author)); | ||
@@ -253,3 +256,14 @@ content.appendChild(Separation()); | ||
// src/get_space.ts | ||
// src/utils/check_avatar.ts | ||
var check_avatar = async (username, type = "user") => { | ||
const route = type === "user" ? "users" : "organizations"; | ||
try { | ||
const response = await fetch(`https://huggingface.co/api/${route}/${username}/avatar`); | ||
return response.ok; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; | ||
// src/utils/get_space.ts | ||
var get_space = async (space_id) => { | ||
@@ -301,2 +315,4 @@ try { | ||
} | ||
const [user, org] = await Promise.all([check_avatar(space.author, "user"), check_avatar(space.author, "org")]); | ||
space.type = user ? "user" : org ? "org" : "unknown"; | ||
const mini_header_element = create(space); | ||
@@ -303,0 +319,0 @@ inject(mini_header_element, options); |
@@ -182,5 +182,6 @@ "use strict"; | ||
// src/header/components/content/avatar.ts | ||
var Avatar = (username) => { | ||
var Avatar = (username, type = "user") => { | ||
const route = type === "user" ? "users" : "organizations"; | ||
const element = document.createElement("img"); | ||
element.src = `https://huggingface.co/api/users/${username}/avatar`; | ||
element.src = `https://huggingface.co/api/${route}/${username}/avatar`; | ||
element.style.width = "0.875rem"; | ||
@@ -261,3 +262,5 @@ element.style.height = "0.875rem"; | ||
content.style.height = "40px"; | ||
content.appendChild(Avatar(space.author)); | ||
if (space.type !== "unknown") { | ||
content.appendChild(Avatar(space.author, space.type)); | ||
} | ||
content.appendChild(Username(space.author)); | ||
@@ -279,3 +282,14 @@ content.appendChild(Separation()); | ||
// src/get_space.ts | ||
// src/utils/check_avatar.ts | ||
var check_avatar = async (username, type = "user") => { | ||
const route = type === "user" ? "users" : "organizations"; | ||
try { | ||
const response = await fetch(`https://huggingface.co/api/${route}/${username}/avatar`); | ||
return response.ok; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; | ||
// src/utils/get_space.ts | ||
var get_space = async (space_id) => { | ||
@@ -323,2 +337,4 @@ try { | ||
} | ||
const [user, org] = await Promise.all([check_avatar(space.author, "user"), check_avatar(space.author, "org")]); | ||
space.type = user ? "user" : org ? "org" : "unknown"; | ||
const mini_header_element = create(space); | ||
@@ -325,0 +341,0 @@ inject(mini_header_element, options); |
@@ -1,2 +0,2 @@ | ||
export declare const Avatar: (username: string) => HTMLImageElement; | ||
export declare const Avatar: (username: string, type?: "user" | "org") => HTMLImageElement; | ||
//# sourceMappingURL=avatar.d.ts.map |
@@ -5,2 +5,3 @@ export interface Space { | ||
author: string; | ||
type?: "user" | "org" | "unknown"; | ||
} | ||
@@ -7,0 +8,0 @@ export interface User { |
{ | ||
"name": "@huggingface/space-header", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"packageManager": "pnpm@8.10.5", | ||
@@ -5,0 +5,0 @@ "description": "Use the Space mini_header outside Hugging Face", |
@@ -1,4 +0,6 @@ | ||
export const Avatar = (username: string): HTMLImageElement => { | ||
export const Avatar = (username: string, type: "user" | "org" = "user"): HTMLImageElement => { | ||
const route = type === "user" ? "users" : "organizations"; | ||
const element = document.createElement("img"); | ||
element.src = `https://huggingface.co/api/users/${username}/avatar`; | ||
element.src = `https://huggingface.co/api/${route}/${username}/avatar`; | ||
@@ -5,0 +7,0 @@ element.style.width = "0.875rem"; |
@@ -18,3 +18,5 @@ import type { Space } from "../../../type"; | ||
content.appendChild(Avatar(space.author)); | ||
if (space.type !== "unknown") { | ||
content.appendChild(Avatar(space.author, space.type)); | ||
} | ||
content.appendChild(Username(space.author)); | ||
@@ -21,0 +23,0 @@ content.appendChild(Separation()); |
@@ -6,3 +6,4 @@ import type { Options, Space, Header } from "./type"; | ||
import { create } from "./header/create"; | ||
import { get_space } from "./get_space"; | ||
import { check_avatar } from "./utils/check_avatar"; | ||
import { get_space } from "./utils/get_space"; | ||
import { inject } from "./inject"; | ||
@@ -31,2 +32,5 @@ | ||
const [user, org] = await Promise.all([check_avatar(space.author, "user"), check_avatar(space.author, "org")]); | ||
space.type = user ? "user" : org ? "org" : "unknown"; | ||
const mini_header_element = create(space as Space); | ||
@@ -33,0 +37,0 @@ inject(mini_header_element, options); |
@@ -5,2 +5,3 @@ export interface Space { | ||
author: string; | ||
type?: "user" | "org" | "unknown"; | ||
} | ||
@@ -7,0 +8,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74166
65
1653
8