Created
November 16, 2020 20:19
-
-
Save jasonLaster/b827ae45985a51321480d68d222f43ef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| diff --git a/src/dispatch/internal.js b/src/dispatch/internal.js | |
| index a09fc7bb..c7082e40 100644 | |
| --- a/src/dispatch/internal.js | |
| +++ b/src/dispatch/internal.js | |
| @@ -18,12 +18,55 @@ async function fetchGraphQL(query, name, variables = {}) { | |
| return await result.json(); | |
| } | |
| +async function fetchUser(authId) { | |
| + const query = `query fetchUser($auth_id: String) { | |
| + userIds(where: {auth_id: { _eq: $auth_id } }, limit: 1) { | |
| + id | |
| + } | |
| + } | |
| + `; | |
| + let response = await fetchGraphQL(query, "fetchUser", { auth_id: authId }); | |
| + return response.userIds[0]; | |
| +} | |
| + | |
| const InternalMessageHandlers = { | |
| "Internal.echo": async function ({ str, count }) { | |
| const newStr = str.repeat(count); | |
| return { str: newStr }; | |
| }, | |
| + "Internal.saveRecording": async ({ recordingData, authId }) => { | |
| + // we used to use get-user.ts to get the hasura user_id. We can do that directly from the backend now | |
| + // https://github.com/RecordReplay/recordings/blob/master/pages/api/get-user.ts | |
| + | |
| + const user = await fetchUser(authId); | |
| + | |
| + // heavily inspired by | |
| + // https://github.com/RecordReplay/recordings/blob/master/pages/api/create-recording.ts | |
| + | |
| + const name = `SaveRecording`; | |
| + const query = ` | |
| + mutation SaveRecording($data: recordings_insert_input!) { | |
| + insert_recordings_one(object: $data) { | |
| + id | |
| + recording_id | |
| + last_screen_data | |
| + last_screen_mime_type | |
| + duration | |
| + title | |
| + url | |
| + user_id | |
| + } | |
| + } | |
| + `; | |
| + | |
| + let response = await fetchGraphQL(query, name, { | |
| + data: { ...recordingData, user_id: user.id }, | |
| + }); | |
| + return { recordings: response.data.insert_recordings_one }; | |
| + }, | |
| + | |
| "Internal.getRecordings": async function ({ authId }) { | |
| const name = `GetRecordings`; | |
| const query = ` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment