Files
ragflow/web/src/components/new-document-link.tsx
Yongteng Lei 3d10e2075c Refa: files /file API to RESTFul style (#13741)
### What problem does this PR solve?

Files /file API to RESTFul style.

### Type of change

- [x] Documentation Update
- [x] Refactoring

---------

Co-authored-by: writinwaters <cai.keith@gmail.com>
Co-authored-by: Liu An <asiro@qq.com>
2026-03-24 19:24:41 +08:00

52 lines
1.1 KiB
TypeScript

import {
getExtension,
isSupportedPreviewDocumentType,
} from '@/utils/document-util';
import React from 'react';
interface IProps extends React.PropsWithChildren {
link?: string;
preventDefault?: boolean;
color?: string;
documentName: string;
documentId?: string;
resource?: 'document' | 'files';
className?: string;
}
const NewDocumentLink = ({
children,
link,
preventDefault = false,
color = 'rgb(15, 79, 170)',
documentId,
documentName,
resource = 'document',
className,
}: IProps) => {
let nextLink = link;
const extension = getExtension(documentName);
if (!link) {
nextLink = `/document/${documentId}?ext=${extension}&resource=${resource}`;
}
return (
<a
target="_blank"
onClick={
!preventDefault || isSupportedPreviewDocumentType(extension)
? undefined
: (e) => e.preventDefault()
}
href={nextLink}
rel="noreferrer"
style={{ color: className ? '' : color, wordBreak: 'break-all' }}
className={className}
>
{children}
</a>
);
};
export default NewDocumentLink;