forked from langflow-ai/langflow
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add new use-query endpoint of upload files (langflow-ai#2533)
* refactor: add new use-query endpoint of upload files * extend type for payload callbackSuccess * [autofix.ci] apply automated fixes * bugfix: drag and drop image on chat not working * Refactored query function to use Options * Used dedicated function as queryFn * ✨ (API): export use-post-upload-file in files index ♻️ (FileInput): refactor file upload mutation to use onSuccess and onError ♻️ (chatInput): refactor file upload mutation to use onSuccess and onError ♻️ (chatView): refactor file upload mutation to use onSuccess and onError * ♻️ (use-get-download-images.ts): simplify getDownloadImagesFn function ♻️ (use-get-transactions.ts): simplify getTransactionsFn function ✨ (use-handle-file-change.tsx): add hook to handle file input changes ✨ (use-upload.tsx): add hook to handle file paste events * Added type on Request Processor --------- Co-authored-by: anovazzi1 <otavio2204@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Lucas Oliveira <lucas.edu.oli@hotmail.com> (cherry picked from commit bfaac8b)
- Loading branch information
1 parent
f57fa54
commit 7f97c3d
Showing
20 changed files
with
362 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./use-get-download-images"; | ||
export * from "./use-get-profile-pictures"; | ||
export * from "./use-post-upload-file"; |
38 changes: 38 additions & 0 deletions
38
src/frontend/src/controllers/API/queries/files/use-get-download-images.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { keepPreviousData } from "@tanstack/react-query"; | ||
import { useQueryFunctionType } from "../../../../types/api"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
interface DownloadImagesQueryParams { | ||
flowId: string; | ||
fileName: string; | ||
} | ||
|
||
export interface DownloadImagesResponse { | ||
response: string; | ||
} | ||
|
||
export const useGetDownloadImagesQuery: useQueryFunctionType< | ||
DownloadImagesQueryParams, | ||
DownloadImagesResponse | ||
> = ({ flowId, fileName }) => { | ||
const { query } = UseRequestProcessor(); | ||
|
||
const getDownloadImagesFn = async () => { | ||
const response = await api.get<DownloadImagesResponse>( | ||
`${getURL("FILES")}/images/${flowId}/${fileName}`, | ||
); | ||
return response["data"]; | ||
}; | ||
|
||
const queryResult = query( | ||
["useGetDownloadImagesQuery"], | ||
getDownloadImagesFn, | ||
{ | ||
placeholderData: keepPreviousData, | ||
}, | ||
); | ||
|
||
return queryResult; | ||
}; |
36 changes: 36 additions & 0 deletions
36
src/frontend/src/controllers/API/queries/files/use-get-profile-pictures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { keepPreviousData } from "@tanstack/react-query"; | ||
import { useQueryFunctionType } from "../../../../types/api"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
interface ProfilePicturesQueryParams {} | ||
|
||
export interface ProfilePicturesResponse { | ||
files: string[]; | ||
} | ||
|
||
export const useGetProfilePicturesQuery: useQueryFunctionType< | ||
ProfilePicturesQueryParams, | ||
ProfilePicturesResponse | ||
> = () => { | ||
const { query } = UseRequestProcessor(); | ||
|
||
const getProfilePicturesFn = async () => { | ||
const response = await api.get<ProfilePicturesResponse>( | ||
`${getURL("FILES")}/profile_pictures/list`, | ||
); | ||
|
||
return response.data; | ||
}; | ||
|
||
const queryResult = query( | ||
["useGetProfilePicturesQuery"], | ||
getProfilePicturesFn, | ||
{ | ||
placeholderData: keepPreviousData, | ||
}, | ||
); | ||
|
||
return queryResult; | ||
}; |
40 changes: 40 additions & 0 deletions
40
src/frontend/src/controllers/API/queries/files/use-post-upload-file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useMutationFunctionType } from "@/types/api"; | ||
import { UseMutationResult } from "@tanstack/react-query"; | ||
import { api } from "../../api"; | ||
import { getURL } from "../../helpers/constants"; | ||
import { UseRequestProcessor } from "../../services/request-processor"; | ||
|
||
interface IPostUploadFile { | ||
file: File; | ||
id: string; | ||
} | ||
|
||
export const usePostUploadFile: useMutationFunctionType<IPostUploadFile> = ( | ||
options?, | ||
) => { | ||
const { mutate } = UseRequestProcessor(); | ||
|
||
const postUploadFileFn = async (payload: IPostUploadFile): Promise<any> => { | ||
const formData = new FormData(); | ||
formData.append("file", payload.file); | ||
|
||
const response = await api.post<any>( | ||
`${getURL("FILES")}/upload/${payload.id}`, | ||
formData, | ||
); | ||
|
||
return response.data; | ||
}; | ||
|
||
const mutation: UseMutationResult<IPostUploadFile, any, IPostUploadFile> = | ||
mutate( | ||
["usePostUploadFile"], | ||
async (payload: IPostUploadFile) => { | ||
const res = await postUploadFileFn(payload); | ||
return res; | ||
}, | ||
options, | ||
); | ||
|
||
return mutation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.