mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-25 19:15:18 +02:00
refactor(env): replace inline process.env reads with BACKEND_URL in connector forms and hooks
This commit is contained in:
parent
1119f557df
commit
9e886f8274
6 changed files with 15 additions and 15 deletions
|
|
@ -9,11 +9,11 @@ import { useApiKey } from "@/hooks/use-api-key";
|
||||||
import { copyToClipboard as copyToClipboardUtil } from "@/lib/utils";
|
import { copyToClipboard as copyToClipboardUtil } from "@/lib/utils";
|
||||||
import { getConnectorBenefits } from "../connector-benefits";
|
import { getConnectorBenefits } from "../connector-benefits";
|
||||||
import type { ConnectFormProps } from "../index";
|
import type { ConnectFormProps } from "../index";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
|
|
||||||
const PLUGIN_RELEASES_URL =
|
const PLUGIN_RELEASES_URL =
|
||||||
"https://github.com/MODSetter/SurfSense/releases?q=obsidian&expanded=true";
|
"https://github.com/MODSetter/SurfSense/releases?q=obsidian&expanded=true";
|
||||||
|
|
||||||
const BACKEND_URL = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL ?? "https://surfsense.com";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obsidian connect form for the plugin-only architecture.
|
* Obsidian connect form for the plugin-only architecture.
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { authenticatedFetch } from "@/lib/auth-utils";
|
import { authenticatedFetch } from "@/lib/auth-utils";
|
||||||
import type { ConnectorConfigProps } from "../index";
|
import type { ConnectorConfigProps } from "../index";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
export interface CirclebackConfigProps extends ConnectorConfigProps {
|
export interface CirclebackConfigProps extends ConnectorConfigProps {
|
||||||
onNameChange?: (name: string) => void;
|
onNameChange?: (name: string) => void;
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +42,7 @@ export const CirclebackConfig: FC<CirclebackConfigProps> = ({ connector, onNameC
|
||||||
const doFetch = async () => {
|
const doFetch = async () => {
|
||||||
if (!connector.search_space_id) return;
|
if (!connector.search_space_id) return;
|
||||||
|
|
||||||
const baseUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL;
|
const baseUrl = BACKEND_URL;
|
||||||
if (!baseUrl) {
|
if (!baseUrl) {
|
||||||
console.error("NEXT_PUBLIC_FASTAPI_BACKEND_URL is not configured");
|
console.error("NEXT_PUBLIC_FASTAPI_BACKEND_URL is not configured");
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import { getReauthEndpoint, LIVE_CONNECTOR_TYPES } from "../../constants/connect
|
||||||
import { getConnectorDisplayName } from "../../tabs/all-connectors-tab";
|
import { getConnectorDisplayName } from "../../tabs/all-connectors-tab";
|
||||||
import { MCPServiceConfig } from "../components/mcp-service-config";
|
import { MCPServiceConfig } from "../components/mcp-service-config";
|
||||||
import { getConnectorConfigComponent } from "../index";
|
import { getConnectorConfigComponent } from "../index";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
const VISION_LLM_CONNECTOR_TYPES = new Set<SearchSourceConnector["connector_type"]>([
|
const VISION_LLM_CONNECTOR_TYPES = new Set<SearchSourceConnector["connector_type"]>([
|
||||||
EnumConnectorName.GOOGLE_DRIVE_CONNECTOR,
|
EnumConnectorName.GOOGLE_DRIVE_CONNECTOR,
|
||||||
EnumConnectorName.COMPOSIO_GOOGLE_DRIVE_CONNECTOR,
|
EnumConnectorName.COMPOSIO_GOOGLE_DRIVE_CONNECTOR,
|
||||||
|
|
@ -93,7 +93,7 @@ export const ConnectorEditView: FC<ConnectorEditViewProps> = ({
|
||||||
if (!spaceId || !reauthEndpoint) return;
|
if (!spaceId || !reauthEndpoint) return;
|
||||||
setReauthing(true);
|
setReauthing(true);
|
||||||
try {
|
try {
|
||||||
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";
|
const backendUrl = BACKEND_URL;
|
||||||
const url = new URL(`${backendUrl}${reauthEndpoint}`);
|
const url = new URL(`${backendUrl}${reauthEndpoint}`);
|
||||||
url.searchParams.set("connector_id", String(connector.id));
|
url.searchParams.set("connector_id", String(connector.id));
|
||||||
url.searchParams.set("space_id", String(spaceId));
|
url.searchParams.set("space_id", String(spaceId));
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ import {
|
||||||
parseOAuthAuthResponse,
|
parseOAuthAuthResponse,
|
||||||
validateIndexingConfigState,
|
validateIndexingConfigState,
|
||||||
} from "../constants/connector-popup.schemas";
|
} from "../constants/connector-popup.schemas";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
const OAUTH_RESULT_COOKIE = "connector_oauth_result";
|
const OAUTH_RESULT_COOKIE = "connector_oauth_result";
|
||||||
|
|
||||||
function readOAuthResultCookie(): string | null {
|
function readOAuthResultCookie(): string | null {
|
||||||
|
|
@ -364,7 +364,7 @@ export const useConnectorDialog = () => {
|
||||||
try {
|
try {
|
||||||
// Check if authEndpoint already has query parameters
|
// Check if authEndpoint already has query parameters
|
||||||
const separator = connector.authEndpoint.includes("?") ? "&" : "?";
|
const separator = connector.authEndpoint.includes("?") ? "&" : "?";
|
||||||
const url = `${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}${connector.authEndpoint}${separator}space_id=${searchSpaceId}`;
|
const url = `${BACKEND_URL}${connector.authEndpoint}${separator}space_id=${searchSpaceId}`;
|
||||||
|
|
||||||
const response = await authenticatedFetch(url, { method: "GET" });
|
const response = await authenticatedFetch(url, { method: "GET" });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import { cn } from "@/lib/utils";
|
||||||
import { getReauthEndpoint, LIVE_CONNECTOR_TYPES } from "../constants/connector-constants";
|
import { getReauthEndpoint, LIVE_CONNECTOR_TYPES } from "../constants/connector-constants";
|
||||||
import { useConnectorStatus } from "../hooks/use-connector-status";
|
import { useConnectorStatus } from "../hooks/use-connector-status";
|
||||||
import { getConnectorDisplayName } from "../tabs/all-connectors-tab";
|
import { getConnectorDisplayName } from "../tabs/all-connectors-tab";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
interface ConnectorAccountsListViewProps {
|
interface ConnectorAccountsListViewProps {
|
||||||
connectorType: string;
|
connectorType: string;
|
||||||
connectorTitle: string;
|
connectorTitle: string;
|
||||||
|
|
@ -55,7 +55,7 @@ export const ConnectorAccountsListView: FC<ConnectorAccountsListViewProps> = ({
|
||||||
if (!searchSpaceId || !endpoint) return;
|
if (!searchSpaceId || !endpoint) return;
|
||||||
setReauthingId(connector.id);
|
setReauthingId(connector.id);
|
||||||
try {
|
try {
|
||||||
const backendUrl = process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL || "http://localhost:8000";
|
const backendUrl = BACKEND_URL;
|
||||||
const url = new URL(`${backendUrl}${endpoint}`);
|
const url = new URL(`${backendUrl}${endpoint}`);
|
||||||
url.searchParams.set("connector_id", String(connector.id));
|
url.searchParams.set("connector_id", String(connector.id));
|
||||||
url.searchParams.set("space_id", String(searchSpaceId));
|
url.searchParams.set("space_id", String(searchSpaceId));
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { authenticatedFetch } from "@/lib/auth-utils";
|
import { authenticatedFetch } from "@/lib/auth-utils";
|
||||||
|
import { BACKEND_URL } from "@/lib/env-config";
|
||||||
export interface SearchSourceConnector {
|
export interface SearchSourceConnector {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -108,7 +108,7 @@ export const useSearchSourceConnectors = (lazy: boolean = false, searchSpaceId?:
|
||||||
|
|
||||||
// Build URL with optional search_space_id query parameter
|
// Build URL with optional search_space_id query parameter
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-source-connectors`
|
`${BACKEND_URL}/api/v1/search-source-connectors`
|
||||||
);
|
);
|
||||||
if (spaceId !== undefined) {
|
if (spaceId !== undefined) {
|
||||||
url.searchParams.append("search_space_id", spaceId.toString());
|
url.searchParams.append("search_space_id", spaceId.toString());
|
||||||
|
|
@ -170,7 +170,7 @@ export const useSearchSourceConnectors = (lazy: boolean = false, searchSpaceId?:
|
||||||
try {
|
try {
|
||||||
// Add search_space_id as a query parameter
|
// Add search_space_id as a query parameter
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-source-connectors`
|
`${BACKEND_URL}/api/v1/search-source-connectors`
|
||||||
);
|
);
|
||||||
url.searchParams.append("search_space_id", spaceId.toString());
|
url.searchParams.append("search_space_id", spaceId.toString());
|
||||||
|
|
||||||
|
|
@ -208,7 +208,7 @@ export const useSearchSourceConnectors = (lazy: boolean = false, searchSpaceId?:
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-source-connectors/${connectorId}`,
|
`${BACKEND_URL}/api/v1/search-source-connectors/${connectorId}`,
|
||||||
{
|
{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
@ -239,7 +239,7 @@ export const useSearchSourceConnectors = (lazy: boolean = false, searchSpaceId?:
|
||||||
const deleteConnector = async (connectorId: number) => {
|
const deleteConnector = async (connectorId: number) => {
|
||||||
try {
|
try {
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/search-source-connectors/${connectorId}`,
|
`${BACKEND_URL}/api/v1/search-source-connectors/${connectorId}`,
|
||||||
{
|
{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
|
|
@ -284,7 +284,7 @@ export const useSearchSourceConnectors = (lazy: boolean = false, searchSpaceId?:
|
||||||
|
|
||||||
const response = await authenticatedFetch(
|
const response = await authenticatedFetch(
|
||||||
`${
|
`${
|
||||||
process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL
|
BACKEND_URL
|
||||||
}/api/v1/search-source-connectors/${connectorId}/index?${params.toString()}`,
|
}/api/v1/search-source-connectors/${connectorId}/index?${params.toString()}`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue