]> git.feebdaed.xyz Git - gomehub.git/commitdiff
Adding sorrylinus
authorseantywork <seantywork@gmail.com>
Fri, 12 Jul 2024 06:45:17 +0000 (15:45 +0900)
committerseantywork <seantywork@gmail.com>
Fri, 12 Jul 2024 06:45:17 +0000 (15:45 +0900)
ctl/base.go
ctl/ctl.go
pkg/dbquery/dbquery.go
pkg/sorrylinus/sorrylinus.go

index 5c0d22b4e1cec1683a53a1c6a8b00518b4ae1433..3cc44876e2eb6c52e053969979dc68cfe56b818a 100644 (file)
@@ -1,14 +1,23 @@
 package controller
 
 import (
+       "encoding/json"
        "fmt"
        "net/http"
 
        "github.com/gin-gonic/gin"
        pkgauth "github.com/seantywork/sorrylinus-again/pkg/auth"
        "github.com/seantywork/sorrylinus-again/pkg/com"
+       "github.com/seantywork/sorrylinus-again/pkg/dbquery"
 )
 
+type EntryStruct struct {
+       Entry []struct {
+               Title string
+               Id    string
+       } `json:"entry"`
+}
+
 func GetIndex(c *gin.Context) {
 
        c.HTML(200, "index.html", gin.H{})
@@ -92,10 +101,6 @@ func GetViewMypageRoom(c *gin.Context) {
 
 }
 
-func GetBase(c *gin.Context) {
-
-}
-
 func GetViewContentArticle(c *gin.Context) {
 
        c.HTML(200, "content/article.html", gin.H{})
@@ -113,3 +118,66 @@ func GetViewRoom(c *gin.Context) {
        c.HTML(200, "room/index.html", gin.H{})
 
 }
+
+func GetMediaEntry(c *gin.Context) {
+
+       entry := EntryStruct{}
+
+       em, err := dbquery.GetEntryForMedia()
+
+       if err != nil {
+
+               fmt.Printf("get content entry: failed to retrieve: %s\n", err.Error())
+
+               c.JSON(http.StatusInternalServerError, com.SERVER_RE{Status: "error", Reply: "failed to retrieve content entry"})
+
+               return
+
+       }
+
+       for k, v := range em {
+
+               if v.Type == "article" {
+
+                       entry.Entry = append(entry.Entry, struct {
+                               Title string
+                               Id    string
+                       }{
+
+                               Title: v.PlainName,
+                               Id:    k,
+                       })
+
+               } else if v.Type == "video" {
+
+                       entry.Entry = append(entry.Entry, struct {
+                               Title string
+                               Id    string
+                       }{
+
+                               Title: v.PlainName + "." + v.Extension,
+                               Id:    k,
+                       })
+
+               } else {
+
+                       continue
+               }
+
+       }
+
+       jb, err := json.Marshal(entry)
+
+       if err != nil {
+
+               fmt.Printf("get content entry: failed to marshal: %s\n", err.Error())
+
+               c.JSON(http.StatusInternalServerError, com.SERVER_RE{Status: "error", Reply: "failed to retrieve content entry"})
+
+               return
+
+       }
+
+       c.JSON(http.StatusOK, com.SERVER_RE{Status: "success", Reply: string(jb)})
+
+}
index 29ff3ead21436d8e481e40f847c27b138f4d4934..a751f2efce6e88fd9de1c9d51d6cc96424d46a4d 100644 (file)
@@ -97,14 +97,14 @@ func RegisterRoutes(e *gin.Engine) {
 
        e.GET("/mypage/room", GetViewMypageRoom)
 
-       e.GET("/api/base", GetBase)
-
        e.GET("/content/article/:articleId", GetViewContentArticle)
 
        e.GET("/content/video/:videoId", GetViewContentVideo)
 
        e.GET("/room/:roomId", GetViewRoom)
 
+       e.GET("/api/content/entry", GetMediaEntry)
+
        // auth
 
        e.GET("/api/oauth2/google/signin", pkgauth.OauthGoogleLogin)
@@ -124,8 +124,10 @@ func RegisterRoutes(e *gin.Engine) {
        // sorrylinus
 
        // e.POST("/api/sorrylinus/connect", pkgsoli.Connect)
+
        // e.POST("/api/sorrylinus/disconnect", pkgsoli.Disconnect)
-       // e.POST("/api/sorrylinus/rt", pkgsoli.RoundTrip)
+
+       // e.POST("/api/sorrylinus/rt", pkgsoli.RoundTripEx)
 
        // edition
 
@@ -157,7 +159,7 @@ func RegisterRoutes(e *gin.Engine) {
 
        e.GET("/api/peers/signal/address", pkgstream.GetPeersSignalAddress)
 
-       // channel
+       // com
 
        pkgcom.AddChannelHandler(CONF.Stream.PeerSignalAddr, pkgstream.RoomSignalHandler)
 
index 62aef1cf0b4360fc2d14f129bd680923ca0988c6..16adca5288a519b00a44155f48727421db78aaa5 100644 (file)
@@ -242,6 +242,54 @@ func GetByIdFromSession(email string) (string, *SessionStruct, error) {
        return "", nil, fmt.Errorf("id: %s: not found", email)
 }
 
+func GetEntryForMedia() (map[string]MediaStruct, error) {
+
+       em := make(map[string]MediaStruct)
+
+       files, err := os.ReadDir(mediaPath)
+
+       if err != nil {
+
+               return nil, fmt.Errorf("media entry: failed to read dir: %s", err.Error())
+
+       }
+
+       for _, f := range files {
+
+               ms := MediaStruct{}
+
+               f_name := f.Name()
+
+               if !strings.Contains(f_name, ".json") {
+                       continue
+               }
+
+               key_name := strings.ReplaceAll(f_name, ".json", "")
+
+               this_file_path := mediaPath + f_name
+
+               file_b, err := os.ReadFile(this_file_path)
+
+               if err != nil {
+
+                       return nil, fmt.Errorf("media entry: failed to read file: %s", err.Error())
+
+               }
+
+               err = json.Unmarshal(file_b, &ms)
+
+               if err != nil {
+
+                       return nil, fmt.Errorf("media entry: failed to marshal: %s", err.Error())
+               }
+
+               em[key_name] = ms
+
+       }
+
+       return em, nil
+}
+
 func RemoveSessionKeyFromSession(session_key string) error {
 
        this_file_path := sessionPath + session_key + ".json"
index 499fd2b5cd4b20e022bfd85c644210675373d6cd..de21021a89a2ce5cbc5f2dc93d0a3658f96892a2 100644 (file)
@@ -1 +1,19 @@
 package sorrylinus
+
+import "github.com/gin-gonic/gin"
+
+func Connect(c *gin.Context) {
+
+}
+
+func Disconnect(c *gin.Context) {
+
+}
+
+func RoundTripEx(c *gin.Context) {
+
+}
+
+func RoundTrip() {
+
+}