Compare commits
10 Commits
ccb810ee69
...
main
Author | SHA1 | Date | |
---|---|---|---|
a7ef859c43 | |||
ba06de2c11 | |||
8dcdd27745 | |||
a43bcc9c14 | |||
71800440be | |||
051408fcdd | |||
48b893a403 | |||
0a0af6b04b | |||
85fe309b05 | |||
e7b8338932 |
@@ -22,7 +22,7 @@ docker-build:
|
|||||||
# All branches are tagged with $DOCKER_IMAGE_NAME (defaults to commit ref slug)
|
# All branches are tagged with $DOCKER_IMAGE_NAME (defaults to commit ref slug)
|
||||||
# Default branch is also tagged with `latest`
|
# Default branch is also tagged with `latest`
|
||||||
script:
|
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"
|
- docker push "$DOCKER_IMAGE_NAME"
|
||||||
- |
|
- |
|
||||||
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
|
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
|
||||||
|
@@ -21,6 +21,9 @@ func main() {
|
|||||||
|
|
||||||
services.InitPostService()
|
services.InitPostService()
|
||||||
|
|
||||||
|
// Not needed but anyways
|
||||||
|
services.InitImgKitHelper()
|
||||||
|
|
||||||
ticker := time.NewTicker(10 * time.Minute)
|
ticker := time.NewTicker(10 * time.Minute)
|
||||||
|
|
||||||
runFetchPosts := func() {
|
runFetchPosts := func() {
|
||||||
|
@@ -22,6 +22,8 @@ type config struct {
|
|||||||
DBUser string
|
DBUser string
|
||||||
DBPassword string
|
DBPassword string
|
||||||
DBName string
|
DBName string
|
||||||
|
|
||||||
|
ImageKitId string
|
||||||
}
|
}
|
||||||
|
|
||||||
var Config *config
|
var Config *config
|
||||||
@@ -29,7 +31,7 @@ var Config *config
|
|||||||
func Load() *config {
|
func Load() *config {
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
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
|
// Get mastodon instance
|
||||||
@@ -65,7 +67,6 @@ func Load() *config {
|
|||||||
audience = "CatsOfMastodonBotGo"
|
audience = "CatsOfMastodonBotGo"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dbEngine := os.Getenv("CAOM_DB_ENGINE")
|
dbEngine := os.Getenv("CAOM_DB_ENGINE")
|
||||||
dbHost := os.Getenv("CAOM_DB_HOST")
|
dbHost := os.Getenv("CAOM_DB_HOST")
|
||||||
dbPort := os.Getenv("CAOM_DB_PORT")
|
dbPort := os.Getenv("CAOM_DB_PORT")
|
||||||
@@ -82,6 +83,11 @@ func Load() *config {
|
|||||||
dbPassword = ""
|
dbPassword = ""
|
||||||
dbName = "caom.db"
|
dbName = "caom.db"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imageKitId := os.Getenv("CAOM_IMAGEKIT_ID")
|
||||||
|
if imageKitId == "" {
|
||||||
|
slog.Info("No imagekit id provided, not using imagekit.io")
|
||||||
|
}
|
||||||
// Inititlize AppContext
|
// Inititlize AppContext
|
||||||
var appContext = &config{
|
var appContext = &config{
|
||||||
AdminPassword: adminPassword,
|
AdminPassword: adminPassword,
|
||||||
@@ -98,6 +104,8 @@ func Load() *config {
|
|||||||
DBUser: dbUser,
|
DBUser: dbUser,
|
||||||
DBPassword: dbPassword,
|
DBPassword: dbPassword,
|
||||||
DBName: dbName,
|
DBName: dbName,
|
||||||
|
|
||||||
|
ImageKitId: imageKitId,
|
||||||
}
|
}
|
||||||
return appContext
|
return appContext
|
||||||
|
|
||||||
|
26
internal/services/imgKitHelper.go
Normal file
26
internal/services/imgKitHelper.go
Normal 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
|
||||||
|
}
|
13
internal/web/dto/adminDash.go
Normal file
13
internal/web/dto/adminDash.go
Normal 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"`
|
||||||
|
}
|
@@ -1,5 +0,0 @@
|
|||||||
package dto
|
|
||||||
|
|
||||||
type ApproveMediaInput struct {
|
|
||||||
MediaId string `json:"mediaId" binding:"required"`
|
|
||||||
}
|
|
@@ -1,5 +0,0 @@
|
|||||||
package dto
|
|
||||||
|
|
||||||
type LoginInput struct {
|
|
||||||
Password string `json:"password" binding:"required"`
|
|
||||||
}
|
|
@@ -1,5 +0,0 @@
|
|||||||
package dto
|
|
||||||
|
|
||||||
type RejectMediaInput struct {
|
|
||||||
MediaId string `json:"mediaId" binding:"required"`
|
|
||||||
}
|
|
@@ -53,6 +53,8 @@ func (ps *AdminDashboardHandler) RejectMedia(c *gin.Context) {
|
|||||||
|
|
||||||
func (ps *AdminDashboardHandler) GetMedia(c *gin.Context) {
|
func (ps *AdminDashboardHandler) GetMedia(c *gin.Context) {
|
||||||
media := ps.PostService.GetMedia()
|
media := ps.PostService.GetMedia()
|
||||||
|
media.PreviewUrl = services.GetPreviewUrl(media.RemoteUrl)
|
||||||
|
media.RemoteUrl = services.GetPreviewUrl(media.RemoteUrl)
|
||||||
c.JSON(http.StatusOK, media)
|
c.JSON(http.StatusOK, media)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,9 +16,14 @@ func InitApiEndpointHandler() {
|
|||||||
ApiEndpointHandlerInstance = &ApiEndpointHandler{
|
ApiEndpointHandlerInstance = &ApiEndpointHandler{
|
||||||
PostService: *services.PostServiceInstance,
|
PostService: *services.PostServiceInstance,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps *ApiEndpointHandler) GetRandomPost(c *gin.Context) {
|
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)
|
||||||
|
}
|
||||||
|
@@ -22,6 +22,6 @@ func (ps *EmbedCardHandler) GetEmbedCard(c *gin.Context) {
|
|||||||
post := ps.PostService.GetRandomPost()
|
post := ps.PostService.GetRandomPost()
|
||||||
c.HTML(200, "home/embed.html", gin.H{
|
c.HTML(200, "home/embed.html", gin.H{
|
||||||
"postUrl": post.Url,
|
"postUrl": post.Url,
|
||||||
"imageUrl": post.Attachments[0].RemoteUrl,
|
"imageUrl": services.GetRemoteUrl(post.Attachments[0].RemoteUrl),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 7.5 KiB |
@@ -13,7 +13,7 @@
|
|||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
|
|
||||||
<meta name="twitter:card" content="summary_large_image" />
|
<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">
|
<link rel="stylesheet" crossorigin href="/admin/assets/index-DShmOgsI.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
User-agent: *
|
User-agent: *
|
||||||
Allow: /
|
Disallow: /
|
Reference in New Issue
Block a user