aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorDhravya Shah <[email protected]>2024-08-09 22:44:48 -0700
committerDhravya Shah <[email protected]>2024-08-09 22:44:48 -0700
commit12aa2e083217e6944e15fe6099caa7cc71018212 (patch)
tree45001ee5bb724395e2ef6f8c8f4dc62569007764 /apps
parentMerge branch 'main' of github.com:supermemoryai/supermemory (diff)
downloadsupermemory-12aa2e083217e6944e15fe6099caa7cc71018212.tar.xz
supermemory-12aa2e083217e6944e15fe6099caa7cc71018212.zip
made counter work, wait on ratelimits and handle errors gracefully
Diffstat (limited to 'apps')
-rw-r--r--apps/extension/background.ts44
1 files changed, 3 insertions, 41 deletions
diff --git a/apps/extension/background.ts b/apps/extension/background.ts
index b905c7c9..5703b3d6 100644
--- a/apps/extension/background.ts
+++ b/apps/extension/background.ts
@@ -173,6 +173,9 @@ const importTweet = async (tweetMd: string, tweet: Tweet) => {
})
.then(async (response) => {
if (!response.ok) {
+ if (response.status === 444) {
+ resolve(); // Skip saving if the tweet already exists
+ }
console.log(
"Supermemory error",
response.status,
@@ -268,47 +271,6 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
return;
}
chrome.storage.session.set({ cookie, csrf, auth });
-
- const myHeaders = new Headers();
- myHeaders.append("Cookie", cookie);
- myHeaders.append("X-Csrf-token", csrf);
- myHeaders.append("Authorization", auth);
-
- const requestOptions: RequestInit = {
- method: "GET",
- headers: myHeaders,
- redirect: "follow",
- };
-
- const variables = {
- count: 200,
- includePromotedContent: false,
- };
-
- // only fetch once in 1 minute
- if (now - lastTwitterFetch < 60 * 1000) {
- console.log("Waiting for ratelimits");
- return;
- }
-
- fetch(
- `${BOOKMARKS_URL}&variables=${encodeURIComponent(JSON.stringify(variables))}`,
- requestOptions,
- )
- .then((response) => response.text())
- .then((result) => {
- const tweets = getAllTweets(JSON.parse(result));
-
- console.log("tweets", tweets);
- // Cache the result along with the current timestamp
- chrome.storage.local.set({
- lastFetch: new Date().getTime(),
- cachedData: tweets,
- });
-
- lastTwitterFetch = now;
- })
- .catch((error) => console.error(error));
});
return;
}