Skip to content

Commit 0e80a59

Browse files
committed
Added preview for WhatsApp
1 parent 0ec822f commit 0e80a59

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

internal/webserver/Webserver.go

+27-4
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,34 @@ func redirect(w http.ResponseWriter, url string) {
196196
}
197197

198198
type redirectValues struct {
199-
FileId string
200-
RedirectUrl string
199+
FileId string
200+
RedirectUrl string
201+
Name string
202+
Size string
203+
PublicName string
204+
BaseUrl string
205+
PasswordRequired bool
201206
}
202207

203208
// Handling of /id/?/? - used when filename shall be displayed, will redirect to regular download URL
204209
func redirectFromFilename(w http.ResponseWriter, r *http.Request) {
210+
addNoCacheHeader(w)
205211
id := r.PathValue("id")
212+
file, ok := storage.GetFile(id)
213+
if !ok {
214+
redirect(w, "../../error")
215+
return
216+
}
217+
218+
config := configuration.Get()
206219
err := templateFolder.ExecuteTemplate(w, "redirect_filename", redirectValues{
207-
id, "d"})
220+
FileId: id,
221+
RedirectUrl: "d",
222+
Name: file.Name,
223+
Size: file.Size,
224+
PublicName: config.PublicName,
225+
BaseUrl: config.ServerUrl,
226+
PasswordRequired: file.PasswordHash != ""})
208227
helper.CheckIgnoreTimeout(err)
209228
}
210229

@@ -373,13 +392,16 @@ func showDownload(w http.ResponseWriter, r *http.Request) {
373392
return
374393
}
375394

395+
config := configuration.Get()
396+
376397
view := DownloadView{
377398
Name: file.Name,
378399
Size: file.Size,
379400
Id: file.Id,
380401
IsDownloadView: true,
381402
EndToEndEncryption: file.Encryption.IsEndToEndEncrypted,
382-
PublicName: configuration.Get().PublicName,
403+
PublicName: config.PublicName,
404+
BaseUrl: config.ServerUrl,
383405
IsFailedLogin: false,
384406
UsesHttps: configuration.UsesHttps(),
385407
}
@@ -547,6 +569,7 @@ type DownloadView struct {
547569
Id string
548570
Cipher string
549571
PublicName string
572+
BaseUrl string
550573
IsFailedLogin bool
551574
IsAdminView bool
552575
IsDownloadView bool

internal/webserver/web/templates/html_header.tmpl

+9-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@
4040
<title>{{.PublicName}}: Password required</title>
4141
<meta name="title" content="{{.PublicName}}">
4242
<meta name="description" content="Password required">
43+
44+
<meta property="og:title" content="{{.PublicName}}"/>
45+
<meta property="og:description" content="Password required"/>
4346
{{ else }}
4447
<title>{{.PublicName}}: {{.Name}}</title>
45-
<meta name="title" content="{{.PublicName}}">
46-
<meta name="description" content="{{.Name}}">
48+
<meta name="title" content="{{.PublicName}}: {{.Name}}">
49+
<meta name="description" content="{{.Size}}">
50+
51+
<meta property="og:title" content="{{.Name}}"/>
52+
<meta property="og:description" content="{{.Size}}"/>
4753
{{end }}
54+
<meta property="og:url" content="{{.BaseUrl}}"/>
4855
{{ else }}
4956
<title>{{.PublicName}}</title>
5057
{{end }}

internal/webserver/web/templates/html_redirect_filename.tmpl

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
{{define "redirect_filename"}}
2-
<html><head></head>
2+
<html><head>
3+
4+
{{ if .PasswordRequired }}
5+
<title>{{.PublicName}}: Password required</title>
6+
<meta name="title" content="{{.PublicName}}">
7+
<meta name="description" content="Password required">
8+
9+
<meta property="og:title" content="{{.PublicName}}"/>
10+
<meta property="og:description" content="Password required"/>
11+
{{ else }}
12+
<title>{{.PublicName}}: {{.Name}}</title>
13+
<meta name="title" content="{{.PublicName}}: {{.Name}}">
14+
<meta name="description" content="{{.Size}}">
15+
16+
<meta property="og:title" content="{{.Name}}"/>
17+
<meta property="og:description" content="{{.Size}}"/>
18+
{{end }}
19+
<meta property="og:url" content="{{.BaseUrl}}"/>
20+
21+
</head>
322

423
<!-- If you are not being redirected, click <a id="redirect" href="./../../{{.RedirectUrl}}?id={{.FileId}}">here</a> -->
524

625

726
<script>
827
let hash = window.location.hash.substr(1);
9-
//let url = document.getElementById("redirect");
10-
11-
//url.href = url.href + "#"+hash;
1228
window.location.replace("./../../{{.RedirectUrl}}?id={{.FileId}}#"+hash);
1329
</script>
1430

0 commit comments

Comments
 (0)