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
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)
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
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 {
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 {
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)
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
--- /dev/null
+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
+}
pkgutils "github.com/seantywork/sorrylinus-again/pkg/utils"
)
+var EXTENSION_ALLOWLIST []string
+
type ArticleInfo struct {
Title string `json:"title"`
Content string `json:"content"`
}
-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"})
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, ".")
}
- 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 {
}
- 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"})
}
- 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"})
}
- fmt.Println("image download success")
+ fmt.Println("media download success")
}
--- /dev/null
+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")
+}
+++ /dev/null
-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")
-
-}
-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"
})
uploadByFile(file){
- return imageUploader(file).then(function(data){
+ return mediaUploader(file).then(function(data){
if(data.status != "success"){
success: 1,
file: {
- url: '/api/image/c/' + data.reply,
+ url: '/api/media/c/' + data.reply,
}
}
for(let i = 0; i < contentEntry.entry.length; i ++){
- if(contentEntry.entry[i].type != "video"){
+ if(contentEntry.entry[i].type != "article"){
continue
}
"encoding/json"
"fmt"
"image/color"
+ "os"
"gocv.io/x/gocv"
"github.com/wimspaargaren/yolov3"
"github.com/gorilla/websocket"
+ "github.com/seantywork/sorrylinus-again/pkg/dbquery"
)
func turn_on_gui_with_video() {
}
+}
+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() {
// print_bits()
- sorrylinus_roundtrip()
+ //sorrylinus_roundtrip()
+
+ test_editorjs_parse()
}
--- /dev/null
+{"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
<!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>