diff --git a/products/ASC.Files/Client/package.json b/products/ASC.Files/Client/package.json index c43d6b7c38..ebb844fd7f 100644 --- a/products/ASC.Files/Client/package.json +++ b/products/ASC.Files/Client/package.json @@ -15,7 +15,8 @@ "extends @appserver/browserslist-config-asc" ], "dependencies": { - "copy-to-clipboard": "^3.3.1" + "copy-to-clipboard": "^3.3.1", + "file-saver": "^2.0.5" }, "devDependencies": { "@babel/core": "^7.15.5", diff --git a/products/ASC.Files/Client/src/HOCs/withContextOptions.js b/products/ASC.Files/Client/src/HOCs/withContextOptions.js index bd83bbfdd2..4e00478559 100644 --- a/products/ASC.Files/Client/src/HOCs/withContextOptions.js +++ b/products/ASC.Files/Client/src/HOCs/withContextOptions.js @@ -5,6 +5,7 @@ import { combineUrl } from "@appserver/common/utils"; import { FileAction, AppServerConfig } from "@appserver/common/constants"; import toastr from "@appserver/components/toast/toastr"; import config from "../../package.json"; +import saveAs from "file-saver"; export default function withContextOptions(WrappedComponent) { class WithContextOptions extends React.Component { @@ -147,10 +148,36 @@ export default function withContextOptions(WrappedComponent) { openDocEditor(id, providerKey, tab, urlFormation); }; + + isPwa = () => { + return ["fullscreen", "standalone", "minimal-ui"].some( + (displayMode) => + window.matchMedia("(display-mode: " + displayMode + ")").matches + ); + }; + onClickDownload = () => { const { item, downloadAction, t } = this.props; const { fileExst, contentLength, viewUrl } = item; const isFile = !!fileExst && contentLength; + + if (this.isPwa()) { + const xhr = new XMLHttpRequest(); + xhr.open("GET", viewUrl); + xhr.responseType = "blob"; + + xhr.onload = () => { + saveAs(xhr.response, item.title); + }; + + xhr.onerror = () => { + console.error("download failed", viewUrl); + }; + + xhr.send(); + return; + } + isFile ? window.open(viewUrl, "_self") : downloadAction(t("Translations:ArchivingData")).catch((err) => diff --git a/yarn.lock b/yarn.lock index 40cb62b341..c312616fce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8899,6 +8899,11 @@ file-loader@^6.2.0: loader-utils "^2.0.0" schema-utils "^3.0.0" +file-saver@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38" + integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA== + file-selector@^0.2.2: version "0.2.4" resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-0.2.4.tgz#7b98286f9dbb9925f420130ea5ed0a69238d4d80"