1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-10 03:11:07 +00:00

add-download-url (#6771)

* add-download-url

* update unitest

* update

* update

* update

* update

* Update test_view_lib_file.py

* code-optimize

* Update shared-dir-view.js

* code-optimize
This commit is contained in:
Ranjiwei
2024-09-19 11:12:10 +08:00
committed by GitHub
parent a5d8ef3fe2
commit 86770c47f9
22 changed files with 82 additions and 48 deletions

View File

@@ -17,7 +17,7 @@ const propTypes = {
class ImageDialog extends React.Component {
downloadImage = (imageSrc) => {
let downloadUrl = imageSrc.indexOf('?dl=1') > -1 ? imageSrc : imageSrc + '?dl=1';
let downloadUrl = imageSrc;
if (document.getElementById('downloadFrame')) {
document.body.removeChild(document.getElementById('downloadFrame'));
@@ -72,7 +72,7 @@ class ImageDialog extends React.Component {
zoomInLabel={gettext('Zoom in')}
zoomOutLabel={gettext('Zoom out')}
enableRotate={true}
onClickDownload={() => this.downloadImage(imageItems[imageIndex].url)}
onClickDownload={() => this.downloadImage(imageItems[imageIndex].downloadURL)}
onClickDelete={this.props.onDeleteImage ? () => this.props.onDeleteImage(imageItems[imageIndex].name) : null}
onViewOriginal={this.onViewOriginal}
viewOriginalImageLabel={gettext('View original image')}

View File

@@ -9,7 +9,7 @@ import Move from '../../components/dialog/move-dirent-dialog';
import CreateFolder from '../../components/dialog/create-folder-dialog';
import CreateFile from '../../components/dialog/create-file-dialog';
import ImageDialog from '../../components/dialog/image-dialog';
import { gettext, siteRoot, thumbnailSizeForOriginal } from '../../utils/constants';
import { fileServerRoot, gettext, siteRoot, thumbnailSizeForOriginal } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import TextTranslation from '../../utils/text-translation';
import TreeSection from '../../components/tree-section';
@@ -269,6 +269,7 @@ class DirColumnNav extends React.Component {
'src': src,
'thumbnail': `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}`,
'node': items.find(item => item.path.split('/').pop() === name),
'downloadURL': `${fileServerRoot}repos/${repoID}/files/?op=download&p=${path}`,
};
};

View File

@@ -1,6 +1,6 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { siteRoot, username, enableSeadoc, thumbnailDefaultSize, thumbnailSizeForOriginal, gettext } from '../../utils/constants';
import { siteRoot, username, enableSeadoc, thumbnailDefaultSize, thumbnailSizeForOriginal, gettext, fileServerRoot } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import { seafileAPI } from '../../utils/seafile-api';
import URLDecorator from '../../utils/url-decorator';
@@ -591,6 +591,7 @@ class DirentGridView extends React.Component {
'url': `${siteRoot}lib/${repoID}/file${path}`,
'thumbnail': `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}`,
'src': `${siteRoot}repo/${repoID}/raw${path}?t=${cacheBuster}`,
'downloadURL': `${fileServerRoot}repos/${repoID}/files/?op=download&p=${path}`,
};
};

View File

@@ -1,6 +1,6 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { siteRoot, gettext, username, enableSeadoc, thumbnailSizeForOriginal } from '../../utils/constants';
import { siteRoot, gettext, username, enableSeadoc, thumbnailSizeForOriginal, fileServerRoot } from '../../utils/constants';
import { Utils } from '../../utils/utils';
import TextTranslation from '../../utils/text-translation';
import URLDecorator from '../../utils/url-decorator';
@@ -189,6 +189,7 @@ class DirentListView extends React.Component {
'url': `${siteRoot}lib/${repoID}/file${path}`,
'thumbnail': `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}`,
'src': `${siteRoot}repo/${repoID}/raw${path}`,
'downloadURL': `${fileServerRoot}repos/${repoID}/files/?op=download&p=${path}`,
};
};

View File

@@ -1,10 +1,10 @@
import React from 'react';
import VideoPlayer from '../video-player';
import { MimetypesKind } from '../../utils/constants';
import '../../css/video-file-view.css';
const {
rawPath
rawPath, fileExt
} = window.app.pageOptions;
class FileContent extends React.Component {
@@ -15,7 +15,8 @@ class FileContent extends React.Component {
preload: 'auto',
playbackRates: [0.5, 1, 1.5, 2],
sources: [{
src: rawPath
src: rawPath,
type: MimetypesKind[fileExt] || 'video/mp4'
}]
};
return (

View File

@@ -28,6 +28,7 @@ const {
canEditFile, err,
// fileEnc, // for 'edit', not undefined only for some kinds of files (e.g. text file)
canDownloadFile,
fileDownloadURL,
} = window.app.pageOptions;
class FileToolbar extends React.Component {
@@ -162,7 +163,7 @@ class FileToolbar extends React.Component {
id="download-file"
icon="download"
text={gettext('Download')}
href="?dl=1"
href={fileDownloadURL}
/>
)}
<IconButton

View File

@@ -19,7 +19,7 @@ const propTypes = {
let loginUser = window.app.pageOptions.name;
let contactEmail = window.app.pageOptions.contactEmail;
const { sharedToken, trafficOverLimit, fileName, fileSize, sharedBy, siteName, enableWatermark, canDownload,
zipped, filePath, enableShareLinkReportAbuse } = window.shared.pageOptions;
zipped, filePath, enableShareLinkReportAbuse, sharedFileDownloadURL } = window.shared.pageOptions;
class SharedFileView extends React.Component {
@@ -129,7 +129,8 @@ class SharedFileView extends React.Component {
</Button>
}{' '}
{(canDownload && !trafficOverLimit) &&
<a href={`?${zipped ? 'p=' + encodeURIComponent(filePath) + '&' : ''}dl=1`} className="btn btn-success">{gettext('Download')} ({Utils.bytesToSize(fileSize)})</a>
<a href={`${zipped ? '?p=' + encodeURIComponent(filePath) + '&dl=1' : sharedFileDownloadURL}`} className="btn btn-success">{gettext('Download')} ({Utils.bytesToSize(fileSize)})</a>
}{' '}
{(enableShareLinkReportAbuse && (loginUser !== sharedBy)) &&
<Button