Skip to content

Commit

Permalink
Handle unsplash errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vanpelt committed Jun 23, 2024
1 parent 45badee commit e2feb3b
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 159 deletions.
304 changes: 152 additions & 152 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,154 +1,154 @@
{
"name": "openui",
"license": "MIT",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "vite build",
"postbuild": "rm -rf ../backend/openui/dist && cp -r dist ../backend/openui/dist",
"deploy": "npm run build -- --mode hosted && fly deploy ../backend",
"commit": "cz",
"dev": "vite --open",
"prepare": "cd .. && husky install frontend/.husky",
"preview": "vite preview",
"preview:test": "start-server-and-test preview http://localhost:4173",
"test": "vitest",
"test:ci": "vitest run",
"test:e2e": "pnpm preview:test 'cypress open'",
"test:e2e:headless": "pnpm preview:test 'cypress run'",
"test:e2e:ci": "vite build && pnpm preview:test 'cypress run --record'",
"format": "prettier -uw --cache --ignore-path .gitignore .",
"run-tsc": "tsc",
"run-eslint": "eslint --cache --fix --ignore-path .gitignore --ext .ts,.tsx .",
"run-stylelint": "stylelint --cache --fix --ignore-path .gitignore **/*.css",
"lint": "run-p run-tsc run-eslint run-stylelint",
"validate": "run-p lint test:ci test:e2e:headless"
},
"dependencies": {
"@monaco-editor/react": "^4.6.0",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-hover-card": "^1.0.7",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slider": "^1.1.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@tailwindcss/typography": "^0.5.13",
"@tanstack/react-query": "^5.36.0",
"@types/mdast": "^4.0.3",
"@uiw/copy-to-clipboard": "^1.0.17",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"groq-sdk": "^0.3.3",
"i18next": "^23.11.5",
"jotai": "^2.8.0",
"jotai-devtools": "^0.10.0",
"jotai-minidb": "^0.0.8",
"js-cookie": "^3.0.5",
"litellm": "^0.12.0",
"lucide-react": "^0.378.0",
"monaco-editor": "^0.49.0",
"monaco-tailwindcss": "^0.6.0",
"nanoid": "^5.0.7",
"openai": "^4.45.0",
"prettier": "^3.2.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-i18next": "^14.1.2",
"react-markdown": "^9.0.1",
"react-router-dom": "^6.23.1",
"react-syntax-highlighter": "^15.5.0",
"remark": "^15.0.1",
"remark-frontmatter": "^5.0.0",
"remark-parse": "^11.0.0",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"unified": "^11.0.4",
"unsplash-js": "^7.0.19"
},
"devDependencies": {
"@nabla/vite-plugin-eslint": "^2.0.4",
"@playwright/test": "^1.44.1",
"@tailwindcss/forms": "^0.5.7",
"@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/css-mediaquery": "^0.1.4",
"@types/js-cookie": "^3.0.6",
"@types/node": "^20.14.7",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"@types/react-syntax-highlighter": "^15.5.13",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-istanbul": "^1.6.0",
"autoprefixer": "^10.4.19",
"commitizen": "^4.3.0",
"css-mediaquery": "^0.1.2",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-prefer-function-component": "^3.3.0",
"eslint-plugin-testing-library": "^6.2.2",
"eslint-plugin-unicorn": "^53.0.0",
"husky": "^9.0.11",
"jsdom": "^24.0.0",
"lint-staged": "^15.2.2",
"msw": "^2.3.0",
"npm-run-all": "^4.1.5",
"ollama": "^0.5.1",
"postcss": "^8.4.38",
"prettier-plugin-tailwindcss": "^0.5.14",
"start-server-and-test": "^2.0.3",
"stylelint": "^16.5.0",
"stylelint-config-standard": "^36.0.0",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vite-plugin-mkcert": "^1.17.5",
"vite-plugin-monaco-editor": "^1.1.0",
"vite-plugin-pwa": "^0.20.0",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.6.0",
"whatwg-fetch": "^3.6.20",
"workbox-build": "^7.1.0",
"workbox-window": "^7.1.0"
},
"browserslist": {
"production": "Edge >= 18, Firefox >= 60, Chrome >= 61, Safari >= 11, Opera >= 48",
"development": [
"last 1 chrome version",
"last 1 firefox version"
]
},
"lint-staged": {
"*": "prettier -uw --cache",
"*.css": "stylelint --cache --fix",
"*.{ts,tsx}": [
"eslint --cache --fix",
"vitest related --run --coverage=false"
]
},
"pnpm": {
"overrides": {
"headers-polyfill": "3.1.2"
}
}
"name": "openui",
"license": "MIT",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "vite build",
"postbuild": "rm -rf ../backend/openui/dist && cp -r dist ../backend/openui/dist",
"deploy": "npm run build -- --mode hosted && fly deploy ../backend && git restore ../backend/openui/dist && git clean -f ../backend/openui/dist/assets/",
"commit": "cz",
"dev": "vite --open",
"prepare": "cd .. && husky install frontend/.husky",
"preview": "vite preview",
"preview:test": "start-server-and-test preview http://localhost:4173",
"test": "vitest",
"test:ci": "vitest run",
"test:e2e": "pnpm preview:test 'cypress open'",
"test:e2e:headless": "pnpm preview:test 'cypress run'",
"test:e2e:ci": "vite build && pnpm preview:test 'cypress run --record'",
"format": "prettier -uw --cache --ignore-path .gitignore .",
"run-tsc": "tsc",
"run-eslint": "eslint --cache --fix --ignore-path .gitignore --ext .ts,.tsx .",
"run-stylelint": "stylelint --cache --fix --ignore-path .gitignore **/*.css",
"lint": "run-p run-tsc run-eslint run-stylelint",
"validate": "run-p lint test:ci test:e2e:headless"
},
"dependencies": {
"@monaco-editor/react": "^4.6.0",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-hover-card": "^1.0.7",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slider": "^1.1.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@tailwindcss/typography": "^0.5.13",
"@tanstack/react-query": "^5.36.0",
"@types/mdast": "^4.0.3",
"@uiw/copy-to-clipboard": "^1.0.17",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"groq-sdk": "^0.3.3",
"i18next": "^23.11.5",
"jotai": "^2.8.0",
"jotai-devtools": "^0.10.0",
"jotai-minidb": "^0.0.8",
"js-cookie": "^3.0.5",
"litellm": "^0.12.0",
"lucide-react": "^0.378.0",
"monaco-editor": "^0.49.0",
"monaco-tailwindcss": "^0.6.0",
"nanoid": "^5.0.7",
"openai": "^4.45.0",
"prettier": "^3.2.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-i18next": "^14.1.2",
"react-markdown": "^9.0.1",
"react-router-dom": "^6.23.1",
"react-syntax-highlighter": "^15.5.0",
"remark": "^15.0.1",
"remark-frontmatter": "^5.0.0",
"remark-parse": "^11.0.0",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"unified": "^11.0.4",
"unsplash-js": "^7.0.19"
},
"devDependencies": {
"@nabla/vite-plugin-eslint": "^2.0.4",
"@playwright/test": "^1.44.1",
"@tailwindcss/forms": "^0.5.7",
"@testing-library/dom": "^10.1.0",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^15.0.7",
"@testing-library/user-event": "^14.5.2",
"@types/css-mediaquery": "^0.1.4",
"@types/js-cookie": "^3.0.6",
"@types/node": "^20.14.7",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"@types/react-syntax-highlighter": "^15.5.13",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-istanbul": "^1.6.0",
"autoprefixer": "^10.4.19",
"commitizen": "^4.3.0",
"css-mediaquery": "^0.1.2",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-prefer-function-component": "^3.3.0",
"eslint-plugin-testing-library": "^6.2.2",
"eslint-plugin-unicorn": "^53.0.0",
"husky": "^9.0.11",
"jsdom": "^24.0.0",
"lint-staged": "^15.2.2",
"msw": "^2.3.0",
"npm-run-all": "^4.1.5",
"ollama": "^0.5.1",
"postcss": "^8.4.38",
"prettier-plugin-tailwindcss": "^0.5.14",
"start-server-and-test": "^2.0.3",
"stylelint": "^16.5.0",
"stylelint-config-standard": "^36.0.0",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vite-plugin-mkcert": "^1.17.5",
"vite-plugin-monaco-editor": "^1.1.0",
"vite-plugin-pwa": "^0.20.0",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.6.0",
"whatwg-fetch": "^3.6.20",
"workbox-build": "^7.1.0",
"workbox-window": "^7.1.0"
},
"browserslist": {
"production": "Edge >= 18, Firefox >= 60, Chrome >= 61, Safari >= 11, Opera >= 48",
"development": [
"last 1 chrome version",
"last 1 firefox version"
]
},
"lint-staged": {
"*": "prettier -uw --cache",
"*.css": "stylelint --cache --fix",
"*.{ts,tsx}": [
"eslint --cache --fix",
"vitest related --run --coverage=false"
]
},
"pnpm": {
"overrides": {
"headers-polyfill": "3.1.2"
}
}
}
18 changes: 11 additions & 7 deletions frontend/src/lib/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,17 @@ async function getRandomPhoto(
img = results[Math.floor(seed * results.length)]
}
if (!img) {
console.log(`Searching unsplash for ${image.alt} ${image.src}`)
const data = await api.search.getPhotos({ query: image.alt, orientation })
// TODO: maybe grab a random image from the results
results = data.response?.results ?? []
if (results.length > 0) {
img = results[Math.floor(seed * results.length)]
CACHE.set(image.alt, results)
try {
console.log(`Searching unsplash for ${image.alt} ${image.src}`)
const data = await api.search.getPhotos({ query: image.alt, orientation })
// TODO: maybe grab a random image from the results
results = data.response?.results ?? []
if (results.length > 0) {
img = results[Math.floor(seed * results.length)]
CACHE.set(image.alt, results)
}
} catch (error) {
console.error(error)
}
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function fixHTML(html: string) {
let fixed = html.replaceAll('-gray-', '-zinc-')
// use placehold.co for images
fixed = fixed.replaceAll('via.placeholder.com', 'placehold.co')
fixed = fixed.replaceAll('via.placeholder.co', 'placehold.co')
fixed = fixed.replaceAll('placehold.it', 'placehold.co')
// point to our own backend for mp3's / wav files
fixed = fixed.replaceAll(
Expand Down

0 comments on commit e2feb3b

Please sign in to comment.