diff --git a/src/plugins/backgrounds/unsplash/Unsplash.tsx b/src/plugins/backgrounds/unsplash/Unsplash.tsx index 96a0fc684..daddc0af2 100644 --- a/src/plugins/backgrounds/unsplash/Unsplash.tsx +++ b/src/plugins/backgrounds/unsplash/Unsplash.tsx @@ -127,7 +127,7 @@ const Unsplash: React.FC = ({ } }, [cache]); - const url = item ? buildLink(item.src) : null; + const url = item?.src.length ? buildLink(item.src) : null; const go = (amount: number) => cache && cache.items[cache.cursor + amount] diff --git a/src/plugins/backgrounds/unsplash/api.ts b/src/plugins/backgrounds/unsplash/api.ts index 97cc649e6..fb2890c6d 100644 --- a/src/plugins/backgrounds/unsplash/api.ts +++ b/src/plugins/backgrounds/unsplash/api.ts @@ -45,7 +45,20 @@ export const fetchImages = async ({ const res = await fetch(`${url}?${params}`, { headers, cache: "no-cache" }); const body = await res.json(); - // TODO: validate types + if (res.status != 200) { + const empty: Image[] = [ + { + src: "", + credit: { + imageLink: "", + location: undefined, + userName: "", + userLink: "", + } + } + ] + return empty; + }; return body.map((item: any) => ({ src: item.urls.raw, diff --git a/src/plugins/widgets/quote/QuoteSettings.tsx b/src/plugins/widgets/quote/QuoteSettings.tsx index 1cddcb626..8eabf970e 100644 --- a/src/plugins/widgets/quote/QuoteSettings.tsx +++ b/src/plugins/widgets/quote/QuoteSettings.tsx @@ -4,13 +4,6 @@ import { Props, defaultData } from "./types"; const QuoteSettings: React.FC = ({ data = defaultData, setData }) => (
-

- Daily Quotes from 'They Said So' are no longer available, please see{" "} - - this GitHub issue - - . We apologize for the inconvenience this may have caused. -

Hourly Quotes
); diff --git a/src/plugins/widgets/quote/api.ts b/src/plugins/widgets/quote/api.ts index 14ccfc89f..f90ed1c5b 100644 --- a/src/plugins/widgets/quote/api.ts +++ b/src/plugins/widgets/quote/api.ts @@ -2,17 +2,37 @@ import { API } from "../../types"; import { Quote } from "./types"; // Get developer excuse -async function getDeveloperExcuse() { +async function getDeveloperExcuse(): Promise<{quote: string, author: string | undefined}> { try { const res = await fetch("https://api.tabliss.io/v1/developer-excuses"); const body = await res.json(); return { quote: body.data, + author: "Normal Developer" }; } catch (err) { return { quote: "Unable to get a new developer excuse.", + author: undefined + }; + } +} + +async function getRandomQuote(): Promise<{quote: string, author: string | undefined}> { + try { + const res = await fetch("https://api.quotable.io/quotes/random?limit=1"); + const body = await res.json(); + const quote = body[0]; + + return { + quote: quote.content, + author: quote.author + }; + } catch (err) { + return { + quote: "Unable to get random quote.", + author: undefined }; } } @@ -21,17 +41,23 @@ export async function getQuote( loader: API["loader"], category: string, ): Promise { + loader.push(); - const data = await getDeveloperExcuse(); + const data = + category === "developerexcuses" + ? await getDeveloperExcuse() + : await getRandomQuote(); loader.pop(); const quote = cleanQuote(data.quote); + const author = data.author; return { ...data, quote, + author, timestamp: Date.now(), }; }