raycast / extensions

Everything you need to extend Raycast.
https://developers.raycast.com
MIT License
5.37k stars 3.06k forks source link

[Raindrop.io] Redirect to "Something went wrong" #4041

Closed abjutus closed 1 year ago

abjutus commented 1 year ago

Extension

https://www.raycast.com/lardissone/raindrop-io

Description

I have already setup the test token, and as in screen recording below, the app did get bookmarks. However, it redirected to the error page.

Steps To Reproduce

  1. Open raycast
  2. trigger raindrop command

Current Behaviour

Error Log

TypeError: Cannot read properties of undefined (reading 'collections')

Xa:latest_bookmarks.js:37:4871

---
34: `),p.highlights.length&&(d+=`## Highlights
35: `,p.highlights.map(i=>{d+=`> ${i.text}${i.note?` (Note: ${i.note})`:""}`}),d+=`
36: 
37: `),d};return(0,z.jsx)($.List.Item,{id:String(p._id),icon:(0,Ba.getFavicon)(p.link,{fallback:"raindrop-icon.png"}),title:p.title,subtitle:p.tags.map(d=>`#${d}`).join(" "),accessories:[{text:(0,k1.default)().to((0,k1.default)(p.lastUpdate))}],actions:(0,z.jsxs)($.ActionPanel,{children:[(0,z.jsx)($.Action.OpenInBrowser,{url:p.link}),(0,z.jsx)($.Action.Push,{title:"Show Details",icon:$.Icon.Sidebar,target:(0,z.jsx)($.Detail,{markdown:a(),navigationTitle:p.title,actions:(0,z.jsxs)($.ActionPanel,{children:[(0,z.jsx)($.Action.OpenInBrowser,{url:p.link}),(0,z.jsx)($.Action.CopyToClipboard,{title:"Copy URL",content:p.link}),(0,z.jsx)($.Action.OpenInBrowser,{title:"Open Permanent Copy",url:`https://api.raindrop.io/v1/raindrop/${p._id}/cache`})]}),metadata:(0,z.jsxs)($.Detail.Metadata,{children:[(0,z.jsx)($.Detail.Metadata.Label,{title:"Created",text:(0,k1.default)(p.created).format("ll")}),(0,z.jsx)($.Detail.Metadata.Label,{title:"Last Updated",text:(0,k1.default)(p.lastUpdate).format("ll")}),(0,z.jsx)($.Detail.Metadata.Label,{title:"Domain",text:p.domain}),p.tags&&(0,z.jsx)($.Detail.Metadata.TagList,{title:"Tags",children:p.tags.map(d=>(0,z.jsx)($.Detail.Metadata.TagList.Item,{text:d,color:"#eed535"},d))}),(0,z.jsx)($.Detail.Metadata.Separator,{}),p.broken&&(0,z.jsx)($.Detail.Metadata.Label,{title:"Link broken",text:"Yes"}),p.important&&(0,z.jsx)($.Detail.Metadata.Label,{title:"Favorite",text:"Yes"})]})})}),(0,z.jsx)($.Action.CopyToClipboard,{title:"Copy URL",content:p.link})]})},p._id)}var Oa=t1(require("react")),de=require("@raycast/api"),ie=require("react/jsx-runtime"),N0=Oa.default.memo(function({isLoading:p,handleChange:a,collections:d,defaultValue:i}){return p?null:(0,ie.jsxs)(de.List.Dropdown,{onChange:a,tooltip:"Select Collection",defaultValue:i,children:[(0,ie.jsx)(de.List.Dropdown.Item,{title:"All bookmarks",value:"0"}),(0,ie.jsx)(de.List.Dropdown.Item,{title:"Unsorted",value:"-1"}),d?.map(m=>(0,ie.jsx)(de.List.Dropdown.Item,{title:m.label,value:`${m.value}`},`${m.value}_${Math.random().toString(16).substring(2,8)}`)),(0,ie.jsx)(de.List.Dropdown.Item,{title:"\u{1F5D1} Trash",value:"-99"})]})}),Fa=N0;var Ye=require("react"),Ga=t1(M1());var me=require("@raycast/api"),$a=t1(M1());function Ra({collection:e,search:p=""}){let a=(0,me.getPreferenceValues)(),d=`https://api.raindrop.io/rest/v1/raindrops/${e}?sort=-created&search=${encodeURIComponent(p)??""}`,{isLoading:i,data:m,revalidate:r}=(0,$a.useFetch)(d,{headers:{Authorization:`Bearer ${a.token}`},keepPreviousData:!0,onError:()=>{(0,me.showToast)(me.Toast.Style.Failure,"Cannot search bookmark")}});return{isLoading:i,data:m,revalidate:r}}var te=require("@raycast/api"),Ma=t1(M1());function ka(){let e=(0,te.getPreferenceValues)(),{isLoading:p,data:a,revalidate:d}=(0,Ma.useFetch)("https://api.raindrop.io/rest/v1/collections/all",{headers:{Authorization:`Bearer ${e.token}`},keepPreviousData:!0,onError:()=>{(0,te.showToast)(te.Toast.Style.Failure,"Cannot fetch collections")}});return{isLoading:p,data:a,revalidate:d}}var le=require("@raycast/api"),Ua=t1(M1());function Ia(){let e=(0,le.getPreferenceValues)(),{isLoading:p,data:a,revalidate:d}=(0,Ua.useFetch)("https://api.raindrop.io/rest/v1/user",{headers:{Authorization:`Bearer ${e.token}`},keepPreviousData:!0,onError:()=>{(0,le.showToast)(le.Toast.Style.Failure,"Cannot fetch user details")}});return{isLoading:p,data:a,revalidate:d}}var qa=[],B2=[];function ja(e,p,a){let d=p.filter(i=>a==0&&!i.parent||i.parent&&i.parent.$id==a);for(let i of d){let m=i._id;i.children=[],ja(i.children,p,m),e.push(i)}}function S0(e){let p=[];return e.length>1?e.forEach(a=>{a.collections.forEach(d=>{p.push([a.title,d])})}):e[0].collections.forEach(a=>{p.push([null,a])}),p}function D0(e,p){let a=[];return p.forEach(d=>{let i=e.find(m=>m._id==d[1]);a.push([...d,i])}),a}var za=(e,p="")=>{for(let a=0;a<e.length;a++){let d=e[a],i=`${p} > ${d.title}`;B2.push({value:d._id,label:i}),d.children&&za(d.children,i)}},b0=e=>{e.forEach(p=>{let d=`${p[0]?`${p[0]} - `:""}${p[2]?.title}`;B2.push({value:p[2]?._id,label:d}),p[2]?.children&&za(p[2]?.children,d)})},Ha=(e,p)=>{ja(qa,p.items,0);let a=S0(e.user.groups),d=D0(qa,a);return b0(d),B2};function Ya({collection:e="0",search:p=""}){let[a,d]=(0,Ye.useState)(!0),[i,m]=(0,Ga.useCachedState)("collections",[]),{isLoading:r,data:t}=Ia(),{isLoading:l,data:s}=Ra({collection:e,search:p}),{isLoading:f,data:v}=ka();return(0,Ye.useEffect)(()=>{let h=r||l||f;if(d(h),!h&&t?.result&&v?.result){let _=Ha(t,v);m(_)}},[r,l,f]),{isLoading:a,bookmarks:s,collections:i}}var O2=require("@raycast/api");function Wa(){return{getLastUsedCollection:async()=>await O2.LocalStorage.getItem("lastUsedCollection"),setLastUsedCollection:async a=>{await O2.LocalStorage.setItem("lastUsedCollection",a)}}}var F2=require("react/jsx-runtime");function Xa(){let e=(0,We.getPreferenceValues)(),[p,a]=(0,$2.useCachedState)("last-used-collection","0"),{getLastUsedCollection:d,setLastUsedCollection:i}=Wa();(0,Za.useEffect)(()=>{(async()=>{let _=await d();a(_||"0")})()},[]);let m=e.useLastCollection?p:"0",[r,t]=(0,$2.useCachedState)("selected-collection",m),{isLoading:l,bookmarks:s,collections:f}=Ya({collection:r});return(0,F2.jsx)(We.List,{isLoading:l,searchBarPlaceholder:"Filter bookmarks by title...",searchBarAccessory:(0,F2.jsx)(Fa,{isLoading:l,handleChange:h=>{r!==h&&(t(h),i(h))},collections:f,defaultValue:r}),children:s?.items?.map(h=>(0,F2.jsx)(L2,{bookmark:h},h._id))})}0&&(module.exports={});
38: /*!
39:  * content-type
40:  * Copyright(c) 2015 Douglas Christopher Wilson
---

wr:index.js:5:2490
    at ray-navigation-stack
No:index.js:5:2088

Screen Recording

https://user-images.githubusercontent.com/12343599/209428769-cbb2e4c2-3c40-492a-a6b8-94d25e6f6dd1.mov

Expected Behaviour

No response

raycastbot commented 1 year ago

Thank you for opening this issue!

🔔 @lardissone you might want to have a look.

lardissone commented 1 year ago

@alanaudi thank you for reporting. I'm trying to debug but I can't replicate it.

Does it happens with "Latest bookmarks" command too?

Can you confirm if the latest bookmarks in your Raindrop account after "Homebrew" have special characters in the names or something odd?

silouanwright commented 1 year ago

I can confirm this is bug is also happening with me too.

ScreenShot 2022-12-26 at 16 30 16@2x

ScreenShot 2022-12-26 at 16 32 52@2x
TypeError: Cannot read properties of undefined (reading 'collections')

Ja:search.js:37:4871

---
34: `),p.highlights.length&&(d+=`## Highlights
35: `,p.highlights.map(i=>{d+=`> ${i.text}${i.note?` (Note: ${i.note})`:""}`}),d+=`
36: 
37: `),d};return(0,z.jsx)($.List.Item,{id:String(p._id),icon:(0,Ba.getFavicon)(p.link,{fallback:"raindrop-icon.png"}),title:p.title,subtitle:p.tags.map(d=>`#${d}`).join(" "),accessories:[{text:(0,k1.default)().to((0,k1.default)(p.lastUpdate))}],actions:(0,z.jsxs)($.ActionPanel,{children:[(0,z.jsx)($.Action.OpenInBrowser,{url:p.link}),(0,z.jsx)($.Action.Push,{title:"Show Details",icon:$.Icon.Sidebar,target:(0,z.jsx)($.Detail,{markdown:a(),navigationTitle:p.title,actions:(0,z.jsxs)($.ActionPanel,{children:[(0,z.jsx)($.Action.OpenInBrowser,{url:p.link}),(0,z.jsx)($.Action.CopyToClipboard,{title:"Copy URL",content:p.link}),(0,z.jsx)($.Action.OpenInBrowser,{title:"Open Permanent Copy",url:`https://api.raindrop.io/v1/raindrop/${p._id}/cache`})]}),metadata:(0,z.jsxs)($.Detail.Metadata,{children:[(0,z.jsx)($.Detail.Metadata.Label,{title:"Created",text:(0,k1.default)(p.created).format("ll")}),(0,z.jsx)($.Detail.Metadata.Label,{title:"Last Updated",text:(0,k1.default)(p.lastUpdate).format("ll")}),(0,z.jsx)($.Detail.Metadata.Label,{title:"Domain",text:p.domain}),p.tags&&(0,z.jsx)($.Detail.Metadata.TagList,{title:"Tags",children:p.tags.map(d=>(0,z.jsx)($.Detail.Metadata.TagList.Item,{text:d,color:"#eed535"},d))}),(0,z.jsx)($.Detail.Metadata.Separator,{}),p.broken&&(0,z.jsx)($.Detail.Metadata.Label,{title:"Link broken",text:"Yes"}),p.important&&(0,z.jsx)($.Detail.Metadata.Label,{title:"Favorite",text:"Yes"})]})})}),(0,z.jsx)($.Action.CopyToClipboard,{title:"Copy URL",content:p.link})]})},p._id)}var Oa=t1(require("react")),de=require("@raycast/api"),ie=require("react/jsx-runtime"),S0=Oa.default.memo(function({isLoading:p,handleChange:a,collections:d,defaultValue:i}){return p?null:(0,ie.jsxs)(de.List.Dropdown,{onChange:a,tooltip:"Select Collection",defaultValue:i,children:[(0,ie.jsx)(de.List.Dropdown.Item,{title:"All bookmarks",value:"0"}),(0,ie.jsx)(de.List.Dropdown.Item,{title:"Unsorted",value:"-1"}),d?.map(m=>(0,ie.jsx)(de.List.Dropdown.Item,{title:m.label,value:`${m.value}`},`${m.value}_${Math.random().toString(16).substring(2,8)}`)),(0,ie.jsx)(de.List.Dropdown.Item,{title:"\u{1F5D1} Trash",value:"-99"})]})}),Fa=S0;var Ye=require("react"),Ga=t1(M1());var me=require("@raycast/api"),$a=t1(M1());function Ra({collection:e,search:p=""}){let a=(0,me.getPreferenceValues)(),d=`https://api.raindrop.io/rest/v1/raindrops/${e}?sort=-created&search=${encodeURIComponent(p)??""}`,{isLoading:i,data:m,revalidate:r}=(0,$a.useFetch)(d,{headers:{Authorization:`Bearer ${a.token}`},keepPreviousData:!0,onError:()=>{(0,me.showToast)(me.Toast.Style.Failure,"Cannot search bookmark")}});return{isLoading:i,data:m,revalidate:r}}var te=require("@raycast/api"),Ma=t1(M1());function ka(){let e=(0,te.getPreferenceValues)(),{isLoading:p,data:a,revalidate:d}=(0,Ma.useFetch)("https://api.raindrop.io/rest/v1/collections/all",{headers:{Authorization:`Bearer ${e.token}`},keepPreviousData:!0,onError:()=>{(0,te.showToast)(te.Toast.Style.Failure,"Cannot fetch collections")}});return{isLoading:p,data:a,revalidate:d}}var le=require("@raycast/api"),Ua=t1(M1());function Ia(){let e=(0,le.getPreferenceValues)(),{isLoading:p,data:a,revalidate:d}=(0,Ua.useFetch)("https://api.raindrop.io/rest/v1/user",{headers:{Authorization:`Bearer ${e.token}`},keepPreviousData:!0,onError:()=>{(0,le.showToast)(le.Toast.Style.Failure,"Cannot fetch user details")}});return{isLoading:p,data:a,revalidate:d}}var qa=[],B2=[];function ja(e,p,a){let d=p.filter(i=>a==0&&!i.parent||i.parent&&i.parent.$id==a);for(let i of d){let m=i._id;i.children=[],ja(i.children,p,m),e.push(i)}}function D0(e){let p=[];return e.length>1?e.forEach(a=>{a.collections.forEach(d=>{p.push([a.title,d])})}):e[0].collections.forEach(a=>{p.push([null,a])}),p}function b0(e,p){let a=[];return p.forEach(d=>{let i=e.find(m=>m._id==d[1]);a.push([...d,i])}),a}var za=(e,p="")=>{for(let a=0;a<e.length;a++){let d=e[a],i=`${p} > ${d.title}`;B2.push({value:d._id,label:i}),d.children&&za(d.children,i)}},V0=e=>{e.forEach(p=>{let d=`${p[0]?`${p[0]} - `:""}${p[2]?.title}`;B2.push({value:p[2]?._id,label:d}),p[2]?.children&&za(p[2]?.children,d)})},Ha=(e,p)=>{ja(qa,p.items,0);let a=D0(e.user.groups),d=b0(qa,a);return V0(d),B2};function Ya({collection:e="0",search:p=""}){let[a,d]=(0,Ye.useState)(!0),[i,m]=(0,Ga.useCachedState)("collections",[]),{isLoading:r,data:t}=Ia(),{isLoading:l,data:s}=Ra({collection:e,search:p}),{isLoading:f,data:u}=ka();return(0,Ye.useEffect)(()=>{let _=r||l||f;if(d(_),!_&&t?.result&&u?.result){let g=Ha(t,u);m(g)}},[r,l,f]),{isLoading:a,bookmarks:s,collections:i}}var O2=require("@raycast/api");function Wa(){return{getLastUsedCollection:async()=>await O2.LocalStorage.getItem("lastUsedCollection"),setLastUsedCollection:async a=>{await O2.LocalStorage.setItem("lastUsedCollection",a)}}}var F2=require("react/jsx-runtime");function Ja(){let e=(0,We.getPreferenceValues)(),[p,a]=(0,$2.useCachedState)("last-used-collection","0"),{getLastUsedCollection:d,setLastUsedCollection:i}=Wa();(0,Za.useEffect)(()=>{(async()=>{let A=await d();a(A||"0")})()},[]);let m=e.useLastCollection?p:"0",[r,t]=(0,Xa.useState)(""),[l,s]=(0,$2.useCachedState)("selected-collection",m),{isLoading:f,bookmarks:u,collections:_}=Ya({collection:l,search:r});return(0,F2.jsx)(We.List,{searchBarPlaceholder:"Search bookmarks using Raindrop.io operators...",searchBarAccessory:(0,F2.jsx)(Fa,{isLoading:f,handleChange:w=>{l!==w&&(s(w),i(w))},collections:_,defaultValue:l}),onSearchTextChange:t,isLoading:f,throttle:!0,children:u?.items?.map(w=>(0,F2.jsx)(L2,{bookmark:w},w._id))})}0&&(module.exports={});
38: /*!
39:  * content-type
40:  * Copyright(c) 2015 Douglas Christopher Wilson
---

wr:index.js:5:2490
    at ray-navigation-stack
No:index.js:5:2088
abjutus commented 1 year ago

@lardissone Thanks for your reply, yes, it did. The interesting thing is that when I have more bookmarks, I cannot replicate it too. The similarity between me and @reywright, we are both new to raindrop, and have only "4" bookmarks at that time. I cannot find any odd or special character.

image
lardissone commented 1 year ago

@alanaudi thanks for the heads up! this is a weird edge case. I'll investigate!

lardissone commented 1 year ago

@alanaudi should be fixed now with #4085

Thank you for your help debugging this!

abjutus commented 1 year ago

@lardissone thanks for your nice work!

lardissone commented 1 year ago

@pernielsentikaer @alanaudi this issue can be closed, fixed by #4085

pernielsentikaer commented 1 year ago

Closing as requested