Compare commits

..

10 Commits

15 changed files with 67 additions and 25 deletions

View File

@@ -22,7 +22,7 @@ docker-build:
# All branches are tagged with $DOCKER_IMAGE_NAME (defaults to commit ref slug)
# Default branch is also tagged with `latest`
script:
- docker build --pull -t "$DOCKER_IMAGE_NAME" .
- docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from $CI_REGISTRY_IMAGE:latest --pull -t "$DOCKER_IMAGE_NAME" .
- docker push "$DOCKER_IMAGE_NAME"
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then

View File

@@ -21,6 +21,9 @@ func main() {
services.InitPostService()
// Not needed but anyways
services.InitImgKitHelper()
ticker := time.NewTicker(10 * time.Minute)
runFetchPosts := func() {

View File

@@ -22,6 +22,8 @@ type config struct {
DBUser string
DBPassword string
DBName string
ImageKitId string
}
var Config *config
@@ -29,7 +31,7 @@ var Config *config
func Load() *config {
err := godotenv.Load()
if err != nil {
slog.Error("Error loading .env file - Using environment variables instead")
slog.Warn("Error loading .env file - Using environment variables instead")
}
// Get mastodon instance
@@ -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.io")
}
// Inititlize AppContext
var appContext = &config{
AdminPassword: adminPassword,
@@ -98,6 +104,8 @@ func Load() *config {
DBUser: dbUser,
DBPassword: dbPassword,
DBName: dbName,
ImageKitId: imageKitId,
}
return appContext

View File

@@ -0,0 +1,26 @@
package services
import "CatsOfMastodonBotGo/internal/config"
type ImgKitHelper struct {
}
var ImgKitHelperInstance *ImgKitHelper
func InitImgKitHelper() {
ImgKitHelperInstance = &ImgKitHelper{}
}
func GetPreviewUrl(url string) string {
if config.Config.ImageKitId == "" {
return url
}
return "https://ik.imagekit.io/" + config.Config.ImageKitId + "/tr:w-500,h-500,c-at_max,f-webp,q-50/" + url
}
func GetRemoteUrl(url string) string {
if config.Config.ImageKitId == "" {
return url
}
return "https://ik.imagekit.io/" + config.Config.ImageKitId + "/tr:q-70,dpr-auto,f-webp/" + url
}

View File

@@ -0,0 +1,13 @@
package dto
type ApproveMediaInput struct {
MediaId string `json:"mediaId" binding:"required"`
}
type LoginInput struct {
Password string `json:"password" binding:"required"`
}
type RejectMediaInput struct {
MediaId string `json:"mediaId" binding:"required"`
}

View File

@@ -1,5 +0,0 @@
package dto
type ApproveMediaInput struct {
MediaId string `json:"mediaId" binding:"required"`
}

View File

@@ -1,5 +0,0 @@
package dto
type LoginInput struct {
Password string `json:"password" binding:"required"`
}

View File

@@ -1,5 +0,0 @@
package dto
type RejectMediaInput struct {
MediaId string `json:"mediaId" binding:"required"`
}

View File

@@ -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.RemoteUrl)
media.RemoteUrl = services.GetPreviewUrl(media.RemoteUrl)
c.JSON(http.StatusOK, media)
}

View File

@@ -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 i := range post.Attachments {
post.Attachments[i].RemoteUrl = services.GetRemoteUrl(post.Attachments[i].RemoteUrl)
post.Attachments[i].PreviewUrl = services.GetPreviewUrl(post.Attachments[i].RemoteUrl)
}
c.JSON(200, post)
}

View File

@@ -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

View File

@@ -13,7 +13,7 @@
<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary_large_image" />
<script type="module" crossorigin src="/admin/assets/index-Do3iuUd_.js"></script>
<script type="module" crossorigin src="/admin/assets/index-JxecVd-K.js"></script>
<link rel="stylesheet" crossorigin href="/admin/assets/index-DShmOgsI.css">
</head>

View File

@@ -1,2 +1,2 @@
User-agent: *
Allow: /
Disallow: /