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{})
}
-func GetBase(c *gin.Context) {
-
-}
-
func GetViewContentArticle(c *gin.Context) {
c.HTML(200, "content/article.html", gin.H{})
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)})
+
+}
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)
// 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
e.GET("/api/peers/signal/address", pkgstream.GetPeersSignalAddress)
- // channel
+ // com
pkgcom.AddChannelHandler(CONF.Stream.PeerSignalAddr, pkgstream.RoomSignalHandler)
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"
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() {
+
+}