-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#245): dynamically fetch the sponsorship message
Added one-time fetch function on backend as fetching on frontend was blocked due to CORS
- Loading branch information
1 parent
e9cb60a
commit b122640
Showing
7 changed files
with
63 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// fetch a resource and return the result to the renderer | ||
// this is meant as a one-off utility for special cases | ||
import { ipcMain } from 'electron' | ||
import { IPC_EVENT_oneTimeFetch } from '../shared/main-renderer-events' | ||
import fetch from 'node-fetch' | ||
|
||
async function oneTimeFetch(url) { | ||
if (url.length == 0) return false | ||
|
||
let res = await fetch(url) | ||
if (res) { | ||
return res.json() | ||
} | ||
else { | ||
return null | ||
} | ||
} | ||
|
||
function setupOneTimeFetchEvent() { | ||
// comes from the renderer process (ipcRenderer.send()) | ||
ipcMain.on(IPC_EVENT_oneTimeFetch, async (event, payload) => { | ||
let res = await oneTimeFetch(payload) | ||
event.sender.send(IPC_EVENT_oneTimeFetch, res) | ||
}) | ||
} | ||
export { setupOneTimeFetchEvent, oneTimeFetch } |
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ export * from './file/save' | |
export * from './file/unzip' | ||
|
||
export * from './log' | ||
export * from './oneTimeFetch' |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ipcRenderer } from 'electron' | ||
import * as events from 'shared/main-renderer-events' | ||
|
||
// get JSON data from an arbitrary endpoint | ||
export function oneTimeFetch(url) { | ||
return new Promise<JSON>((resolve, reject) => { | ||
ipcRenderer.send(events.IPC_EVENT_oneTimeFetch, url) | ||
ipcRenderer.once(events.IPC_EVENT_oneTimeFetch, (event, res: JSON) => { | ||
resolve(res) | ||
}) | ||
}) | ||
} |
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