Skip to content

Commit

Permalink
fix(frontend): do not use backend url in <img> (langflow-ai#2424)
Browse files Browse the repository at this point in the history
* fronted: do not use backend url in <img>

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 2, 2024
1 parent 9bc683b commit b44e43a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 46 deletions.
27 changes: 5 additions & 22 deletions src/frontend/src/components/headerComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
import AlertDropdown from "../../alerts/alertDropDown";
import profileCircle from "../../assets/profile-circle.png";
import {
BACKEND_URL,
BASE_URL_API,
LOCATIONS_TO_RETURN,
USER_PROJECTS_HEADER,
Expand Down Expand Up @@ -50,11 +49,9 @@ export default function Header(): JSX.Element {
const routeHistory = useLocationStore((state) => state.routeHistory);

const profileImageUrl =
`${BACKEND_URL.slice(
0,
BACKEND_URL.length - 1,
)}${BASE_URL_API}files/profile_pictures/${userData?.profile_image}` ??
profileCircle;
`${BASE_URL_API}files/profile_pictures/${
userData?.profile_image ?? "Space/046-rocket.svg"
}` ?? profileCircle;
async function checkForChanges(): Promise<void> {
if (nodes.length === 0) {
await removeFlow(id!);
Expand Down Expand Up @@ -202,14 +199,7 @@ export default function Header(): JSX.Element {
className="shrink-0"
>
<img
src={
`${BACKEND_URL.slice(
0,
BACKEND_URL.length - 1,
)}${BASE_URL_API}files/profile_pictures/${
userData?.profile_image ?? "Space/046-rocket.svg"
}` ?? profileCircle
}
src={profileImageUrl}
className="h-7 w-7 shrink-0 focus-visible:outline-0"
/>
</Button>
Expand All @@ -220,14 +210,7 @@ export default function Header(): JSX.Element {
<DropdownMenuLabel>
<div className="flex items-center gap-3">
<img
src={
`${BACKEND_URL.slice(
0,
BACKEND_URL.length - 1,
)}${BASE_URL_API}files/profile_pictures/${
userData?.profile_image ?? "Space/046-rocket.svg"
}` ?? profileCircle
}
src={profileImageUrl}
className="h-5 w-5 focus-visible:outline-0"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export default function FileCard({

const fileWrapperClasses = getClasses(isHovered);

const imgSrc = `${BACKEND_URL.slice(
0,
BACKEND_URL.length - 1,
)}${BASE_URL_API}files/images/${content}`;
const imgSrc = `${BASE_URL_API}files/images/${content}`;

if (showFile) {
if (imgTypes.has(fileType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ export default async function handleDownload({
try {
isDownloading = true;

const response = await fetch(
`${BACKEND_URL.slice(
0,
BACKEND_URL.length - 1,
)}${BASE_URL_API}files/download/${content}`,
);
const response = await fetch(`${BASE_URL_API}files/download/${content}`);
if (!response.ok) {
throw new Error("Network response was not ok");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { useEffect } from "react";
import {
BACKEND_URL,
BASE_URL_API,
} from "../../../../../../../../../constants/constants";
import { BASE_URL_API } from "../../../../../../../../../constants/constants";

const usePreloadImages = (
profilePictures: { [key: string]: string[] },
Expand All @@ -24,12 +21,11 @@ const usePreloadImages = (

useEffect(() => {
const imageArray: string[] = [];
const firstUrl = `${BACKEND_URL.slice(0, BACKEND_URL.length - 1)}`;

Object.keys(profilePictures).flatMap((folder) =>
profilePictures[folder].map((path) =>
imageArray.push(
`${firstUrl}${BASE_URL_API}files/profile_pictures/${folder}/${path}`,
`${BASE_URL_API}files/profile_pictures/${folder}/${path}`,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { useEffect, useRef, useState } from "react";
import { Button } from "../../../../../../../../components/ui/button";
import Loading from "../../../../../../../../components/ui/loading";
import {
BACKEND_URL,
BASE_URL_API,
} from "../../../../../../../../constants/constants";
import { BASE_URL_API } from "../../../../../../../../constants/constants";
import { useDarkStore } from "../../../../../../../../stores/darkStore";
import { cn } from "../../../../../../../../utils/utils";
import usePreloadImages from "./hooks/use-preload-images";
Expand Down Expand Up @@ -55,10 +52,7 @@ export default function ProfilePictureChooserComponent({
>
<img
key={idx}
src={`${BACKEND_URL.slice(
0,
BACKEND_URL.length - 1,
)}${BASE_URL_API}files/profile_pictures/${
src={`${BASE_URL_API}files/profile_pictures/${
folder + "/" + path
}`}
style={{
Expand Down

0 comments on commit b44e43a

Please sign in to comment.