Przeglądaj źródła

adding some fun stuff to the digital art section

AETH-erial 7 miesięcy temu
rodzic
commit
5bb4b1a020

+ 17 - 1
html/templates/centered_image.html

@@ -3,8 +3,24 @@
 <html lang="en">
     <div class="row container-fluid m-0 p-0">
         <div class="col container-fluid" style="background-color: black;"></div>
-        <img src="{{ . }}" loading="lazy" class="img-fluid m-0 p-0 col-auto" style="background-color: black; max-height: 70vh;">
+        <img src="{{ .ApiPath }}" loading="lazy" class="img-fluid m-0 p-0 col-auto" style="background-color: black; max-height: 70vh;">
         <div class="col container-fluid" style="background-color: black;"></div>
     </div>
+    <a href="#">
+        <div class="mask" style="background-color: hsla(0, 0%, 98%, 0.2)">
+            <div class="row align-items-center" style="font-family: monospace; color: white; min-height: 100%;">
+                <div class="col"></div>
+                <div class="col-auto">
+                    <div class="row col-auto p-2 m-2" style="font-size: xx-large;">
+                        '{{ .Title }}'
+                    </div>
+                    <div class="row col-auto p-2 m-2" style="font-size: x-large;">
+                        {{ .Desc }}
+                    </div>
+                </div>
+                <div class="col"></div>
+            </div>
+        </div>
+    </a>
 </html>
 {{ end }}

+ 1 - 3
html/templates/digital_art.html

@@ -17,9 +17,7 @@
                         <div class="row position-relative shadow-lg p-3 m-3 rounded justify-content-center"
                             style="width: 80vh; max-width: 95%; background-color: rgb(22, 22, 22);">
                                 {{ template "centered_image.html" . }}
-                            <a href="#">
-                                <div class="mask" style="background-color: hsla(0, 0%, 98%, 0.2)"></div>
-                            </a>
+
                         </div>
                     </div>
                 </div>

+ 0 - 1
pkg/controller/controller.go

@@ -86,7 +86,6 @@ func (c *Controller) SaveImage(img *helpers.ImageStoreItem) error {
 }
 
 
-
 func NewController(root string, domain string, redisPort string, redisAddr string) *Controller {
 	return &Controller{WebRoot: root, Cache: helpers.NewCache(),
 								Domain: domain, RedisConfig: helpers.RedisConf{

+ 2 - 1
pkg/controller/html_handlers.go

@@ -137,7 +137,8 @@ func (c *Controller) ServeTechnicalWriteups(ctx *gin.Context) {
 // @Tags webpages
 // @Router /digital [get]
 func (c *Controller) ServeDigitalArt(ctx *gin.Context) {
-	fnames, err := helpers.GetImagePaths(4, 0)
+	rds := helpers.NewRedisClient(c.RedisConfig)
+	fnames, err := helpers.GetImageData(rds)
 	if err != nil {
 		ctx.HTML(http.StatusInternalServerError, "unhandled_error",
 		gin.H{

+ 1 - 5
pkg/helpers/auth.go

@@ -43,11 +43,7 @@ func (c *AllCache) update(id string, cookie string) {
 
 func (c *AllCache) Read(id string) bool {
     _, ok := c.AuthCookies.Get(id)
-    if ok {
-
-        return true
-    }
-    return false
+	return ok
 }
 
 

+ 1 - 6
pkg/helpers/helpers.go

@@ -2,8 +2,7 @@ package helpers
 
 import (
 	"encoding/json"
-	"fmt"
-	"os"
+
 	"strings"
 	"time"
 
@@ -203,23 +202,19 @@ Retrieve all documents from the category specified in the argument category
 */
 func GetAllDocuments(category string, redisCfg RedisConf) ([]*Document, error) {
 	rdc := NewRedisClient(redisCfg)
-	fmt.Fprintf(os.Stdout, "%+v\n", redisCfg)
 	ids, err := rdc.AllDocIds()
 	if err != nil {
-		fmt.Fprint(os.Stdout, "failed 1")
 		return nil, err
 	}
 	var docs []*Document
 	for idx := range ids {
 		doc, err := rdc.GetItem(ids[idx])
 		if err != nil {
-			fmt.Fprint(os.Stdout, "failed 2")
 			return nil, err
 		}
 		if doc.Category != category {
 			continue
 		}
-		
 		docs = append(docs, &Document{
 			Ident: doc.Ident,
 			Created: doc.Created,

+ 24 - 0
pkg/helpers/redis.go

@@ -139,6 +139,30 @@ func (r *RedisCaller) GetItem(id string) (*Document, error) {
 	return &doc, nil
 }
 
+/*
+Retrieve all redis items by category. Returns all the IDs of items that belong to that category
+	:param category: the category to filter by
+*/
+func (r *RedisCaller) GetByCategory(category string) ([]string, error) {
+	ids, err := r.AllDocIds()
+	if err != nil {
+		return nil, err
+	}
+	var matches []string
+	for i := range ids {
+		item, err := r.GetItem(ids[i])
+		if err != nil {
+			return nil, err
+		}
+		if item.Category == category {
+			matches = append(matches, ids[i])
+		}
+
+	}
+	return matches, nil
+}
+
+
 /*
 Delete the target document in redis
 	:param id: the id to delete from redis

+ 25 - 15
pkg/helpers/storage.go

@@ -1,12 +1,14 @@
 package helpers
 
 import (
+	"encoding/json"
 	"fmt"
 	"os"
 	"time"
 
 	"git.aetherial.dev/aeth/keiji/pkg/env"
 	"github.com/google/uuid"
+	"github.com/redis/go-redis/v9"
 )
 
 type InvalidSkipArg struct {Skip int}
@@ -24,6 +26,7 @@ type ImageStoreItem struct {
 	Created			string	`json:"created"`
 	Desc			string	`json:"description" form:"description"`
 	Category		string	`json:"category"`
+	ApiPath			string
 }
 
 /*
@@ -56,25 +59,32 @@ func GetImageStore() string {
 }
 
 /*
-Return all of the filenames of the images that exist in the imagestore location
-	:param limit: the limit of filenames to return
-	:param skip: the index to start getting images from
+Return database entries of the images that exist in the imagestore
+	:param rds: pointer to a RedisCaller to perform the lookups with
 */
-func GetImagePaths(limit int, skip int) ([]string, error) {
-	f, err := os.ReadDir(GetImageStore())
+func GetImageData(rds *RedisCaller) ([]*ImageStoreItem, error) {
+	ids, err := rds.GetByCategory(DIGITAL_ART)
 	if err != nil {
 		return nil, err
 	}
-	if len(f) < skip {
-		return nil, &InvalidSkipArg{Skip: skip}
-	}
-	if len(f) < limit {
-		return nil, &InvalidSkipArg{Skip: limit}
-	}
-	fnames := []string{}
-	for i := skip; i < (skip + limit); i++ {
-		fnames = append(fnames, fmt.Sprintf("/api/v1/images/%s", f[i].Name()))
+
+	var imageEntries []*ImageStoreItem
+	for i := range ids {
+		val, err := rds.Client.Get(rds.ctx, ids[i]).Result()
+		if err == redis.Nil {
+			return nil, err
+		} else if err != nil {
+			return nil, err
+		}
+		data := []byte(val)
+		var imageEntry ImageStoreItem
+		err = json.Unmarshal(data, &imageEntry)
+		if err != nil {
+			return nil, err
+		}
+		imageEntry.ApiPath = fmt.Sprintf("/api/v1/images/%s", imageEntry.Filename)
+		imageEntries = append(imageEntries, &imageEntry)
 	}
-	return fnames, err
+	return imageEntries, err
 }