Skip to content

Commit

Permalink
Merge branch 'feat/custom-filename' of https://github.com/aaquibnaved…
Browse files Browse the repository at this point in the history
…/react-doc-viewer into aaquibnaved-feat/custom-filename
  • Loading branch information
cyntler committed Apr 15, 2022
2 parents 00ce4ea + 35b9fe1 commit 8494603
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/components/FileName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ export const FileName: FC<{}> = () => {

if (!currentDocument || config?.header?.disableFileName) return null;

let fileName = currentDocument.uri || "";
fileName = decodeURI(fileName);
let fileName = "";

if (!config?.header?.retainURLParams) {
fileName = fileName.split("?")[0];
}
if (currentDocument.fileName) {
fileName = currentDocument.fileName;
} else {
fileName = currentDocument.uri || "";
fileName = decodeURI(fileName);

if (!config?.header?.retainURLParams) {
fileName = fileName.split("?")[0];
}

const splitURL = fileName.split("/");
if (splitURL.length) {
fileName = splitURL[splitURL.length - 1];
const splitURL = fileName.split("/");
if (splitURL.length) {
fileName = splitURL[splitURL.length - 1];
}
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/pdf/components/PDFControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const PDFControls: FC<{}> = () => {
<DownloadButton
id="pdf-download"
href={currentDocument?.fileData as string}
download={currentDocument?.uri}
download={currentDocument?.fileName || currentDocument?.uri}
>
<DownloadPDFIcon color="#000" size="75%" />
</DownloadButton>
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface IDocument {
uri: string;
fileType?: string;
fileData?: string | ArrayBuffer;
fileName?: string;
}

export interface DocRendererProps {
Expand Down

0 comments on commit 8494603

Please sign in to comment.