]> git.feebdaed.xyz Git - gomehub.git/commitdiff
Merged article and video, cascading deletion for article
authorseantywork <seantywork@gmail.com>
Tue, 23 Jul 2024 09:36:19 +0000 (18:36 +0900)
committerseantywork <seantywork@gmail.com>
Tue, 23 Jul 2024 09:36:19 +0000 (18:36 +0900)
12 files changed:
ctl/base.go
ctl/ctl.go
pkg/auth/integrity.go
pkg/dbquery/dbquery.go
pkg/dbquery/source.go [new file with mode: 0644]
pkg/edition/edition.go
pkg/edition/edition_etc.go [new file with mode: 0644]
pkg/edition/edition_video.go [deleted file]
public/js/mypage/article.js
test/test.go
test/test.json [new file with mode: 0644]
view/index/index.html

index 412c7f8e659ee7a0947074326032bb829607f2f9..9e1a48944a0659bc47eaed148bf7f534facb549e 100644 (file)
@@ -267,19 +267,6 @@ func GetMediaEntry(c *gin.Context) {
                                Type:  "article",
                        })
 
-               } else if v.Type == "video" {
-
-                       entry.Entry = append(entry.Entry, struct {
-                               Title string `json:"title"`
-                               Id    string `json:"id"`
-                               Type  string `json:"type"`
-                       }{
-
-                               Title: v.PlainName + "." + v.Extension,
-                               Id:    k,
-                               Type:  "video",
-                       })
-
                } else {
 
                        continue
index 4ccf558404953f5e0ae1848dc83a304c95579f16..9d11b94adb4914bcf66c679c6b2f9e82fb5f8733 100644 (file)
@@ -114,13 +114,13 @@ func RegisterRoutes(e *gin.Engine) {
 
        e.GET("/mypage/article", GetViewMypageArticle)
 
-       e.GET("/mypage/video", GetViewMypageVideo)
+       // e.GET("/mypage/video", GetViewMypageVideo)
 
        e.GET("/mypage/room", GetViewMypageRoom)
 
        e.GET("/content/article/:articleId", GetViewContentArticle)
 
-       e.GET("/content/video/:videoId", GetViewContentVideo)
+       // e.GET("/content/video/:videoId", GetViewContentVideo)
 
        e.GET("/room/:roomId", GetViewRoom)
 
@@ -160,15 +160,15 @@ func RegisterRoutes(e *gin.Engine) {
 
        e.GET("/api/article/c/:contentId", pkgedition.GetArticleContentById)
 
-       e.POST("/api/image/upload", pkgedition.PostImageUpload)
+       e.POST("/api/media/upload", pkgedition.PostMediaUpload)
 
-       e.GET("/api/image/c/:contentId", pkgedition.GetImageContentById)
+       e.GET("/api/media/c/:contentId", pkgedition.GetMediaContentById)
 
-       e.POST("/api/video/upload", pkgedition.PostVideoUpload)
+       // e.POST("/api/video/upload", pkgedition.PostVideoUpload)
 
-       e.POST("/api/video/delete", pkgedition.PostVideoDelete)
+       // e.POST("/api/video/delete", pkgedition.PostVideoDelete)
 
-       e.GET("/api/video/c/:contentId", pkgedition.GetVideoContentByID)
+       //e.GET("/api/video/c/:contentId", pkgedition.GetVideoContentByID)
 
        // stream
 
index 5cf414a871ea8d1e454e80b07722a840ea0970ea..f4e7f7ecb7ff035de277e408d4555279f6e53cc1 100644 (file)
@@ -50,6 +50,38 @@ func VerifyCodeNameValue(raw string) bool {
        return true
 }
 
+func VerifyCodeNameValueWithStop(raw string, stop rune) (bool, string) {
+
+       var retstr string
+
+       for _, c := range raw {
+
+               if unicode.IsLetter(c) {
+
+                       retstr += string(c)
+
+                       continue
+
+               } else if unicode.IsDigit(c) {
+
+                       retstr += string(c)
+
+                       continue
+
+               } else if c == stop {
+
+                       return true, retstr
+
+               } else {
+
+                       return false, ""
+               }
+
+       }
+
+       return true, retstr
+}
+
 func VerifyDefaultValue(raw string) bool {
 
        for _, c := range raw {
index 6dacb5ebd7a3b34bc35306335687a47e2a0832da..08ed3d7cdee20d9052695975707689f268c2d143 100644 (file)
@@ -555,6 +555,34 @@ func DeleteArticle(media_key string) error {
 
        this_article_path := articlePath + media_key + "." + ms.Extension
 
+       article_file_b, err := os.ReadFile(this_article_path)
+
+       if err != nil {
+
+               return fmt.Errorf("failed to delete article: article file: %s", err.Error())
+       }
+
+       associatedTargets, err := GetAssociateMediaKeysForEditorjsSrc(article_file_b)
+
+       if err != nil {
+
+               return fmt.Errorf("failed to delete article: %s", err.Error())
+
+       }
+
+       atLen := len(associatedTargets)
+
+       for i := 0; i < atLen; i++ {
+
+               err := DeleteMedia(associatedTargets[i])
+
+               if err != nil {
+
+                       return fmt.Errorf("failed to delete associated key: %s", err.Error())
+               }
+
+       }
+
        err = os.Remove(this_article_path)
 
        if err != nil {
@@ -654,6 +682,49 @@ func UploadImage(c *gin.Context, file *multipart.FileHeader, filename string, ne
        return nil
 }
 
+func DownloadMedia(c *gin.Context, watchId string) error {
+
+       ms, err := GetByMediaKeyFromMedia(watchId)
+
+       if ms == nil {
+
+               return fmt.Errorf("failed to download media: %s", err.Error())
+
+       }
+
+       this_media_path := ""
+
+       if ms.Type == "image" {
+
+               this_media_path = imagePath + watchId + "." + ms.Extension
+
+       } else if ms.Type == "video" {
+
+               this_media_path = videoPath + watchId + "." + ms.Extension
+
+       }
+
+       if _, err := os.Stat(this_media_path); err != nil {
+
+               return err
+
+       }
+
+       if ms.Type == "image" {
+
+               c.Header("Content-Type", "image/"+ms.Extension)
+
+       } else if ms.Type == "video" {
+
+               c.Header("Content-Type", "video/"+ms.Extension)
+
+       }
+
+       c.File(this_media_path)
+
+       return nil
+}
+
 func DownloadImage(c *gin.Context, watchId string) error {
 
        ms, err := GetByMediaKeyFromMedia(watchId)
@@ -721,6 +792,55 @@ func UploadVideo(c *gin.Context, file *multipart.FileHeader, filename string, ne
        return nil
 }
 
+func DeleteMedia(media_key string) error {
+
+       var ms MediaStruct
+
+       this_file_path := mediaPath + media_key + ".json"
+
+       file_b, err := os.ReadFile(this_file_path)
+
+       if err != nil {
+
+               return fmt.Errorf("failed to delete media: %s", err.Error())
+
+       }
+
+       err = json.Unmarshal(file_b, &ms)
+
+       if err != nil {
+
+               return fmt.Errorf("failed to delete media: marshal: %s", err.Error())
+       }
+
+       var this_media_path string
+
+       if ms.Type == "image" {
+
+               this_media_path = imagePath + media_key + "." + ms.Extension
+
+       } else if ms.Type == "video" {
+
+               this_media_path = videoPath + media_key + "." + ms.Extension
+       }
+
+       err = os.Remove(this_media_path)
+
+       if err != nil {
+
+               return fmt.Errorf("failed to delete media: rm: %s", err.Error())
+       }
+
+       err = os.Remove(this_file_path)
+
+       if err != nil {
+
+               return fmt.Errorf("failed to delete media: rmkey: %s", err.Error())
+       }
+
+       return nil
+}
+
 func DeleteVideo(media_key string) error {
 
        var ms MediaStruct
diff --git a/pkg/dbquery/source.go b/pkg/dbquery/source.go
new file mode 100644 (file)
index 0000000..96baef5
--- /dev/null
@@ -0,0 +1,84 @@
+package dbquery
+
+import (
+       "encoding/json"
+       "fmt"
+       "strings"
+)
+
+func GetAssociateMediaKeysForEditorjsSrc(rawArticle []byte) ([]string, error) {
+
+       var retlist []string
+
+       var editorjsSrc map[string]interface{}
+
+       err := json.Unmarshal(rawArticle, &editorjsSrc)
+
+       if err != nil {
+
+               return nil, fmt.Errorf("failed to unmarshal: %s", err.Error())
+
+       }
+
+       blocks, okay := editorjsSrc["blocks"]
+
+       if !okay {
+
+               return nil, fmt.Errorf("invalid format: %s", "no blocks")
+       }
+
+       blocksList := blocks.([]interface{})
+
+       blocksLen := len(blocksList)
+
+       for i := 0; i < blocksLen; i++ {
+
+               blockObj := blocksList[i].(map[string]interface{})
+
+               objType, okay := blockObj["type"]
+
+               if !okay {
+                       continue
+               }
+
+               if objType != "image" {
+                       continue
+               }
+
+               objData, okay := blockObj["data"]
+
+               if !okay {
+                       continue
+               }
+
+               objFields := objData.(map[string]interface{})
+
+               fileField, okay := objFields["file"]
+
+               if !okay {
+                       continue
+               }
+
+               targetProps := fileField.(map[string]interface{})
+
+               urlTarget, okay := targetProps["url"]
+
+               if !okay {
+                       continue
+               }
+
+               target := urlTarget.(string)
+
+               pathList := strings.Split(target, "/")
+
+               keyExt := pathList[len(pathList)-1]
+
+               keyExtList := strings.Split(keyExt, ".")
+
+               key := keyExtList[0]
+
+               retlist = append(retlist, key)
+       }
+
+       return retlist, nil
+}
index 2f0ca3122475378e26e16a932f83d78a39eb09d7..54b59977e7288fe11b7bf6ecdc5484b6e9386b2d 100644 (file)
@@ -14,6 +14,8 @@ import (
        pkgutils "github.com/seantywork/sorrylinus-again/pkg/utils"
 )
 
+var EXTENSION_ALLOWLIST []string
+
 type ArticleInfo struct {
        Title   string `json:"title"`
        Content string `json:"content"`
@@ -159,13 +161,13 @@ func GetArticleContentById(c *gin.Context) {
 
 }
 
-func PostImageUpload(c *gin.Context) {
+func PostMediaUpload(c *gin.Context) {
 
        _, my_type, _ := pkgauth.WhoAmI(c)
 
        if my_type != "admin" {
 
-               fmt.Printf("image upload: not admin\n")
+               fmt.Printf("media upload: not admin\n")
 
                c.JSON(http.StatusForbidden, com.SERVER_RE{Status: "error", Reply: "you're not admin"})
 
@@ -175,6 +177,13 @@ func PostImageUpload(c *gin.Context) {
 
        file, _ := c.FormFile("file")
 
+       rawMediaType := file.Header.Get("Content-Type")
+
+       mediaProplist := strings.Split(rawMediaType, "/")
+
+       mediaType := mediaProplist[0]
+       mediaExt := mediaProplist[1]
+
        f_name := file.Filename
 
        f_name_list := strings.Split(f_name, ".")
@@ -204,11 +213,21 @@ func PostImageUpload(c *gin.Context) {
 
        }
 
-       fmt.Printf("received: %s, size: %d\n", file.Filename, file.Size)
+       fmt.Printf("received: %s, size: %d, type: %s\n", file.Filename, file.Size, rawMediaType)
 
        file_name, _ := pkgutils.GetRandomHex(32)
 
-       err := dbquery.UploadImage(c, file, v_fname, file_name, extension)
+       var err error
+
+       if mediaType == "image" {
+
+               err = dbquery.UploadImage(c, file, v_fname, file_name, mediaExt)
+
+       } else if mediaType == "video" {
+
+               err = dbquery.UploadVideo(c, file, v_fname, file_name, mediaExt)
+
+       }
 
        if err != nil {
 
@@ -220,17 +239,21 @@ func PostImageUpload(c *gin.Context) {
 
        }
 
-       c.JSON(http.StatusOK, com.SERVER_RE{Status: "success", Reply: file_name})
+       client_file_name := file_name + "." + mediaExt
+
+       c.JSON(http.StatusOK, com.SERVER_RE{Status: "success", Reply: client_file_name})
 
 }
 
-func GetImageContentById(c *gin.Context) {
+func GetMediaContentById(c *gin.Context) {
 
        watchId := c.Param("contentId")
 
-       if !pkgauth.VerifyCodeNameValue(watchId) {
+       check, san := pkgauth.VerifyCodeNameValueWithStop(watchId, '.')
+
+       if !check {
 
-               fmt.Printf("download image: illegal: %s\n", watchId)
+               fmt.Printf("download media: illegal: %s\n", watchId)
 
                c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
 
@@ -238,11 +261,11 @@ func GetImageContentById(c *gin.Context) {
 
        }
 
-       err := dbquery.DownloadImage(c, watchId)
+       err := dbquery.DownloadMedia(c, san)
 
        if err != nil {
 
-               fmt.Printf("download image: %s\n", err.Error())
+               fmt.Printf("download media: %s\n", err.Error())
 
                c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
 
@@ -250,5 +273,5 @@ func GetImageContentById(c *gin.Context) {
 
        }
 
-       fmt.Println("image download success")
+       fmt.Println("media download success")
 }
diff --git a/pkg/edition/edition_etc.go b/pkg/edition/edition_etc.go
new file mode 100644 (file)
index 0000000..0bcad25
--- /dev/null
@@ -0,0 +1,256 @@
+package edition
+
+import (
+       "fmt"
+       "net/http"
+       "strings"
+
+       "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"
+       pkgdbq "github.com/seantywork/sorrylinus-again/pkg/dbquery"
+       pkgutils "github.com/seantywork/sorrylinus-again/pkg/utils"
+)
+
+func PostVideoUpload(c *gin.Context) {
+
+       _, my_type, _ := pkgauth.WhoAmI(c)
+
+       if my_type != "admin" {
+
+               fmt.Printf("video upload: not admin\n")
+
+               c.JSON(http.StatusForbidden, com.SERVER_RE{Status: "error", Reply: "you're not admin"})
+
+               return
+
+       }
+
+       file, _ := c.FormFile("file")
+
+       f_name := file.Filename
+
+       f_name_list := strings.Split(f_name, ".")
+
+       f_name_len := len(f_name_list)
+
+       if f_name_len < 1 {
+
+               fmt.Println("no extension specified")
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+       }
+
+       v_fname := pkgauth.SanitizePlainNameValue(f_name_list[0])
+
+       extension := f_name_list[f_name_len-1]
+
+       if !pkgutils.CheckIfSliceContains[string](EXTENSION_ALLOWLIST, extension) {
+
+               fmt.Println("extension not allowed")
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+
+       }
+
+       fmt.Printf("received: %s, size: %d\n", file.Filename, file.Size)
+
+       file_name, _ := pkgutils.GetRandomHex(32)
+
+       err := pkgdbq.UploadVideo(c, file, v_fname, file_name, extension)
+
+       if err != nil {
+
+               fmt.Println(err.Error())
+
+               c.JSON(http.StatusInternalServerError, com.SERVER_RE{Status: "error", Reply: "failed to save"})
+
+               return
+
+       }
+
+       c.JSON(http.StatusOK, com.SERVER_RE{Status: "success", Reply: "uploaded"})
+
+}
+
+func PostVideoDelete(c *gin.Context) {
+
+       _, my_type, _ := pkgauth.WhoAmI(c)
+
+       if my_type != "admin" {
+
+               fmt.Printf("video delete: not admin\n")
+
+               c.JSON(http.StatusForbidden, com.SERVER_RE{Status: "error", Reply: "you're not admin"})
+
+               return
+
+       }
+
+       fmt.Println("delete video")
+
+       var req com.CLIENT_REQ
+
+       if err := c.BindJSON(&req); err != nil {
+
+               fmt.Printf("video delete: failed to bind: %s\n", err.Error())
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+       }
+
+       if !pkgauth.VerifyCodeNameValue(req.Data) {
+
+               fmt.Printf("video name verification failed: %s\n", req.Data)
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+
+       }
+
+       err := dbquery.DeleteVideo(req.Data)
+
+       if err != nil {
+
+               fmt.Printf("video delete: %s\n", err.Error())
+
+               c.JSON(http.StatusInternalServerError, com.SERVER_RE{Status: "error", Reply: "failed delete"})
+
+               return
+
+       }
+
+       c.JSON(http.StatusOK, com.SERVER_RE{Status: "success", Reply: "deleted"})
+
+}
+
+func GetVideoContentByID(c *gin.Context) {
+
+       watchId := c.Param("contentId")
+
+       if !pkgauth.VerifyCodeNameValue(watchId) {
+
+               fmt.Printf("download video: illegal: %s\n", watchId)
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+
+       }
+
+       err := pkgdbq.DownloadVideo(c, watchId)
+
+       if err != nil {
+
+               fmt.Printf("download video: %s\n", err.Error())
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+
+       }
+
+       fmt.Println("video download success")
+
+}
+
+func PostImageUpload(c *gin.Context) {
+
+       _, my_type, _ := pkgauth.WhoAmI(c)
+
+       if my_type != "admin" {
+
+               fmt.Printf("image upload: not admin\n")
+
+               c.JSON(http.StatusForbidden, com.SERVER_RE{Status: "error", Reply: "you're not admin"})
+
+               return
+
+       }
+
+       file, _ := c.FormFile("file")
+
+       f_name := file.Filename
+
+       f_name_list := strings.Split(f_name, ".")
+
+       f_name_len := len(f_name_list)
+
+       if f_name_len < 1 {
+
+               fmt.Println("no extension specified")
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+       }
+
+       v_fname := pkgauth.SanitizePlainNameValue(f_name_list[0])
+
+       extension := f_name_list[f_name_len-1]
+
+       if !pkgutils.CheckIfSliceContains[string](EXTENSION_ALLOWLIST, extension) {
+
+               fmt.Println("extension not allowed")
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+
+       }
+
+       fmt.Printf("received: %s, size: %d\n", file.Filename, file.Size)
+
+       file_name, _ := pkgutils.GetRandomHex(32)
+
+       err := dbquery.UploadImage(c, file, v_fname, file_name, extension)
+
+       if err != nil {
+
+               fmt.Println(err.Error())
+
+               c.JSON(http.StatusInternalServerError, com.SERVER_RE{Status: "error", Reply: "failed to save"})
+
+               return
+
+       }
+
+       c.JSON(http.StatusOK, com.SERVER_RE{Status: "success", Reply: file_name})
+
+}
+
+func GetImageContentById(c *gin.Context) {
+
+       watchId := c.Param("contentId")
+
+       if !pkgauth.VerifyCodeNameValue(watchId) {
+
+               fmt.Printf("download image: illegal: %s\n", watchId)
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+
+       }
+
+       err := dbquery.DownloadImage(c, watchId)
+
+       if err != nil {
+
+               fmt.Printf("download image: %s\n", err.Error())
+
+               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
+
+               return
+
+       }
+
+       fmt.Println("image download success")
+}
diff --git a/pkg/edition/edition_video.go b/pkg/edition/edition_video.go
deleted file mode 100644 (file)
index ee31e1b..0000000
+++ /dev/null
@@ -1,164 +0,0 @@
-package edition
-
-import (
-       "fmt"
-       "net/http"
-       "strings"
-
-       "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"
-       pkgdbq "github.com/seantywork/sorrylinus-again/pkg/dbquery"
-       pkgutils "github.com/seantywork/sorrylinus-again/pkg/utils"
-)
-
-var EXTENSION_ALLOWLIST []string
-
-func PostVideoUpload(c *gin.Context) {
-
-       _, my_type, _ := pkgauth.WhoAmI(c)
-
-       if my_type != "admin" {
-
-               fmt.Printf("video upload: not admin\n")
-
-               c.JSON(http.StatusForbidden, com.SERVER_RE{Status: "error", Reply: "you're not admin"})
-
-               return
-
-       }
-
-       file, _ := c.FormFile("file")
-
-       f_name := file.Filename
-
-       f_name_list := strings.Split(f_name, ".")
-
-       f_name_len := len(f_name_list)
-
-       if f_name_len < 1 {
-
-               fmt.Println("no extension specified")
-
-               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
-
-               return
-       }
-
-       v_fname := pkgauth.SanitizePlainNameValue(f_name_list[0])
-
-       extension := f_name_list[f_name_len-1]
-
-       if !pkgutils.CheckIfSliceContains[string](EXTENSION_ALLOWLIST, extension) {
-
-               fmt.Println("extension not allowed")
-
-               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
-
-               return
-
-       }
-
-       fmt.Printf("received: %s, size: %d\n", file.Filename, file.Size)
-
-       file_name, _ := pkgutils.GetRandomHex(32)
-
-       err := pkgdbq.UploadVideo(c, file, v_fname, file_name, extension)
-
-       if err != nil {
-
-               fmt.Println(err.Error())
-
-               c.JSON(http.StatusInternalServerError, com.SERVER_RE{Status: "error", Reply: "failed to save"})
-
-               return
-
-       }
-
-       c.JSON(http.StatusOK, com.SERVER_RE{Status: "success", Reply: "uploaded"})
-
-}
-
-func PostVideoDelete(c *gin.Context) {
-
-       _, my_type, _ := pkgauth.WhoAmI(c)
-
-       if my_type != "admin" {
-
-               fmt.Printf("video delete: not admin\n")
-
-               c.JSON(http.StatusForbidden, com.SERVER_RE{Status: "error", Reply: "you're not admin"})
-
-               return
-
-       }
-
-       fmt.Println("delete video")
-
-       var req com.CLIENT_REQ
-
-       if err := c.BindJSON(&req); err != nil {
-
-               fmt.Printf("video delete: failed to bind: %s\n", err.Error())
-
-               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
-
-               return
-       }
-
-       if !pkgauth.VerifyCodeNameValue(req.Data) {
-
-               fmt.Printf("video name verification failed: %s\n", req.Data)
-
-               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
-
-               return
-
-       }
-
-       err := dbquery.DeleteVideo(req.Data)
-
-       if err != nil {
-
-               fmt.Printf("video delete: %s\n", err.Error())
-
-               c.JSON(http.StatusInternalServerError, com.SERVER_RE{Status: "error", Reply: "failed delete"})
-
-               return
-
-       }
-
-       c.JSON(http.StatusOK, com.SERVER_RE{Status: "success", Reply: "deleted"})
-
-}
-
-func GetVideoContentByID(c *gin.Context) {
-
-       watchId := c.Param("contentId")
-
-       if !pkgauth.VerifyCodeNameValue(watchId) {
-
-               fmt.Printf("download video: illegal: %s\n", watchId)
-
-               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
-
-               return
-
-       }
-
-       err := pkgdbq.DownloadVideo(c, watchId)
-
-       if err != nil {
-
-               fmt.Printf("download video: %s\n", err.Error())
-
-               c.JSON(http.StatusBadRequest, com.SERVER_RE{Status: "error", Reply: "invalid format"})
-
-               return
-
-       }
-
-       fmt.Println("video download success")
-
-}
index 435b97b49abf1e01f4deb591068c11d8f3294e44..d80e229bd79fbea5c0a9a13eea72f4613eafe2e6 100644 (file)
@@ -9,14 +9,14 @@ const ImageTool = window.ImageTool;
 
 
 
-async function imageUploader(fileData){
+async function mediaUploader(fileData){
 
   const form = new FormData()
 
   form.append("file", fileData)
 
 
-  let resp = await fetch("/api/image/upload", {
+  let resp = await fetch("/api/media/upload", {
         body: form,
         method: "POST"
   })
@@ -101,7 +101,7 @@ var editor = new EditorJS({
             uploadByFile(file){
 
 
-              return imageUploader(file).then(function(data){
+              return mediaUploader(file).then(function(data){
 
                 if(data.status != "success"){
 
@@ -114,7 +114,7 @@ var editor = new EditorJS({
                   success: 1,
                   file: {
 
-                    url: '/api/image/c/' + data.reply,
+                    url: '/api/media/c/' + data.reply,
               
                   }
                 }
@@ -296,7 +296,7 @@ async function getArticleList(){
 
     for(let i = 0; i < contentEntry.entry.length; i ++){
 
-        if(contentEntry.entry[i].type != "video"){
+        if(contentEntry.entry[i].type != "article"){
             continue
         }
 
index 9dfe583d8f6574c103dd30b67bfaf99a721160ab..9bcf62192f638f3e081ab085855d865604006695 100644 (file)
@@ -4,6 +4,7 @@ import (
        "encoding/json"
        "fmt"
        "image/color"
+       "os"
 
        "gocv.io/x/gocv"
 
@@ -12,6 +13,7 @@ import (
        "github.com/wimspaargaren/yolov3"
 
        "github.com/gorilla/websocket"
+       "github.com/seantywork/sorrylinus-again/pkg/dbquery"
 )
 
 func turn_on_gui_with_video() {
@@ -254,6 +256,23 @@ func sorrylinus_roundtrip() {
 
        }
 
+}
+func test_editorjs_parse() {
+
+       file_b, _ := os.ReadFile("./test.json")
+
+       tlist, err := dbquery.GetAssociateMediaKeysForEditorjsSrc(file_b)
+
+       if err != nil {
+
+               fmt.Println(err.Error())
+
+               return
+
+       }
+
+       fmt.Println(tlist)
+
 }
 
 func main() {
@@ -266,6 +285,8 @@ func main() {
 
        // print_bits()
 
-       sorrylinus_roundtrip()
+       //sorrylinus_roundtrip()
+
+       test_editorjs_parse()
 
 }
diff --git a/test/test.json b/test/test.json
new file mode 100644 (file)
index 0000000..19dcdd0
--- /dev/null
@@ -0,0 +1 @@
+{"time":1721723840628,"blocks":[{"id":"vXuUC7Cunc","type":"header","data":{"text":"Title","level":2}},{"id":"hMiWbD8Qgk","type":"paragraph","data":{"text":"Write your thing"}},{"id":"SrbxGY-2kk","type":"image","data":{"caption":"","withBorder":false,"withBackground":false,"stretched":false,"file":{"url":"/api/media/c/70e941dfe04edc17dfdd37f2139683ab2bb97e1a2af9f5ae5dbc1d4c2faf178b.jpeg"}}},{"id":"nVgza_srP_","type":"image","data":{"caption":"","withBorder":false,"withBackground":false,"stretched":false,"file":{"url":"/api/media/c/e00d6e6d412260c4394be68ce9b5e14923a883d5c9cc54b3ac3c6b96b6f1d834.mp4"}}}],"version":"2.30.2"}
\ No newline at end of file
index d60760d8e87b8647c3f690bba676cdb34df23761..604a61666ce22c290b26683929fae3afc0f5bf51 100644 (file)
@@ -2,11 +2,11 @@
 <!doctype html>
 <html>
   <head>
-    <title>sorrylinus again</title>
+    <title> feebdaed.xyz </title>
   </head>
   <body>
 
-    <h1> Sorrylinus Again </h1>
+    <h1> feebdaed.xyz </h1>
 
     {{ if .logged_in }}
     <a href="/api/auth/signout"> Sign Out </a>