aboutsummaryrefslogtreecommitdiff
path: root/apps/extension/src/background.ts
diff options
context:
space:
mode:
authorYash <[email protected]>2024-04-11 04:52:44 +0000
committerYash <[email protected]>2024-04-11 04:52:44 +0000
commit6dcc7d18c9be5e3a5e0a3ff60668424ee0158b4e (patch)
tree179aa936536510cc707368fc7c330c4c7fbdc3f8 /apps/extension/src/background.ts
parentnovel editor (diff)
parentsave user ID with url to ensure that same website can be saved by users (diff)
downloadsupermemory-new-ui.tar.xz
supermemory-new-ui.zip
Merge branch 'main' of https://github.com/Dhravya/supermemory into new-uinew-ui
Diffstat (limited to 'apps/extension/src/background.ts')
-rw-r--r--apps/extension/src/background.ts30
1 files changed, 17 insertions, 13 deletions
diff --git a/apps/extension/src/background.ts b/apps/extension/src/background.ts
index 137849b8..2cf29f40 100644
--- a/apps/extension/src/background.ts
+++ b/apps/extension/src/background.ts
@@ -1,6 +1,9 @@
import { getEnv } from "./util";
-const backendUrl = getEnv() === "development" ? "http://localhost:3000" : "https://supermemory.dhr.wtf";
+const backendUrl =
+ getEnv() === "development"
+ ? "http://localhost:3000"
+ : "https://supermemory.dhr.wtf";
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type === "getJwt") {
@@ -9,9 +12,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
});
return true;
- }
-
- else if (request.type === "urlChange") {
+ } else if (request.type === "urlChange") {
const content = request.content;
const url = request.url;
@@ -24,15 +25,13 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
fetch(`${backendUrl}/api/store`, {
method: "POST",
headers: {
- "Authorization": `Bearer ${jwt}`,
+ Authorization: `Bearer ${jwt}`,
},
body: JSON.stringify({ pageContent: content, url }),
- }).then(ers => console.log(ers.status))
+ }).then((ers) => console.log(ers.status));
});
})();
- }
-
- else if (request.type === "queryApi") {
+ } else if (request.type === "queryApi") {
const input = request.input;
const jwt = request.jwt;
@@ -40,12 +39,12 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
await fetch(`${backendUrl}/api/ask`, {
method: "POST",
headers: {
- "Authorization": `Bearer ${jwt}`,
+ Authorization: `Bearer ${jwt}`,
},
body: JSON.stringify({
query: input,
}),
- }).then(async response => {
+ }).then(async (response) => {
if (!response.body) {
throw new Error("No response body");
}
@@ -59,8 +58,13 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (done) break;
// For simplicity, we're sending chunks as they come.
// This might need to be adapted based on your data and needs.
- const chunkAsString = new TextDecoder('utf-8').decode(value).replace("data: ", "")
- chrome.tabs.sendMessage(sender.tab.id, { action: "streamData", data: chunkAsString });
+ const chunkAsString = new TextDecoder("utf-8")
+ .decode(value)
+ .replace("data: ", "");
+ chrome.tabs.sendMessage(sender.tab.id, {
+ action: "streamData",
+ data: chunkAsString,
+ });
}
// Notify the content script that the stream is complete.
chrome.tabs.sendMessage(sender.tab.id, { action: "streamEnd" });