🌟 Fix download button (#210)

* Add auth cookie to avoid using auth token in the url
* Fix all download button 
* Refactor some of the places where we download file
This commit is contained in:
Anton Shepilov
2023-09-21 14:08:57 +02:00
committed by GitHub
parent 43a5dbddf1
commit d88feaaba8
14 changed files with 61 additions and 125 deletions
@@ -1,48 +1,8 @@
import Strings from 'features/global/utils/strings';
import FileUploadService from 'features/files/services/file-upload-service';
import routerService from '@features/router/services/router-service';
import { DriveApiClient } from '@features/drive/api-client/api-client';
import { DriveItem } from '@features/drive/types';
import { AttachedFileType } from '@features/files/types/file';
export const highlightText = (text?: string, highlight?: string) => {
if (!text) {
return '';
}
if (!highlight) {
return text;
}
const reg = new RegExp('(' + Strings.removeAccents(highlight) + ')', 'ig');
return Strings.removeAccents(text).replace(reg, "<span class='highlight'>$1</span>");
};
export const getFileMessageDownloadRoute = (file: AttachedFileType): string => {
if (file?.metadata?.source === 'internal')
return FileUploadService.getDownloadRoute({
companyId: file.metadata?.external_id?.company_id,
fileId: file.metadata?.external_id?.id,
});
return '';
};
export const onFileDownloadClick = (file: AttachedFileType) => {
const url = getFileMessageDownloadRoute(file);
url && (window.location.href = url);
};
export const openDriveItem = (driveItem: DriveItem, workspace_id: string, drive_app_id: string) => {
routerService.push(
routerService.generateRouteFromState({
companyId: driveItem.company_id,
workspaceId: workspace_id,
channelId: drive_app_id,
}),
);
};
export const onDriveItemDownloadClick = async (driveItem: DriveItem) => {
const url = await DriveApiClient.getDownloadUrl(driveItem.company_id, driveItem.id);
url && (window.location.href = url);
};
@@ -1,12 +1,12 @@
import { SearchIcon } from '@heroicons/react/solid';
import { useEffect, useRef } from 'react';
import { useRecoilState } from 'recoil';
import { InputDecorationIcon } from '@atoms/input/input-decoration-icon';
import { Input } from '@atoms/input/input-text';
import { Loader } from '@atoms/loader';
import Languages from '@features/global/services/languages-service';
import { useSearchDriveItemsLoading } from '@features/search/hooks/use-search-drive-items';
import { SearchInputState } from '@features/search/state/search-input';
import { SearchIcon } from "@heroicons/react/solid";
import { useEffect, useRef } from "react";
import { useRecoilState } from "recoil";
import { InputDecorationIcon } from "@atoms/input/input-decoration-icon";
import { Input } from "@atoms/input/input-text";
import { Loader } from "@atoms/loader";
import Languages from "@features/global/services/languages-service";
import { useSearchDriveItemsLoading } from "@features/search/hooks/use-search-drive-items";
import { SearchInputState } from "@features/search/state/search-input";
export const SearchInput = () => {
const [input, setInput] = useRecoilState(SearchInputState);
@@ -16,9 +16,7 @@ export const SearchInput = () => {
if (inputElement.current) inputElement.current.focus();
}, []);
const driveItemsLoading = useSearchDriveItemsLoading();
const loading = driveItemsLoading;
const loading = useSearchDriveItemsLoading();
return (
<div className="relative flex mt-2 w-full">