frontend: download icon button to force download
Massimo Melina committed
Mar 13, 2023 at 10:43 UTC
2ed2506e49411120c1681db6b11e7a297801ebed
3 files changed
+10
-6
frontend/src/BrowseFiles.ts
+3
-2
@@ -201,8 +201,9 @@ const Entry = memo((entry: DirEntry & { midnight: Date, separator?: string }) =>
201
}),
202
isFolder ? h(Link, { to: base+href }, hIcon('folder'), relativePath.slice(0,-1))
203
: h(Fragment, {},
204
- containerDir && h(Link, { to: base+fixUrl(containerDir), className:'container-folder' }, hIcon('file'), containerDir ),
205
- h('a', { href }, !containerDir && hIcon('file'), name)
204
+ h('a', { href: href + '?dl' }, hIcon('download')),
205
+ containerDir && h(Link, { to: base + fixUrl(containerDir), className:'container-folder' }, containerDir),
206
+ h('a', { href }, name)
207
),
208
h(CustomCode, { name: 'afterEntryName', props: { entry } }),
209
h(EntryProps, entry),
frontend/src/index.scss
+5
-4
@@ -211,13 +211,14 @@ ul.dir {
211
margin: 0 .8em;
212
}
213
& a {
214
- word-break: break-word;
215
- padding-right: 0.3em;
216
-
214
+ &:last-of-type {
215
+ word-break: break-word;
216
+ padding-right: 0.3em;
217
+ }
218
& .icon {
219
margin-right: .3em;
220
}
220
- &.container-folder:hover {
221
+ &:hover {
222
text-decoration: underline;
223
}
224
}
src/serveFile.ts
+2
@@ -52,6 +52,8 @@ export function serveFile(source:string, mime?:string, content?: string | Buffer
52
if (!source)
53
return
54
const fn = path.basename(source)
55
+ if (ctx.params.dl !== undefined) // please, download
56
+ ctx.attachment(fn)
57
mime = mime ?? _.find(mimeCfg.get(), (v,k) => k>'' && isMatch(fn, k)) // isMatch throws on an empty string
58
if (mime === MIME_AUTO)
59
mime = mimetypes.lookup(source) || ''