anzorq commited on
Commit
b43a04e
β€’
1 Parent(s): 33ddd44

~handle missing cardData case

Browse files
Files changed (1) hide show
  1. pages/api/hf_space.js +4 -5
pages/api/hf_space.js CHANGED
@@ -1,4 +1,3 @@
1
-
2
  const get_space_info = async (space_id) => {
3
  try {
4
  const response = await fetch(`https://huggingface.co/api/spaces/${space_id}`)
@@ -14,10 +13,10 @@ const get_space_info = async (space_id) => {
14
  const lastModified = dayjs(json.lastModified).fromNow()
15
 
16
  const author = json.author
17
- const title = json.cardData.title || 'Untitled'
18
- const emoji = json.cardData.emoji
19
- let colorFrom = json.cardData.colorFrom || 'pink'
20
- let colorTo = json.cardData.colorTo || 'purple'
21
  const likes = json.likes
22
  const sdk = json.sdk
23
  const runtime_stage = json.runtime.stage
 
 
1
  const get_space_info = async (space_id) => {
2
  try {
3
  const response = await fetch(`https://huggingface.co/api/spaces/${space_id}`)
 
13
  const lastModified = dayjs(json.lastModified).fromNow()
14
 
15
  const author = json.author
16
+ const title = json.cardData?.title || json.id.split('/')[1].replace(/-/g, ' ') || 'Untitled'
17
+ const emoji = json.cardData?.emoji || 'πŸ€—'
18
+ let colorFrom = json.cardData?.colorFrom || 'pink'
19
+ let colorTo = json.cardData?.colorTo || 'purple'
20
  const likes = json.likes
21
  const sdk = json.sdk
22
  const runtime_stage = json.runtime.stage