diff --git a/README.md b/README.md index 17909ba..92de6d0 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ # padArchiver Tool to store a pad (from the link) into IPFS and Git. -## webServer +All the necessary files are in the /build directory. + +## 1.- webServer This is a webserver that automatically generates a web from the pads directories and files stored. -To run: +To run, inside 'build' directory: ``` ./webServer ``` -## listPadsImporter +## 2.- listPadsImporter This is to import all pads from the json file 'list.json'. Just need to edit the json file, for example: ```json @@ -33,12 +35,12 @@ Just need to edit the json file, for example: ] } ``` -And then execute the importer: +To run, inside 'build' directory: ``` ./importFromList ``` -## apiServer +## 3.- apiServer This is an API to run in localhost. #### Run @@ -56,7 +58,7 @@ To run using the compiled binary: } ``` -- Execute the API server: +- Execute the API server, inside the directory 'build': ``` > ./padArchiver-APIserver ``` @@ -108,8 +110,8 @@ this returns: ``` The IPFS hash is also added to the first line of the document, before adding the document to Git. -## cli -To run the CLI, just need to run: +## 4.- cli +To run the CLI, just need to run inside the directory 'build': ``` ./padArchiver-cli ``` diff --git a/apiServer/apiServer b/apiServer/apiServer index 581a087..653fb4b 100755 Binary files a/apiServer/apiServer and b/apiServer/apiServer differ diff --git a/apiServer/main.go b/apiServer/main.go index 37ae167..6398a75 100644 --- a/apiServer/main.go +++ b/apiServer/main.go @@ -89,7 +89,7 @@ func PostStorePad(w http.ResponseWriter, r *http.Request) { } defer r.Body.Close() - ipfsHash, err := repo.StorePad(pad.Link, pad.Dir, pad.Title) + ipfsHash, err := repo.StorePad(pad.Link, pad.Dir, pad.Title, true) if err != nil { http.Error(w, "error storing pad", http.StatusConflict) } diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..69e5a8a --- /dev/null +++ b/build.sh @@ -0,0 +1,31 @@ +echo "starting build process" +rm -rf build +mkdir build + +cd webServer +echo "building webServer" +go build +cp webServer ../build +cp -r templates ../build +cd .. + +cd listPadsImporter +echo "building listPadsImporter" +go build +cp listPadsImporter ../build +cd .. + +cd apiServer +echo "building apiServer" +go build +cp apiServer ../build +cd .. + + +cd cli +echo "building cli" +go build +cp cli ../build +cd .. + +echo "build process complete, all the necessary files are in the /build directory" diff --git a/build/apiServer b/build/apiServer new file mode 100755 index 0000000..653fb4b Binary files /dev/null and b/build/apiServer differ diff --git a/build/cli b/build/cli new file mode 100755 index 0000000..8829e45 Binary files /dev/null and b/build/cli differ diff --git a/build/listPadsImporter b/build/listPadsImporter new file mode 100755 index 0000000..13459ac Binary files /dev/null and b/build/listPadsImporter differ diff --git a/build/templates/menuTemplate.html b/build/templates/menuTemplate.html new file mode 100644 index 0000000..05f1567 --- /dev/null +++ b/build/templates/menuTemplate.html @@ -0,0 +1,18 @@ + diff --git a/build/templates/pageTemplate.html b/build/templates/pageTemplate.html new file mode 100644 index 0000000..325d935 --- /dev/null +++ b/build/templates/pageTemplate.html @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + padArchiver + + + + + +

+
+
+
+ {{.MenuContent}} +
+
+

{{.Title}}

+
{{.Content}} +
+
+ +
+ + + + + + + + + + + + + + diff --git a/build/templates/wellcome.md b/build/templates/wellcome.md new file mode 100644 index 0000000..ea67dbf --- /dev/null +++ b/build/templates/wellcome.md @@ -0,0 +1,7 @@ +### Wellcome to the padArchiver. +Select one pad from the side menu to visualize. + +![golang logo](https://seeklogo.com/images/G/go-logo-046185B647-seeklogo.com.png) + + +This is the wellcome message, from the 'templates/wellcome.md' file. diff --git a/build/webServer b/build/webServer new file mode 100755 index 0000000..94ad0f6 Binary files /dev/null and b/build/webServer differ diff --git a/cli/cli b/cli/cli index 1c76739..8829e45 100755 Binary files a/cli/cli and b/cli/cli differ diff --git a/cli/main.go b/cli/main.go index 2901c16..8bb8e70 100644 --- a/cli/main.go +++ b/cli/main.go @@ -87,7 +87,7 @@ func option1() { repo := padArchiver.OpenRepo(repoID) - ipfsHash, err := repo.StorePad(link, subdirectory, title) + ipfsHash, err := repo.StorePad(link, subdirectory, title, true) if err != nil { color.Red(err.Error()) } else { diff --git a/listPadsImporter/list.json b/listPadsImporter/list.json index 6837beb..67a185b 100644 --- a/listPadsImporter/list.json +++ b/listPadsImporter/list.json @@ -15,6 +15,11 @@ "link": "http://board.net/p/pad3", "dir": "Group2", "title": "Pad3" + }, + { + "link": "http://board.net/p/loremipsum", + "dir": "SubArea1", + "title": "loremipsum" } ] } diff --git a/listPadsImporter/listPadsImporter b/listPadsImporter/listPadsImporter index 11bdbb1..13459ac 100755 Binary files a/listPadsImporter/listPadsImporter and b/listPadsImporter/listPadsImporter differ diff --git a/listPadsImporter/main.go b/listPadsImporter/main.go index e41259c..89d90b3 100644 --- a/listPadsImporter/main.go +++ b/listPadsImporter/main.go @@ -58,7 +58,7 @@ func main() { fmt.Println(" link: " + pad.Link) fmt.Println(" dir: " + pad.Dir) fmt.Println(" title: " + pad.Title) - ipfsHash, err := repo.StorePad(pad.Link, pad.Dir, pad.Title) + ipfsHash, err := repo.StorePad(pad.Link, pad.Dir, pad.Title, false) check(err) fmt.Println(" ipfs hash: " + ipfsHash) } diff --git a/padArchiver.go b/padArchiver.go index f8bbec3..1a7fc18 100644 --- a/padArchiver.go +++ b/padArchiver.go @@ -23,13 +23,16 @@ func OpenRepo(directory string) Repo { return repo } -func (repo *Repo) StorePad(link string, directory string, title string) (string, error) { +func (repo *Repo) StorePad(link string, directory string, title string, ipfsActive bool) (string, error) { path, err := repo.GetPad(link, "md", directory, title) if err != nil { color.Red(err.Error()) return "", err } + if !ipfsActive { + return "", nil + } hash, err := IpfsAdd(path) if err != nil { color.Red(err.Error()) diff --git a/padArchiver_test.go b/padArchiver_test.go index eac4225..84ad262 100644 --- a/padArchiver_test.go +++ b/padArchiver_test.go @@ -11,7 +11,7 @@ const checkIcon = "\xE2\x9C\x94 " func TestAddPad(t *testing.T) { color.Blue("TestAddPad") repo := OpenRepo("Repo01") - _, err := repo.StorePad("http://board.net/p/pad1", "Group1", "pad1") + _, err := repo.StorePad("http://board.net/p/pad1", "Group1", "pad1", true) if err == nil { color.Green(checkIcon + "checked AddPad") diff --git a/webServer/main.go b/webServer/main.go index 1a7ceaf..54976f0 100644 --- a/webServer/main.go +++ b/webServer/main.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "html/template" "log" "net/http" @@ -13,15 +14,19 @@ import ( ) type ItemModel struct { - Name string - Path string - IsDir bool - Content template.HTML + Name string + Path string + IsDir bool } type MenuModel struct { PageTitle string Items []ItemModel } +type PageModel struct { + Title string + MenuContent template.HTML + Content template.HTML +} func main() { @@ -35,7 +40,7 @@ func main() { log.Fatal(http.ListenAndServe(":8080", router)) } -func generateMenu(dirpath string) MenuModel { +func generateMenuItems(dirpath string) MenuModel { var menuPage MenuModel menuPage.PageTitle = "padArchiver - Menu" _ = filepath.Walk(padArchiver.Storage+dirpath, func(path string, f os.FileInfo, err error) error { @@ -56,6 +61,14 @@ func generateMenu(dirpath string) MenuModel { }) return menuPage } +func generateMenuHTML(dirpath string) template.HTML { + menuItems := generateMenuItems(dirpath) + tmplMenu := template.Must(template.ParseFiles("templates/menuTemplate.html")) + var tpl bytes.Buffer + err := tmplMenu.Execute(&tpl, menuItems) + check(err) + return template.HTML(tpl.String()) +} func getDir(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) var dirpath string @@ -63,11 +76,18 @@ func getDir(w http.ResponseWriter, r *http.Request) { dirpath = vars["path"] dirpath = strings.Replace(dirpath, "%", "/", -1) } + var page PageModel + page.Title = dirpath + if dirpath == "" { + page.Title = "padArchiver" + } + page.MenuContent = generateMenuHTML(dirpath) + content, err := fileToHTML("templates/wellcome.md") + check(err) + page.Content = template.HTML(content) - menuPage := generateMenu(dirpath) - - tmpl := template.Must(template.ParseFiles("templates/menuTemplate.html")) - tmpl.Execute(w, menuPage) + tmpl := template.Must(template.ParseFiles("templates/pageTemplate.html")) + tmpl.Execute(w, page) } func getPage(w http.ResponseWriter, r *http.Request) { @@ -79,10 +99,12 @@ func getPage(w http.ResponseWriter, r *http.Request) { content, err := fileToHTML(path) check(err) - var item ItemModel - item.Name = path - item.Content = template.HTML(content) + var page PageModel + page.Title = path + page.Content = template.HTML(content) - tmpl := template.Must(template.ParseFiles("templates/pageTemplate.html")) - tmpl.Execute(w, item) + page.MenuContent = generateMenuHTML("") + + tmplPage := template.Must(template.ParseFiles("templates/pageTemplate.html")) + tmplPage.Execute(w, page) } diff --git a/webServer/templates/menuTemplate.html b/webServer/templates/menuTemplate.html index 1e3c749..05f1567 100644 --- a/webServer/templates/menuTemplate.html +++ b/webServer/templates/menuTemplate.html @@ -1,91 +1,18 @@ - - - - - - - - - - - - - - padArchiver - - - - - + diff --git a/webServer/templates/pageTemplate.html b/webServer/templates/pageTemplate.html index 33add86..325d935 100644 --- a/webServer/templates/pageTemplate.html +++ b/webServer/templates/pageTemplate.html @@ -10,6 +10,9 @@ padArchiver @@ -24,26 +36,35 @@

-
-
-

{{.Name}}

+
+ {{.MenuContent}} +
+
+

{{.Title}}


{{.Content}}
@@ -69,6 +90,9 @@ + + + diff --git a/webServer/templates/wellcome.md b/webServer/templates/wellcome.md new file mode 100644 index 0000000..ea67dbf --- /dev/null +++ b/webServer/templates/wellcome.md @@ -0,0 +1,7 @@ +### Wellcome to the padArchiver. +Select one pad from the side menu to visualize. + +![golang logo](https://seeklogo.com/images/G/go-logo-046185B647-seeklogo.com.png) + + +This is the wellcome message, from the 'templates/wellcome.md' file. diff --git a/webServer/webServer b/webServer/webServer index 87b1ad9..94ad0f6 100755 Binary files a/webServer/webServer and b/webServer/webServer differ