generated from dsebastien/obsidian-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced globalThis.fetch with node-fetch
- Loading branch information
1 parent
d6fffe0
commit 6f56fd7
Showing
10 changed files
with
122 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import {log} from "./log"; | ||
import Replicate from "replicate"; | ||
import { log } from './log'; | ||
import Replicate from 'replicate'; | ||
|
||
export const getReplicateClient = (apiKey: string): Replicate => { | ||
log('Creating Replicate.com API client', 'debug'); | ||
return new Replicate({ | ||
auth: apiKey, | ||
userAgent: 'Obsidian Replicate', | ||
}); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {PluginSettings} from "../types/plugin-settings.intf"; | ||
import { PluginSettings } from '../types/plugin-settings.intf'; | ||
|
||
export const isApiKeyConfigured = (settings: PluginSettings): boolean => { | ||
return '' !== settings.apiKey.trim(); | ||
} | ||
}; |
8 changes: 5 additions & 3 deletions
8
apps/plugin/src/app/utils/is-image-generation-model-configured.fn.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import {PluginSettings} from "../types/plugin-settings.intf"; | ||
import { PluginSettings } from '../types/plugin-settings.intf'; | ||
|
||
export const isImageGenerationModelConfigured = (settings: PluginSettings): boolean => { | ||
export const isImageGenerationModelConfigured = ( | ||
settings: PluginSettings | ||
): boolean => { | ||
return '' !== settings.imageGenerationModel.trim(); | ||
} | ||
}; |
2 changes: 1 addition & 1 deletion
2
apps/plugin/src/app/utils/replicate-create-prediction-input.intf.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
import { ReplicatePlugin } from './app/plugin'; | ||
import nfetch, { Headers, Request, Response } from 'node-fetch'; | ||
|
||
// Replace the browser's fetch (which uses CORS) with node-fetch, which is compatible, but has no CORS restrictions | ||
// Reference: https://forum.obsidian.md/t/make-http-requests-from-plugins/15461/25?page=2 | ||
|
||
// @ts-expect-error - globalThis is not defined in the Node.js environment | ||
globalThis.fetch = nfetch; | ||
// @ts-expect-error - globalThis is not defined in the Node.js environment | ||
globalThis.Headers = Headers; | ||
// @ts-expect-error - globalThis is not defined in the Node.js environment | ||
globalThis.Request = Request; | ||
// @ts-expect-error - globalThis is not defined in the Node.js environment | ||
globalThis.Response = Response; | ||
|
||
// noinspection JSUnusedGlobalSymbols | ||
export default ReplicatePlugin; |