From ee21bd45f320a284ac93b4673435a1beea932961 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 14 Jan 2025 12:18:51 +0100 Subject: [PATCH] Got rid of unused endpoint and function --- front/lib/swr/data_source_view_tables.ts | 46 ------ .../data_sources/[dsId]/tables/index.ts | 134 ------------------ 2 files changed, 180 deletions(-) delete mode 100644 front/pages/api/w/[wId]/spaces/[spaceId]/data_sources/[dsId]/tables/index.ts diff --git a/front/lib/swr/data_source_view_tables.ts b/front/lib/swr/data_source_view_tables.ts index 1f6f857d1c87d..c65435992d60e 100644 --- a/front/lib/swr/data_source_view_tables.ts +++ b/front/lib/swr/data_source_view_tables.ts @@ -133,49 +133,3 @@ export function useUpdateDataSourceViewTable( return doUpdate; } - -export function useCreateDataSourceTable( - owner: LightWorkspaceType, - dataSourceView: DataSourceViewType -) { - const { mutateRegardlessOfQueryParams: mutateContentNodes } = - useDataSourceViewContentNodes({ - owner, - dataSourceView, - disabled: true, // Needed just to mutate - }); - const sendNotification = useSendNotification(); - - const doCreate = async (body: PostDataSourceTableRequestBody) => { - const tableUrl = `/api/w/${owner.sId}/spaces/${dataSourceView.spaceId}/data_sources/${dataSourceView.dataSource.sId}/tables`; - const res = await fetch(tableUrl, { - method: "POST", - body: JSON.stringify(body), - headers: { - "Content-Type": "application/json", - }, - }); - if (!res.ok) { - const errorData = await getErrorFromResponse(res); - sendNotification({ - type: "error", - title: "Error creating table", - description: `Error: ${errorData.message}`, - }); - return null; - } else { - void mutateContentNodes(); - - sendNotification({ - type: "success", - title: "Table created", - description: "Table has been created", - }); - - const response: PostTableResponseBody = await res.json(); - return response.table; - } - }; - - return doCreate; -} diff --git a/front/pages/api/w/[wId]/spaces/[spaceId]/data_sources/[dsId]/tables/index.ts b/front/pages/api/w/[wId]/spaces/[spaceId]/data_sources/[dsId]/tables/index.ts deleted file mode 100644 index 08bba7a8e192e..0000000000000 --- a/front/pages/api/w/[wId]/spaces/[spaceId]/data_sources/[dsId]/tables/index.ts +++ /dev/null @@ -1,134 +0,0 @@ -import type { CoreAPITable, WithAPIErrorResponse } from "@dust-tt/types"; -import { PostDataSourceTableRequestBodySchema } from "@dust-tt/types"; -import { isLeft } from "fp-ts/lib/Either"; -import * as reporter from "io-ts-reporters"; -import type { NextApiRequest, NextApiResponse } from "next"; - -import { withSessionAuthenticationForWorkspace } from "@app/lib/api/auth_wrappers"; -import { upsertTable } from "@app/lib/api/data_sources"; -import { withResourceFetchingFromRoute } from "@app/lib/api/resource_wrappers"; -import type { Authenticator } from "@app/lib/auth"; -import { DataSourceResource } from "@app/lib/resources/data_source_resource"; -import type { SpaceResource } from "@app/lib/resources/space_resource"; -import { generateRandomModelSId } from "@app/lib/resources/string_ids"; -import { apiError } from "@app/logger/withlogging"; - -export const config = { - api: { - bodyParser: { - sizeLimit: "50mb", - }, - }, -}; - -export type PostTableResponseBody = { - table?: CoreAPITable; -}; - -async function handler( - req: NextApiRequest, - res: NextApiResponse>, - auth: Authenticator, - { space }: { space: SpaceResource } -): Promise { - const { dsId } = req.query; - if (typeof dsId !== "string") { - return apiError(req, res, { - status_code: 400, - api_error: { - type: "invalid_request_error", - message: "Invalid path parameters.", - }, - }); - } - - const dataSource = await DataSourceResource.fetchByNameOrId(auth, dsId); - if ( - !dataSource || - !dataSource.canRead(auth) || - dataSource.space.sId !== space.sId - ) { - return apiError(req, res, { - status_code: 404, - api_error: { - type: "data_source_not_found", - message: "The data source you requested was not found.", - }, - }); - } - - switch (req.method) { - case "POST": - if (!dataSource.canWrite(auth)) { - return apiError(req, res, { - status_code: 403, - api_error: { - type: "data_source_auth_error", - message: "You are not allowed to update data in this data source.", - }, - }); - } - - if (dataSource.connectorId) { - return apiError(req, res, { - status_code: 403, - api_error: { - type: "data_source_auth_error", - message: "You cannot upsert a document on a managed data source.", - }, - }); - } - - const bodyValidation = PostDataSourceTableRequestBodySchema.decode( - req.body - ); - - if (isLeft(bodyValidation)) { - const pathError = reporter.formatValidationErrors(bodyValidation.left); - return apiError(req, res, { - status_code: 400, - api_error: { - type: "invalid_request_error", - message: `Invalid request body: ${pathError}`, - }, - }); - } - - const tableId = generateRandomModelSId(); - const upsertRes = await upsertTable({ - ...bodyValidation.right, - async: bodyValidation.right.async ?? false, - dataSource, - auth, - tableId, - }); - - if (upsertRes.isErr()) { - return apiError(req, res, { - status_code: 500, - api_error: { - type: "internal_server_error", - message: "There was an error upserting the document.", - }, - }); - } - - res.status(201).json({ - table: upsertRes.value?.table, - }); - return; - default: - return apiError(req, res, { - status_code: 405, - api_error: { - type: "method_not_supported_error", - message: - "The method passed is not supported, GET, POST or DELETE is expected.", - }, - }); - } -} - -export default withSessionAuthenticationForWorkspace( - withResourceFetchingFromRoute(handler, { space: { requireCanWrite: true } }) -);