Compare commits
3 Commits
85fe309b05
...
051408fcdd
Author | SHA1 | Date | |
---|---|---|---|
051408fcdd | |||
48b893a403 | |||
0a0af6b04b |
@@ -21,6 +21,9 @@ func main() {
|
||||
|
||||
services.InitPostService()
|
||||
|
||||
// Not needed but anyways
|
||||
services.InitImgKitHelper()
|
||||
|
||||
ticker := time.NewTicker(10 * time.Minute)
|
||||
|
||||
runFetchPosts := func() {
|
||||
|
@@ -22,6 +22,8 @@ type config struct {
|
||||
DBUser string
|
||||
DBPassword string
|
||||
DBName string
|
||||
|
||||
ImageKitId string
|
||||
}
|
||||
|
||||
var Config *config
|
||||
@@ -65,7 +67,6 @@ func Load() *config {
|
||||
audience = "CatsOfMastodonBotGo"
|
||||
}
|
||||
|
||||
|
||||
dbEngine := os.Getenv("CAOM_DB_ENGINE")
|
||||
dbHost := os.Getenv("CAOM_DB_HOST")
|
||||
dbPort := os.Getenv("CAOM_DB_PORT")
|
||||
@@ -82,6 +83,11 @@ func Load() *config {
|
||||
dbPassword = ""
|
||||
dbName = "caom.db"
|
||||
}
|
||||
|
||||
imageKitId := os.Getenv("CAOM_IMAGEKIT_ID")
|
||||
if imageKitId == "" {
|
||||
slog.Info("No imagekit id provided, not using imagekit")
|
||||
}
|
||||
// Inititlize AppContext
|
||||
var appContext = &config{
|
||||
AdminPassword: adminPassword,
|
||||
@@ -98,6 +104,8 @@ func Load() *config {
|
||||
DBUser: dbUser,
|
||||
DBPassword: dbPassword,
|
||||
DBName: dbName,
|
||||
|
||||
ImageKitId: imageKitId,
|
||||
}
|
||||
return appContext
|
||||
|
||||
|
20
internal/services/imgKitHelper.go
Normal file
20
internal/services/imgKitHelper.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package services
|
||||
|
||||
import "CatsOfMastodonBotGo/internal/config"
|
||||
|
||||
type ImgKitHelper struct {
|
||||
}
|
||||
|
||||
var ImgKitHelperInstance *ImgKitHelper
|
||||
|
||||
func InitImgKitHelper() {
|
||||
ImgKitHelperInstance = &ImgKitHelper{}
|
||||
}
|
||||
|
||||
func GetPreviewUrl(url string) string {
|
||||
return "https://ik.imagekit.io/" + config.Config.ImageKitId + "/tr:w-500,h-500,c-at_max,f-webp,q-60/" + url
|
||||
}
|
||||
|
||||
func GetRemoteUrl(url string) string {
|
||||
return "https://ik.imagekit.io/" + config.Config.ImageKitId + "/tr:q-70,dpr-auto,f-webp/" + url
|
||||
}
|
@@ -53,6 +53,8 @@ func (ps *AdminDashboardHandler) RejectMedia(c *gin.Context) {
|
||||
|
||||
func (ps *AdminDashboardHandler) GetMedia(c *gin.Context) {
|
||||
media := ps.PostService.GetMedia()
|
||||
media.PreviewUrl = services.GetPreviewUrl(media.PreviewUrl)
|
||||
media.RemoteUrl = services.GetPreviewUrl(media.RemoteUrl)
|
||||
c.JSON(http.StatusOK, media)
|
||||
}
|
||||
|
||||
|
@@ -16,9 +16,14 @@ func InitApiEndpointHandler() {
|
||||
ApiEndpointHandlerInstance = &ApiEndpointHandler{
|
||||
PostService: *services.PostServiceInstance,
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
func (ps *ApiEndpointHandler) GetRandomPost(c *gin.Context) {
|
||||
c.JSON(200,ps.PostService.GetRandomPost())
|
||||
}
|
||||
post := ps.PostService.GetRandomPost()
|
||||
for _, attachment := range post.Attachments {
|
||||
attachment.RemoteUrl = services.GetRemoteUrl(attachment.RemoteUrl)
|
||||
attachment.PreviewUrl = services.GetPreviewUrl(attachment.RemoteUrl)
|
||||
}
|
||||
c.JSON(200, post)
|
||||
}
|
||||
|
@@ -22,6 +22,6 @@ func (ps *EmbedCardHandler) GetEmbedCard(c *gin.Context) {
|
||||
post := ps.PostService.GetRandomPost()
|
||||
c.HTML(200, "home/embed.html", gin.H{
|
||||
"postUrl": post.Url,
|
||||
"imageUrl": post.Attachments[0].RemoteUrl,
|
||||
"imageUrl": services.GetRemoteUrl(post.Attachments[0].RemoteUrl),
|
||||
})
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 7.5 KiB |
@@ -19,7 +19,5 @@
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<!-- IMPORTANT: DO NOT REMOVE THIS SCRIPT TAG OR THIS VERY COMMENT! -->
|
||||
<script src="https://cdn.gpteng.co/gptengineer.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -1,2 +1,3 @@
|
||||
User-agent: *
|
||||
Allow: /
|
||||
Disallow: /admin
|
||||
|
Reference in New Issue
Block a user