-
-
Notifications
You must be signed in to change notification settings - Fork 93
feat: Add Klipy as a GIF provider alongside Tenor #1932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3e9642b
905cd97
7a77402
e26b057
e2e016c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import {isTestEnv} from '../../test/utils/isTestEnv'; | ||
|
|
||
| export const tenorConfig = isTestEnv ? {googleApiKey: 'xxx'} : getTenorConfig(); | ||
|
|
||
| // In tests the GIF provider defaults to Tenor; the ?gifProvider=klipy query | ||
| // param opts a specific test into the Klipy path. | ||
| export const klipyConfig = isTestEnv ? getTestKlipyConfig() : getKlipyConfig(); | ||
|
|
||
| function getTenorConfig() { | ||
| let config = null; | ||
|
|
||
| if (import.meta.env.VITE_TENOR_API_KEY) { | ||
| config = { | ||
| googleApiKey: import.meta.env.VITE_TENOR_API_KEY | ||
| }; | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| function getKlipyConfig() { | ||
| let config = null; | ||
|
|
||
| if (import.meta.env.VITE_KLIPY_API_KEY) { | ||
| config = { | ||
| apiKey: import.meta.env.VITE_KLIPY_API_KEY | ||
| }; | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| function getTestKlipyConfig() { | ||
| const provider = new URLSearchParams(window.location.search).get('gifProvider'); | ||
| return provider === 'klipy' ? {apiKey: 'xxx'} : null; | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import {ERROR_TYPE} from '../../../../utils/services/gif.js'; | ||
|
|
||
| export function Error({error}) { | ||
| if (error === ERROR_TYPE.COMMON) { | ||
| return ( | ||
| <p> | ||
| Uh-oh! Trouble reaching the GIF service, please check your connection | ||
| </p> | ||
| ); | ||
| } | ||
|
|
||
| if (error === ERROR_TYPE.INVALID_API_KEY) { | ||
| return ( | ||
| <p> | ||
| The GIF API key is not valid. Please check your configuration by following our | ||
| <a href="https://ghost.org/docs/config/" rel="noopener noreferrer" target="_blank"> documentation here</a>. | ||
| </p> | ||
| ); | ||
| } | ||
| return ( | ||
| <p>{error}</p> | ||
| ); | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,7 +5,7 @@ import {$generateHtmlFromNodes} from '@lexical/html'; | |||||
| import {ImageNode as BaseImageNode} from '@tryghost/kg-default-nodes'; | ||||||
| import {ImageNodeComponent} from './ImageNodeComponent'; | ||||||
| import {KoenigCardWrapper, MINIMAL_NODES} from '../index.js'; | ||||||
| import {OPEN_TENOR_SELECTOR_COMMAND, OPEN_UNSPLASH_SELECTOR_COMMAND} from '../plugins/KoenigSelectorPlugin.jsx'; | ||||||
| import {OPEN_GIF_SELECTOR_COMMAND, OPEN_UNSPLASH_SELECTOR_COMMAND} from '../plugins/KoenigSelectorPlugin.jsx'; | ||||||
| import {cleanBasicHtml} from '@tryghost/kg-clean-basic-html'; | ||||||
| import {createCommand} from 'lexical'; | ||||||
| import {populateNestedEditor, setupNestedEditor} from '../utils/nested-editors'; | ||||||
|
|
@@ -51,14 +51,14 @@ export class ImageNode extends BaseImageNode { | |||||
| label: 'GIF', | ||||||
| desc: 'Search and embed gifs', | ||||||
| Icon: GIFIcon, | ||||||
| insertCommand: OPEN_TENOR_SELECTOR_COMMAND, | ||||||
| insertCommand: OPEN_GIF_SELECTOR_COMMAND, | ||||||
| insertParams: { | ||||||
| triggerFileDialog: false | ||||||
| }, | ||||||
| matches: ['gif', 'giphy', 'tenor'], | ||||||
| matches: ['gif', 'giphy', 'tenor', 'klipy'], | ||||||
| priority: 17, | ||||||
| queryParams: ['src'], | ||||||
| isHidden: ({config}) => !config?.tenor, | ||||||
| isHidden: ({config}) => !config?.tenor && !config?.klipy, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hide GIF menu item when no valid provider key is configured. Line 61 gates visibility by provider object presence, but provider resolution requires Suggested fix- isHidden: ({config}) => !config?.tenor && !config?.klipy,
+ isHidden: ({config}) => !(config?.klipy?.apiKey || config?.tenor?.googleApiKey),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pre-existing pattern — the previous line In the real Ghost ↔ Koenig contract, the consumer nullifies the provider object when no key is set:
(Tenor follows the same pattern, long-standing.) So in practice the object-presence check is equivalent to the key-presence check. The defensive-by- There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
✏️ Learnings added
|
||||||
| shortcut: '/gif' | ||||||
| }]; | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.