mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 15:06:19 -05:00
Linking to /download for files that should be downloaded.
This commit is contained in:
parent
a5856309ed
commit
336f732633
4 changed files with 46 additions and 14 deletions
|
|
@ -147,13 +147,13 @@ export function Files() {
|
|||
|
||||
function EbookCard({file}) {
|
||||
const {s} = useContext(ThemeContext);
|
||||
const url = `/media/${encodeURIComponent(file.path)}`;
|
||||
const downloadUrl = `/download/${encodeURIComponent(file.path)}`;
|
||||
let {ebook, suffix} = file;
|
||||
const coverSrc = ebook && ebook.cover_path ? `/media/${encodeURIComponent(ebook.cover_path)}` : null;
|
||||
|
||||
let cover = <CardIcon><FileIcon file={file}/></CardIcon>;
|
||||
if (coverSrc) {
|
||||
cover = <CardPosterLink to={url} poster_url={coverSrc} external={true}/>;
|
||||
cover = <CardPosterLink to={downloadUrl} poster_url={coverSrc} external={true}/>;
|
||||
}
|
||||
|
||||
suffix = suffix ? _.trimStart(suffix, '.').toUpperCase() : null;
|
||||
|
|
@ -164,7 +164,7 @@ function EbookCard({file}) {
|
|||
<CardContent {...s}>
|
||||
<CardHeader>
|
||||
<Container textAlign='left'>
|
||||
<ExternalCardLink to={url}>{ebook ? ebook.title : file.title}</ExternalCardLink>
|
||||
<ExternalCardLink to={downloadUrl}>{ebook ? ebook.title : file.title}</ExternalCardLink>
|
||||
</Container>
|
||||
</CardHeader>
|
||||
<CardDescription>
|
||||
|
|
@ -217,21 +217,22 @@ function ImageCard({file}) {
|
|||
function FileCard({file}) {
|
||||
const {s} = useContext(ThemeContext);
|
||||
|
||||
const isEbookType = file.mimetype && (
|
||||
file.mimetype.startsWith('application/epub') || file.mimetype.startsWith('application/x-mobipocket-ebook')
|
||||
);
|
||||
|
||||
if (file.model === 'video' && file['video']) {
|
||||
return <VideoCard key={file['path']} file={file}/>;
|
||||
} else if (file.model === 'archive' && file['archive']) {
|
||||
return <ArchiveCard key={file['path']} file={file}/>;
|
||||
} else if (file.mimetype && file.mimetype.startsWith('image/')) {
|
||||
return <ImageCard key={file['path']} file={file}/>;
|
||||
} else if (file.mimetype && (
|
||||
file.mimetype.startsWith('application/epub') || file.mimetype.startsWith('application/x-mobipocket-ebook')
|
||||
)) {
|
||||
} else if (isEbookType) {
|
||||
return <EbookCard key={file['path']} file={file}/>;
|
||||
}
|
||||
|
||||
const url = `/media/${encodeURIComponent(file.path)}`;
|
||||
const url = `/download/${encodeURIComponent(file.path)}`;
|
||||
const color = mimetypeColor(file.mimetype);
|
||||
|
||||
const size = file.size !== null && file.size !== undefined ? humanFileSize(file.size) : null;
|
||||
|
||||
return <Card color={color}>
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
|
|||
}
|
||||
|
||||
let videoUrl = `${MEDIA_PATH}/${encodeURIComponent(video.video_path)}`;
|
||||
let downloadUrl = `/download/${encodeURIComponent(video.video_path)}`;
|
||||
|
||||
let posterUrl = video.poster_path ? `${MEDIA_PATH}/${encodeURIComponent(video.poster_path)}` : null;
|
||||
let captionsUrl = video.caption_path ? `${MEDIA_PATH}/${encodeURIComponent(video.caption_path)}` : null;
|
||||
|
|
@ -184,7 +185,7 @@ function VideoPage({videoFile, prevFile, nextFile, setFavorite, ...props}) {
|
|||
|
||||
<p>
|
||||
{favorite_button}
|
||||
<a href={videoUrl}>
|
||||
<a href={downloadUrl} target='_blank' rel='noopener noreferrer'>
|
||||
<Button style={{margin: '0.5em'}}>
|
||||
<Icon name='download'/>
|
||||
Download
|
||||
|
|
|
|||
23
nginx.conf
23
nginx.conf
|
|
@ -60,10 +60,6 @@ http {
|
|||
}
|
||||
|
||||
location /media {
|
||||
if ( $request_filename ~ '^.*/(.+)$' ) {
|
||||
add_header Content-Disposition 'attachment; filename="$1"';
|
||||
}
|
||||
|
||||
# The media files mounted in the docker volume
|
||||
sendfile on;
|
||||
sendfile_max_chunk 1m;
|
||||
|
|
@ -77,6 +73,25 @@ http {
|
|||
alias /media/wrolpi;
|
||||
}
|
||||
|
||||
location /download {
|
||||
# Assume any request here is to download a file from the media directory.
|
||||
if ( $request_filename ~ '^.*/(.+)$' ) {
|
||||
# Always include the filename for downloads.
|
||||
add_header Content-Disposition 'attachment; filename="$1"';
|
||||
}
|
||||
|
||||
sendfile on;
|
||||
sendfile_max_chunk 1m;
|
||||
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
|
||||
autoindex on;
|
||||
autoindex_exact_size off;
|
||||
alias /opt/media;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,11 +50,26 @@ http {
|
|||
}
|
||||
|
||||
location /media {
|
||||
# The media files mounted in the docker volume
|
||||
sendfile on;
|
||||
sendfile_max_chunk 1m;
|
||||
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
|
||||
autoindex on;
|
||||
autoindex_exact_size off;
|
||||
alias /opt/media;
|
||||
}
|
||||
|
||||
location /download {
|
||||
# Assume any request here is to download a file from the media directory.
|
||||
if ( $request_filename ~ '^.*/(.+)$' ) {
|
||||
# Always include the filename for downloads.
|
||||
add_header Content-Disposition 'attachment; filename="$1"';
|
||||
}
|
||||
|
||||
# The media files mounted in the docker volume
|
||||
sendfile on;
|
||||
sendfile_max_chunk 1m;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue