|
@@ -6,6 +6,7 @@ import (
|
|
|
|
|
|
"net/http"
|
|
|
"strconv"
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
@@ -274,3 +275,84 @@ func DownloadTorrentHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
w.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s.torrent\"", torrent.Name))
|
|
|
http.ServeFile(w, r, fmt.Sprintf("files/torrents/%s.torrent", torrent.Hash))
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+func ForumHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
+ forumpath := mux.Vars(r)["rest"]
|
|
|
+ w.Write([]byte("now at forum\n"))
|
|
|
+ fmt.Println(len(forumpath))
|
|
|
+ if len(forumpath) == 0 {
|
|
|
+ // Serve forum root
|
|
|
+ w.Write([]byte("forum root\n"))
|
|
|
+ rootUuid := "7e92ebbd-750f-4a34-ad62-bc6a4f47cbfa"
|
|
|
+ folders, err := dBConnector.TakeChildFolders(rootUuid, 10)
|
|
|
+ if err != nil {
|
|
|
+ w.Write([]byte("error getting folders from server"))
|
|
|
+ fmt.Println("ERROR:", err)
|
|
|
+ }
|
|
|
+ for _, folder := range folders {
|
|
|
+ w.Write([]byte(fmt.Sprintf("<a href=%s>%s</a>\n", (r.URL.String()+"/"+folder.Snake), folder.Title)))
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(forumpath) > 0 {
|
|
|
+ // Serve subfolders
|
|
|
+ dirs := strings.Split(forumpath,"/")
|
|
|
+
|
|
|
+ //var currentUuid string
|
|
|
+ var parentUuid string
|
|
|
+ parentUuid = "7e92ebbd-750f-4a34-ad62-bc6a4f47cbfa"
|
|
|
+
|
|
|
+ var folder Folder
|
|
|
+ for _, dir :=range dirs {
|
|
|
+ var err error
|
|
|
+ folder, err = dBConnector.TakeChildFolderBySnake(parentUuid, dir)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("ERROR:", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if folder == (Folder{}) {
|
|
|
+ // Child not found
|
|
|
+ w.Write([]byte(fmt.Sprintf("\nNot found %v", dir)))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ parentUuid = folder.Uuid
|
|
|
+
|
|
|
+ w.Write([]byte(fmt.Sprintf("/%v", dir)))
|
|
|
+ }
|
|
|
+
|
|
|
+ w.Write([]byte(fmt.Sprintf("\nType of %v is: %d\n", folder.Title, folder.Type)))
|
|
|
+
|
|
|
+ if folder.Type == 1 {
|
|
|
+ // Load subfolders
|
|
|
+ folders, err := dBConnector.TakeChildFolders(folder.Uuid, 10)
|
|
|
+ if err != nil {
|
|
|
+ w.Write([]byte("error getting folders from server"))
|
|
|
+ fmt.Println("ERROR:", err)
|
|
|
+ }
|
|
|
+ for _, folder := range folders {
|
|
|
+ w.Write([]byte(fmt.Sprintf("<a href=%s>%s type:%d</a>\n", (r.URL.String()+"/"+folder.Snake), folder.Title, folder.Type)))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if folder.Type == 2 {
|
|
|
+ // Load messages
|
|
|
+ messages, err := dBConnector.TakeTopicMessages(folder.Uuid, 0)
|
|
|
+ if err != nil {
|
|
|
+ w.Write([]byte("error getting messages from server"))
|
|
|
+ fmt.Println("ERROR:", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(messages) == 0 {
|
|
|
+ // Should be imposible
|
|
|
+ w.Write([]byte("No messages in this topic"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, message := range messages {
|
|
|
+ w.Write([]byte(fmt.Sprintf("Author:\n%s\n Time:\n %s\n Text:\n %s\n\n", message.Author, message.Time, message.Text)))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+ }
|
|
|
+}
|