@@ -224,6 +224,13 @@ func filePath(r *http.Request, file *snips.File) string {
224224 return fmt .Sprintf ("/f/%s" , file .ID )
225225}
226226
227+ func preferredFilePath (file * snips.File ) string {
228+ if file .Name != "" {
229+ return fmt .Sprintf ("/f/%s/n/%s" , file .ID , file .Name )
230+ }
231+ return fmt .Sprintf ("/f/%s" , file .ID )
232+ }
233+
227234func (ui * UI ) File (w http.ResponseWriter , r * http.Request ) {
228235 log := logger .From (r .Context ())
229236
@@ -316,12 +323,18 @@ func (ui *UI) File(w http.ResponseWriter, r *http.Request) {
316323 }
317324
318325 path := filePath (r , file )
319- ogImageURL := fmt .Sprintf ("%s://%s%s/og.png" , ui .cfg .HTTP .External .Scheme , ui .cfg .HTTP .External .Host , path )
320- ogDescription := fmt .Sprintf ("%s · %s · %s · %s" , file .ID , strings .ToLower (file .Type ), humanize .Bytes (file .Size ), humanize .Time (file .UpdatedAt ))
326+ previewURL := fmt .Sprintf ("%s://%s%s" , ui .cfg .HTTP .External .Scheme , ui .cfg .HTTP .External .Host , preferredFilePath (file ))
327+ ogImageURL := previewURL + "/og.png"
328+ previewName := file .ID
329+ if file .Name != "" {
330+ previewName = file .Name
331+ }
332+ ogDescription := fmt .Sprintf ("%s · %s · %s · %s" , previewName , strings .ToLower (file .Type ), humanize .Bytes (file .Size ), humanize .Time (file .UpdatedAt ))
321333
322334 vars := map [string ]interface {}{
323335 "FileID" : file .ID ,
324336 "FileName" : file .Name ,
337+ "PreviewName" : previewName ,
325338 "FilePath" : path ,
326339 "FileSize" : humanize .Bytes (file .Size ),
327340 "CreatedAt" : humanize .Time (file .CreatedAt ),
@@ -334,6 +347,7 @@ func (ui *UI) File(w http.ResponseWriter, r *http.Request) {
334347 "Private" : file .Private ,
335348 "CommitSHA" : config .BuildCommit (),
336349 "OGImageURL" : ogImageURL ,
350+ "OGURL" : previewURL ,
337351 "OGDescription" : ogDescription ,
338352 "RevisionCount" : revisionCount ,
339353 }
@@ -402,6 +416,7 @@ func (ui *UI) OGImage(w http.ResponseWriter, r *http.Request) {
402416 var img bytes.Buffer
403417 err = ui .og .WriteImage (& img , & opengraph.FileInfo {
404418 ID : file .ID ,
419+ Name : file .Name ,
405420 Type : file .Type ,
406421 Size : file .Size ,
407422 UpdatedAt : file .UpdatedAt ,
0 commit comments