mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2026-01-15 12:15:02 +00:00
This commit is contained in:
@@ -24,6 +24,19 @@ const API_URL = {
|
|||||||
ART_INSTITUTE_OF_CHICAGO: "https://api.artic.edu/api/v1/artworks/search",
|
ART_INSTITUTE_OF_CHICAGO: "https://api.artic.edu/api/v1/artworks/search",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isResourceOk = async (url: string): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const { ok } = await fetch(url, {
|
||||||
|
...HIGH_PRIORITY_REQUEST,
|
||||||
|
method: "HEAD",
|
||||||
|
});
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const wallpaperHandler: Record<string, WallpaperHandler> = {
|
export const wallpaperHandler: Record<string, WallpaperHandler> = {
|
||||||
APOD: async ({ isAlt }) => {
|
APOD: async ({ isAlt }) => {
|
||||||
const response = await jsonFetch(
|
const response = await jsonFetch(
|
||||||
@@ -111,12 +124,8 @@ export const wallpaperHandler: Record<string, WallpaperHandler> = {
|
|||||||
|
|
||||||
if (image_id) {
|
if (image_id) {
|
||||||
const url = `https://www.artic.edu/iiif/2/${image_id}/full/1686,/0/default.jpg`;
|
const url = `https://www.artic.edu/iiif/2/${image_id}/full/1686,/0/default.jpg`;
|
||||||
const { ok } = await fetch(url, {
|
|
||||||
...HIGH_PRIORITY_REQUEST,
|
|
||||||
method: "HEAD",
|
|
||||||
});
|
|
||||||
|
|
||||||
if (ok) return url;
|
if (await isResourceOk(url)) return url;
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Ignore failure to get wallpaper
|
// Ignore failure to get wallpaper
|
||||||
@@ -139,10 +148,16 @@ export const wallpaperHandler: Record<string, WallpaperHandler> = {
|
|||||||
wallpaperUrl: await maybeFetchArtwork(),
|
wallpaperUrl: await maybeFetchArtwork(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
LOREM_PICSUM: () => ({
|
LOREM_PICSUM: () => {
|
||||||
fallbackBackground: "",
|
// eslint-disable-next-line unicorn/consistent-function-scoping
|
||||||
newWallpaperFit: "fill",
|
const createLoremPicsumUrl = (): string =>
|
||||||
updateTimeout: MILLISECONDS_IN_HOUR,
|
`https://picsum.photos/seed/${Math.floor(Math.random() * Date.now())}/${viewWidth()}/${viewHeight()}`;
|
||||||
wallpaperUrl: `https://picsum.photos/seed/${Date.now()}/${viewWidth()}/${viewHeight()}`,
|
|
||||||
}),
|
return {
|
||||||
|
fallbackBackground: createLoremPicsumUrl(),
|
||||||
|
newWallpaperFit: "fill",
|
||||||
|
updateTimeout: MILLISECONDS_IN_HOUR,
|
||||||
|
wallpaperUrl: createLoremPicsumUrl(),
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user