Add oembed tags. Fix sharing and copy link button. Add text and file viewer

This commit is contained in:
2023-05-17 19:27:46 +02:00
parent 277637511c
commit bd9359de44
16 changed files with 459 additions and 192 deletions

View File

@@ -3,9 +3,11 @@ package webcontroller
import (
"fmt"
"net/http"
"net/url"
"strings"
"fornaxian.tech/log"
"fornaxian.tech/pixeldrain_api_client/pixelapi"
"fornaxian.tech/util"
"github.com/julienschmidt/httprouter"
)
@@ -35,8 +37,70 @@ func (wc *WebController) serveDirectory(w http.ResponseWriter, r *http.Request,
td.Title = fmt.Sprintf("%s ~ pixeldrain", node.Path[node.BaseIndex].Name)
td.Other = node
td.OGData = wc.metadataFromFilesystem(node)
err = wc.templates.Get().ExecuteTemplate(w, "filesystem", td)
if err != nil && !util.IsNetError(err) {
log.Error("Error executing template filesystem: %s", err)
}
}
func (wc *WebController) metadataFromFilesystem(f pixelapi.FilesystemPath) (og ogData) {
var (
base = f.Path[f.BaseIndex]
name = base.Name
filetype = base.Type
filepath = url.PathEscape(f.Path[0].ID + base.Path)
pageurl = wc.config.WebsiteAddress + "/d/" + filepath
fileurl = wc.config.WebsiteAddress + "/api/filesystem/" + filepath
thumbnailurl = wc.config.WebsiteAddress + "/api/filesystem/" + filepath + "?thumbnail"
)
og.addProp("og:title", name)
og.addProp("og:site_name", "pixeldrain")
og.addProp("og:description", "This file has been shared with you on pixeldrain")
og.addProp("og:url", pageurl)
og.addProp("description", "This file has been shared with you on pixeldrain")
og.addName("description", "This file has been shared with you on pixeldrain")
og.addName("keywords", "pixeldrain,shared,sharing,upload,file,free")
og.addName("twitter:title", name)
og.addName("twitter:site", "@Fornax96")
og.addName("twitter:domain", "pixeldrain.com")
if strings.HasPrefix(filetype, "image") {
og.addProp("og:type", "article")
og.addProp("og:image", fileurl)
og.addProp("og:image:url", fileurl)
og.addProp("og:image:secure_url", fileurl)
og.addProp("og:image:type", filetype)
og.addName("twitter:card", "summary_large_image")
og.addName("twitter:image", fileurl)
og.addLink("image_src", fileurl)
} else if strings.HasPrefix(filetype, "video") {
og.addProp("og:type", "video.other")
og.addProp("og:image", thumbnailurl)
og.addProp("og:video", fileurl)
og.addProp("og:video:url", fileurl)
og.addProp("og:video:secure_url", fileurl)
og.addProp("og:video:type", filetype)
og.addName("twitter:card", "player")
og.addName("twitter:image", thumbnailurl)
og.addName("twitter:player", fileurl)
og.addName("twitter:player:stream", fileurl)
og.addName("twitter:player:stream:content_type", filetype)
og.addLink("image_src", thumbnailurl)
} else if strings.HasPrefix(filetype, "audio") {
og.addProp("og:type", "music.song")
og.addProp("og:image", thumbnailurl)
og.addProp("og:audio", fileurl)
og.addProp("og:audio:secure_url", fileurl)
og.addProp("og:audio:type", filetype)
og.addLink("image_src", thumbnailurl)
} else {
og.addProp("og:type", "website")
og.addProp("og:image", thumbnailurl)
og.addLink("image_src", thumbnailurl)
}
return og
}