import { Alert, Box, DialogContent, FormControlLabel, IconButton, Link, Skeleton, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography, } from "@mui/material"; import { useCallback, useEffect, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { getFileInfo, sendDeleteDirectLink } from "../../../api/api.ts"; import { DirectLink, FileResponse } from "../../../api/explorer.ts"; import { closeDirectLinkManagementDialog } from "../../../redux/globalStateSlice.ts"; import { useAppDispatch, useAppSelector } from "../../../redux/hooks.ts"; import { confirmOperation } from "../../../redux/thunks/dialog.ts"; import { copyToClipboard } from "../../../util/index.ts"; import AutoHeight from "../../Common/AutoHeight.tsx"; import { NoWrapTableCell, StyledCheckbox, StyledTableContainerPaper } from "../../Common/StyledComponents.tsx"; import TimeBadge from "../../Common/TimeBadge.tsx"; import DraggableDialog from "../../Dialogs/DraggableDialog.tsx"; import CopyOutlined from "../../Icons/CopyOutlined.tsx"; import DeleteOutlined from "../../Icons/DeleteOutlined.tsx"; const DirectLinksControl = () => { const { t } = useTranslation(); const dispatch = useAppDispatch(); const [fileExtended, setFileExtended] = useState(undefined); const [loading, setLoading] = useState(false); const [forceDownload, setForceDownload] = useState(false); const open = useAppSelector((state) => state.globalState.directLinkManagementDialogOpen); const target = useAppSelector((state) => state.globalState.directLinkManagementDialogFile); const highlight = useAppSelector((state) => state.globalState.directLinkHighlight); const hilightButNotFound = useMemo(() => { return ( highlight && fileExtended?.extended_info && !fileExtended?.extended_info?.direct_links?.some((link) => link.id == highlight) ); }, [highlight, fileExtended?.extended_info?.direct_links]); const onClose = useCallback(() => { if (!loading) { dispatch(closeDirectLinkManagementDialog()); } }, [dispatch, loading]); useEffect(() => { if (target && open) { setFileExtended(undefined); dispatch( getFileInfo({ uri: target.path, extended: true, }), ).then((res) => setFileExtended(res)); } }, [target, open]); const directLinks = useMemo(() => { return fileExtended?.extended_info?.direct_links?.map((link) => { return { ...link, url: forceDownload ? link.url.replace("/f/", "/f/d/") : link.url, }; }); }, [fileExtended?.extended_info?.direct_links, forceDownload]); const handleRowClick = useCallback((directLink: DirectLink) => { window.open(directLink.url, "_blank"); }, []); const copyURL = useCallback((actionTarget: DirectLink) => { if (!actionTarget) { return; } copyToClipboard(actionTarget.url); }, []); const deleteDirectLink = useCallback( (actionTarget: DirectLink) => { if (!target || !actionTarget) { return; } dispatch(confirmOperation(t("fileManager.deleteLinkConfirm"))).then(() => { setLoading(true); dispatch(sendDeleteDirectLink(actionTarget.id)) .then(() => { setFileExtended((prev) => prev ? { ...prev, extended_info: prev.extended_info ? { ...prev.extended_info, direct_links: prev.extended_info.direct_links?.filter((link) => link.id !== actionTarget.id), } : undefined, } : undefined, ); }) .finally(() => { setLoading(false); }); }); }, [t, target, dispatch], ); return ( {hilightButNotFound && ( {t("application:fileManager.directLinkNotFound")} )} {t("fileManager.actions")} {t("modals.sourceLink")} {t("setting.viewNumber")} {t("fileManager.createdAt")} {!fileExtended && ( )} {directLinks && directLinks.map((link) => ( highlight == link.id ? `inset 0 0 0 2px ${theme.palette.primary.light}` : "none", "&:last-child td, &:last-child th": { border: 0 }, }} > copyURL(link)} size={"small"}> deleteDirectLink(link)} size={"small"}> event.stopPropagation()} > {link.url} {link.downloaded} ))}
{!directLinks && fileExtended && ( {t("application:setting.listEmpty")} )}
{ setForceDownload(!forceDownload); }} disableRipple checked={forceDownload} size="small" /> } label={t("application:modals.forceDownload")} />
); }; export default DirectLinksControl;