Skip to content

Commit

Permalink
fix: various webextension issues (#1439)
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy committed Sep 6, 2024
2 parents fac8f95 + f22bb6f commit 7a4ef1f
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
command: dockerize -wait tcp://localhost:3000 -timeout 30s
- run:
name: lint, typecheck, test, build
command: npx nx run-many --targets=lint,typecheck,test,build
command: npx nx run-many --targets=lint,typecheck,test,build --output-style=static
push_backend:
resource_class: large
docker:
Expand Down
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"libsDir": "packages"
},
"useDaemonProcess": false,
"nxCloudAccessToken": "OGY4NDE3OTItYWViMS00YWM0LTk4ODgtYmI2ZWNhYjY1OGMyfHJlYWQtb25seQ==",
"neverConnectToCloud": true,
"useInferencePlugins": false,
"defaultBase": "master"
}
5 changes: 3 additions & 2 deletions packages/trpc/src/procedures/labels/createLabel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import type { AppRouter } from "../../index";

describe("create Label", () => {
let user: User;
let user2: User;
let trpc: CreateTRPCProxyClient<AppRouter>;

beforeAll(async () => {
({ user, trpc } = await trpcSetup());
({ user, user2, trpc } = await trpcSetup());
});

afterAll(() => {
return tearDown(user.id);
return tearDown(user.id, user2.id);
});

describe("success", () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/trpc/src/procedures/labels/deleteLabel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { faker } from "@faker-js/faker";

describe("deleteLabel", () => {
let user: User;
let user2: User;
let trpc: CreateTRPCProxyClient<AppRouter>;

beforeAll(async () => {
({ user, trpc } = await trpcSetup());
({ user, user2, trpc } = await trpcSetup());
});

afterAll(() => {
return tearDown(user.id);
return tearDown(user.id, user2.id);
});

describe("success", () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/trpc/src/procedures/labels/getLabels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import type { AppRouter } from "../../index";

describe("getLabels", () => {
let user: User;
let user2: User;
let trpc: CreateTRPCProxyClient<AppRouter>;

beforeEach(async () => {
({ user, trpc } = await trpcSetup());
({ user, user2, trpc } = await trpcSetup());
});

afterEach(() => {
return tearDown(user.id);
return tearDown(user.id, user2.id);
});

describe("success", () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/trpc/src/procedures/labels/getLabelsByUserId.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import type { AppRouter } from "../../index";

describe("getLabelsByUserId", () => {
let user: User;
let user2: User;
let trpc: CreateTRPCProxyClient<AppRouter>;

beforeAll(async () => {
({ user, trpc } = await trpcSetup());
({ user, user2, trpc } = await trpcSetup());
});

afterAll(() => {
return tearDown(user.id);
return tearDown(user.id, user2.id);
});

describe("success", () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/trpc/src/procedures/labels/updateLabel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import type { AppRouter } from "../../index";

describe("updates label", () => {
let user: User;
let user2: User;
let trpc: CreateTRPCProxyClient<AppRouter>;

beforeEach(async () => {
({ user, trpc } = await trpcSetup());
({ user, user2, trpc } = await trpcSetup());
});

afterEach(() => {
return tearDown(user.id);
return tearDown(user.id, user2.id);
});

describe("success", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import type { AppRouter } from "../../index";

describe("getRecipe", () => {
let user: User;
let user2: User;
let trpc: CreateTRPCProxyClient<AppRouter>;

beforeAll(async () => {
({ user, trpc } = await trpcSetup());
({ user, user2, trpc } = await trpcSetup());
});

afterAll(() => {
return tearDown(user.id);
return tearDown(user.id, user2.id);
});

describe("success", () => {
Expand Down Expand Up @@ -67,7 +68,7 @@ describe("getRecipe", () => {
});

it("seperate recipies by user", async () => {
const { user: user2 } = await trpcSetup();
const { user: user2, user2: user3 } = await trpcSetup();
await prisma.recipe.create({
data: {
...recipeFactory(user2.id),
Expand All @@ -80,6 +81,6 @@ describe("getRecipe", () => {
});
expect(response).toEqual("Spagetti with tomatos");

return tearDown(user2.id);
return tearDown(user2.id, user3.id);
});
});
5 changes: 4 additions & 1 deletion packages/webextension-v3/src/action/action.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@
<div class="container">
<div id="start">
<div class="headline">
<img class="logo" /><br /><br />
<a href="https://recipesage.com" target="_blank">
<img class="logo" />
</a>
<br /><br />
<h2>Import Site</h2>
</div>
<button id="auto-import">&nbsp;Auto Import&nbsp;</button>&nbsp;
Expand Down
6 changes: 2 additions & 4 deletions packages/webextension-v3/src/action/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,13 @@ const saveClip = async (clipData) => {
case 401:
chrome.storage.local.set({ token: null }, () => {
window.alert(
"Please Login. It looks like you're logged out. Please click the\
RecipeSage icon to login again.",
"Please Login. It looks like you're logged out. Please close and re-open the clip tool to login.",
);
});
break;
default:
window.alert(
"Could Not Save Recipe. An error occurred while saving the recipe.\
Please try again.",
"An error occurred while saving the recipe. Please try again.",
);
break;
}
Expand Down
44 changes: 23 additions & 21 deletions packages/webextension-v3/src/inject/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ if (window[extensionContainerId]) {

let logoLink = document.createElement("a");
logoLink.href = "https://recipesage.com";
logoLink.target = "_blank";
logoLink.onmousedown = (e) => e.stopPropagation();
leftHeadline.appendChild(logoLink);

Expand Down Expand Up @@ -427,28 +428,29 @@ if (window[extensionContainerId]) {
const token = await fetchToken();

let imageId;
try {
const imageResponse = await fetch(currentSnip.imageURL);
const imageBlob = await imageResponse.blob();

const formData = new FormData();
formData.append("image", imageBlob);

const imageCreateResponse = await fetch(
`https://api.recipesage.com/images?token=${token}`,
{
method: "POST",
body: formData,
},
);

if (!imageCreateResponse.ok) return;

const imageData = await imageCreateResponse.json();
if (currentSnip.imageURL?.trim().length) {
try {
const imageResponse = await fetch(currentSnip.imageURL);
const imageBlob = await imageResponse.blob();

const formData = new FormData();
formData.append("image", imageBlob);

const imageCreateResponse = await fetch(
`https://api.recipesage.com/images?token=${token}`,
{
method: "POST",
body: formData,
},
);

imageId = imageData.id;
} catch (e) {
console.error("Error creating image", e);
if (imageCreateResponse.ok) {
const imageData = await imageCreateResponse.json();
imageId = imageData.id;
}
} catch (e) {
console.error("Error creating image", e);
}
}

const recipeCreateResponse = await fetch(
Expand Down

0 comments on commit 7a4ef1f

Please sign in to comment.