Added preview for WhatsApp

This commit is contained in:
Marc Ole Bulling
2024-09-30 18:02:00 +02:00
parent 0ec822fb55
commit 0e80a59e15
3 changed files with 56 additions and 10 deletions

View File

@@ -196,15 +196,34 @@ func redirect(w http.ResponseWriter, url string) {
}
type redirectValues struct {
FileId string
RedirectUrl string
FileId string
RedirectUrl string
Name string
Size string
PublicName string
BaseUrl string
PasswordRequired bool
}
// Handling of /id/?/? - used when filename shall be displayed, will redirect to regular download URL
func redirectFromFilename(w http.ResponseWriter, r *http.Request) {
addNoCacheHeader(w)
id := r.PathValue("id")
file, ok := storage.GetFile(id)
if !ok {
redirect(w, "../../error")
return
}
config := configuration.Get()
err := templateFolder.ExecuteTemplate(w, "redirect_filename", redirectValues{
id, "d"})
FileId: id,
RedirectUrl: "d",
Name: file.Name,
Size: file.Size,
PublicName: config.PublicName,
BaseUrl: config.ServerUrl,
PasswordRequired: file.PasswordHash != ""})
helper.CheckIgnoreTimeout(err)
}
@@ -373,13 +392,16 @@ func showDownload(w http.ResponseWriter, r *http.Request) {
return
}
config := configuration.Get()
view := DownloadView{
Name: file.Name,
Size: file.Size,
Id: file.Id,
IsDownloadView: true,
EndToEndEncryption: file.Encryption.IsEndToEndEncrypted,
PublicName: configuration.Get().PublicName,
PublicName: config.PublicName,
BaseUrl: config.ServerUrl,
IsFailedLogin: false,
UsesHttps: configuration.UsesHttps(),
}
@@ -547,6 +569,7 @@ type DownloadView struct {
Id string
Cipher string
PublicName string
BaseUrl string
IsFailedLogin bool
IsAdminView bool
IsDownloadView bool

View File

@@ -40,11 +40,18 @@
<title>{{.PublicName}}: Password required</title>
<meta name="title" content="{{.PublicName}}">
<meta name="description" content="Password required">
<meta property="og:title" content="{{.PublicName}}"/>
<meta property="og:description" content="Password required"/>
{{ else }}
<title>{{.PublicName}}: {{.Name}}</title>
<meta name="title" content="{{.PublicName}}">
<meta name="description" content="{{.Name}}">
<meta name="title" content="{{.PublicName}}: {{.Name}}">
<meta name="description" content="{{.Size}}">
<meta property="og:title" content="{{.Name}}"/>
<meta property="og:description" content="{{.Size}}"/>
{{end }}
<meta property="og:url" content="{{.BaseUrl}}"/>
{{ else }}
<title>{{.PublicName}}</title>
{{end }}

View File

@@ -1,14 +1,30 @@
{{define "redirect_filename"}}
<html><head></head>
<html><head>
{{ if .PasswordRequired }}
<title>{{.PublicName}}: Password required</title>
<meta name="title" content="{{.PublicName}}">
<meta name="description" content="Password required">
<meta property="og:title" content="{{.PublicName}}"/>
<meta property="og:description" content="Password required"/>
{{ else }}
<title>{{.PublicName}}: {{.Name}}</title>
<meta name="title" content="{{.PublicName}}: {{.Name}}">
<meta name="description" content="{{.Size}}">
<meta property="og:title" content="{{.Name}}"/>
<meta property="og:description" content="{{.Size}}"/>
{{end }}
<meta property="og:url" content="{{.BaseUrl}}"/>
</head>
<!-- If you are not being redirected, click <a id="redirect" href="./../../{{.RedirectUrl}}?id={{.FileId}}">here</a> -->
<script>
let hash = window.location.hash.substr(1);
//let url = document.getElementById("redirect");
//url.href = url.href + "#"+hash;
window.location.replace("./../../{{.RedirectUrl}}?id={{.FileId}}#"+hash);
</script>