"encoding/json"
"fmt"
"net/http"
+ "time"
"github.com/gin-gonic/gin"
pkgauth "github.com/seantywork/sorrylinus-again/pkg/auth"
type EntryStruct struct {
Entry []struct {
- Title string `json:"title"`
- Id string `json:"id"`
- Type string `json:"type"`
+ Title string `json:"title"`
+ Id string `json:"id"`
+ Type string `json:"type"`
+ Timestamp time.Time `json:"timestamp"`
+ Author string `json:"author"`
} `json:"entry"`
}
for k, v := range em {
+ t, _ := time.Parse("2006-01-02-15-04-05", v.CreatedAt)
+
if v.Type == "article" {
entry.Entry = append(entry.Entry, struct {
- Title string `json:"title"`
- Id string `json:"id"`
- Type string `json:"type"`
+ Title string `json:"title"`
+ Id string `json:"id"`
+ Type string `json:"type"`
+ Timestamp time.Time `json:"timestamp"`
+ Author string `json:"author"`
}{
- Title: v.PlainName,
- Id: k,
- Type: "article",
+ Title: v.PlainName,
+ Id: k,
+ Type: "article",
+ Timestamp: t,
+ Author: v.Author,
})
} else {
type MediaStruct struct {
ISPublic bool `json:"is_public"`
+ CreatedAt string `json:"created_at"`
Type string `json:"type"`
Extension string `json:"extension"`
PlainName string `json:"plain_name"`
+ Author string `json:"author"`
AllowedId []string `json:"allowed_id"`
}
return nil
}
-func UploadArticle(content string, plain_name string, new_name string) error {
+func UploadArticle(author string, content string, plain_name string, new_name string) error {
ms := MediaStruct{}
+ c_time := time.Now()
+
+ c_time_fmt := c_time.Format("2006-01-02-15-04-05")
+
ms.ISPublic = true
ms.Type = "article"
ms.PlainName = plain_name
ms.Extension = "json"
+ ms.CreatedAt = c_time_fmt
+ ms.Author = author
this_file_path := mediaPath + new_name + ".json"
}
-func UploadImage(c *gin.Context, file *multipart.FileHeader, filename string, new_filename string, extension string) error {
+func UploadImage(c *gin.Context, author string, file *multipart.FileHeader, filename string, new_filename string, extension string) error {
ms := MediaStruct{}
this_image_path := imagePath + new_filename + "." + extension
+ c_time := time.Now()
+
+ c_time_fmt := c_time.Format("2006-01-02-15-04-05")
+
ms.ISPublic = true
ms.Type = "image"
ms.PlainName = filename
ms.Extension = extension
+ ms.CreatedAt = c_time_fmt
+ ms.Author = author
jb, err := json.Marshal(ms)
return nil
}
-func UploadVideo(c *gin.Context, file *multipart.FileHeader, filename string, new_filename string, extension string) error {
+func UploadVideo(c *gin.Context, author string, file *multipart.FileHeader, filename string, new_filename string, extension string) error {
ms := MediaStruct{}
this_video_path := videoPath + new_filename + "." + extension
+ c_time := time.Now()
+
+ c_time_fmt := c_time.Format("2006-01-02-15-04-05")
+
ms.ISPublic = true
ms.Type = "video"
ms.PlainName = filename
ms.Extension = extension
+ ms.CreatedAt = c_time_fmt
+ ms.Author = author
jb, err := json.Marshal(ms)
func PostArticleUpload(c *gin.Context) {
- _, my_type, _ := pkgauth.WhoAmI(c)
+ _, my_type, my_id := pkgauth.WhoAmI(c)
if my_type != "admin" {
plain_name := pkgauth.SanitizePlainNameValue(a_info.Title)
- err = dbquery.UploadArticle(a_info.Content, plain_name, new_file_name)
+ err = dbquery.UploadArticle(my_id, a_info.Content, plain_name, new_file_name)
if err != nil {
func PostMediaUpload(c *gin.Context) {
- _, my_type, _ := pkgauth.WhoAmI(c)
+ _, my_type, my_id := pkgauth.WhoAmI(c)
if my_type != "admin" {
if mediaType == "image" {
- err = dbquery.UploadImage(c, file, v_fname, file_name, mediaExt)
+ err = dbquery.UploadImage(c, my_id, file, v_fname, file_name, mediaExt)
} else if mediaType == "video" {
- err = dbquery.UploadVideo(c, file, v_fname, file_name, mediaExt)
+ err = dbquery.UploadVideo(c, my_id, file, v_fname, file_name, mediaExt)
}
func PostVideoUpload(c *gin.Context) {
- _, my_type, _ := pkgauth.WhoAmI(c)
+ _, my_type, my_id := pkgauth.WhoAmI(c)
if my_type != "admin" {
file_name, _ := pkgutils.GetRandomHex(32)
- err := pkgdbq.UploadVideo(c, file, v_fname, file_name, extension)
+ err := pkgdbq.UploadVideo(c, my_id, file, v_fname, file_name, extension)
if err != nil {
func PostImageUpload(c *gin.Context) {
- _, my_type, _ := pkgauth.WhoAmI(c)
+ _, my_type, my_id := pkgauth.WhoAmI(c)
if my_type != "admin" {
file_name, _ := pkgutils.GetRandomHex(32)
- err := dbquery.UploadImage(c, file, v_fname, file_name, extension)
+ err := dbquery.UploadImage(c, my_id, file, v_fname, file_name, extension)
if err != nil {
--- /dev/null
+
+function delayMs (ms) {
+
+ return new Promise(function(res) {
+ setTimeout(res, ms)
+ })
+}
+
+
+function getNewDateSortedList(flag, fieldName, orgList){
+
+
+ let newList = []
+
+ if(flag != "asc" && flag != "desc"){
+ return orgList
+ }
+
+
+
+ for(let i = 0; i < orgList.length; i ++){
+
+
+ let d1 = Date.parse(orgList[i][fieldName])
+
+ if(newList.length == 0){
+
+ newList.push(orgList[i])
+
+ continue
+ }
+
+ for(let j = 0; j < newList.length; j ++){
+
+
+ let d2 = Date.parse(newList[j][fieldName])
+
+
+ if(flag == "asc"){
+
+ if(d1 < d2){
+
+ newList.splice(j, 0, orgList[i])
+
+ break
+ }
+
+ if (d1 >= d2 && (j != newList.length - 1)){
+
+ continue
+
+ } else if (d1 >= d2 && (j == newList.length - 1)){
+
+ newList.push(orgList[i])
+
+ break
+ }
+
+
+ } else if(flag == "desc"){
+
+
+ if(d1 > d2){
+
+ newList.splice(j, 0, orgList[i])
+
+ break
+ }
+
+ if (d1 <= d2 && (j != newList.length - 1)){
+
+ continue
+
+ } else if (d1 <= d2 && (j == newList.length - 1)){
+
+ newList.push(orgList[i])
+
+ break
+ }
+
+
+ }
+
+
+
+
+ }
+
+ }
+
+
+ return newList
+
+
+
+
+
+}
\ No newline at end of file
} else {
- for(let i = 0; i < contentEntry.entry.length; i ++){
-
- contentReader.innerHTML += `
- <a href="/content/${contentEntry.entry[i].type}/${contentEntry.entry[i].id}">
- ${contentEntry.entry[i].title}
- </a>
- <br>
- `
+ let sortedEntry = getNewDateSortedList("desc", "timestamp", contentEntry.entry)
+
+ for(let i = 0; i < sortedEntry.length; i ++){
+
+ contentReader.innerHTML += `
+ <a href="/content/${sortedEntry[i].type}/${sortedEntry[i].id}">
+ ${sortedEntry[i].title}
+ </a> [${sortedEntry[i].author}:${sortedEntry[i].timestamp}]
+ <input type="button" onclick="deleteArticle('${sortedEntry[i].id}')" value="delete">
+ <br>
+ `
}
}
contentReader.innerHTML = ""
- for(let i = 0; i < contentEntry.entry.length; i ++){
+ let sortedEntry = getNewDateSortedList("desc", "timestamp", contentEntry.entry)
- if(contentEntry.entry[i].type != "article"){
- continue
- }
+ for(let i = 0; i < sortedEntry.length; i ++){
contentReader.innerHTML += `
- <a href="/content/${contentEntry.entry[i].type}/${contentEntry.entry[i].id}">
- ${contentEntry.entry[i].title}
- </a>
- <input type="button" onclick="deleteArticle('${contentEntry.entry[i].id}')" value="delete">
+ <a href="/content/${sortedEntry[i].type}/${sortedEntry[i].id}">
+ ${sortedEntry[i].title}
+ </a> [${sortedEntry[i].author}:${sortedEntry[i].timestamp}]
+ <input type="button" onclick="deleteArticle('${sortedEntry[i].id}')" value="delete">
<br>
`
articleCount += 1
}
-function delayMs (ms) {
-
- return new Promise(function(res) {
- setTimeout(res, ms)
- })
-}
-
async function testCCTV(){
<a href="/mypage"> My Page </a>
+ <script src="/public/js/common.js"></script>
<script src="/public/js/index/index.js"></script>
</body>
</html>
<div id="article-reader"></div>
-
+ <script src="/public/js/common.js"></script>
<script src="/public/js/mypage/article.js"></script>
</body>
</body>
+ <script src="/public/js/common.js"></script>
<script src="/public/js/mypage/index.js"></script>