small update with some improvements, updated readme
jump to
@@ -1,7 +1,14 @@
-# padArchiver -Tool to store a pad (from the link) into IPFS and Git. +# padArchiver [](https://goreportcard.com/report/github.com/arnaucode/padArchiver) + +Tool to store pads (from url) into local directory and IPFS. + +The tool is composed by different tools around the library: +- webServer +- listPadsImporter +- apiServer +- cli -All the necessary files are in the /build directory. +All the necessary files are in the /build directory. Can be build using the 'bash build.sh' script. ## 1.- webServer This is a webserver that automatically generates a web from the pads directories and files stored.@@ -9,6 +16,10 @@ To run, inside 'build' directory:
``` ./webServer ``` + + + +The html template can be easily changed. ## 2.- listPadsImporter This is to import all pads from the json file 'list.json'.@@ -116,3 +127,5 @@ ```
./padArchiver-cli ``` And follow the instructions. + +
@@ -13,12 +13,15 @@ padArchiver ".."
"github.com/gorilla/mux" ) +//PadModel is the data structure for each pad type PadModel struct { Link string `json:"link"` Dir string `json:"dir"` Title string `json:"title"` IpfsHash string `json:"ipfsHash"` } + +//Repo contains all the pads --currently not used-- type Repo struct { Pads []string `json:"pads"` }@@ -37,6 +40,7 @@ log.Println(config.Port)
log.Fatal(http.ListenAndServe(":"+config.Port, router)) } +//GetReposList is the endpoint to get the list of current repos func GetReposList(w http.ResponseWriter, r *http.Request) { file, err := os.Open(padArchiver.Storage) if err != nil {@@ -56,6 +60,7 @@ check(err)
fmt.Fprintln(w, string(jResp)) } +//GetRepoIDList is the endpoint to get one repo by id func GetRepoIDList(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) repoid := vars["repoid"]@@ -74,6 +79,8 @@ jResp, err := json.Marshal(files)
check(err) fmt.Fprintln(w, string(jResp)) } + +//PostStorePad is the endpoint to post the signal to store one pad func PostStorePad(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) repoid := vars["repoid"]
@@ -5,6 +5,7 @@ "encoding/json"
"io/ioutil" ) +//Config is the configuration of the API server type Config struct { Port string `json:"port"` }
@@ -57,7 +57,7 @@ <button class="btn btn-outline-info my-2 my-sm-0" type="submit">Search</button>
</form> </nav> - <br><br> + <br> <div class="container"> <div class="row"> <div class="col-sm-3">
@@ -1,7 +1,9 @@
### Wellcome to the padArchiver. Select one pad from the side menu to visualize. - + This is the wellcome message, from the 'templates/wellcome.md' file. + +The complete code can be found in https://github.com/arnaucode/padArchiver
@@ -35,7 +35,7 @@
newcommand := bufio.NewReader(os.Stdin) fmt.Print("Please select command number") options := ` - 1 - Store Pad (to IPFS, Git, and send Telegram notification) + 1 - Store Pad (to local directory and IPFS) 2 - IPFS hash to file 0 - Exit cli option to select: `@@ -47,7 +47,7 @@ option = strings.TrimSpace(option)
switch option { case "1": - fmt.Println("selected 1 - Store Pad (to IPFS and Git)") + fmt.Println("selected 1 - Store Pad (to local directory and IPFS)") option1() break case "2":
@@ -8,6 +8,7 @@ "net/http"
"os" ) +//GetPad gets the pad from the link, and stores it into local directory func (repo *Repo) GetPad(link string, extension string, directory string, title string) (string, error) { if extension != "md" && extension != "txt" && extension != "html" && extension != "pdf" && extension != "odt" { return "", errors.New("No valid extension")
@@ -7,11 +7,13 @@
sh "github.com/ipfs/go-ipfs-api" ) -//GettedPads is the directory where are stored the pads that are getted from IPFS +//IpfsStorage is the directory where are stored the pads that are getted from IPFS const IpfsStorage = "ipfsStorage" + +//GettedPads is the directory where are stored the pads that are getted from the links const GettedPads = "ipfsStorage/gettedPads" -//Add gets the content from the etherpad specified in the link, and downloads it in the format of the specified extension, and then, puts it into IPFS +//IpfsAdd gets the content from the etherpad specified in the link, and downloads it in the format of the specified extension, and then, puts it into IPFS func IpfsAdd(path string) (string, error) { //connect to ipfs shell s := sh.NewShell("localhost:5001")@@ -24,7 +26,7 @@ }
return ipfsHash, nil } -//Get gets the content from IPFS for a given hash, and saves it into a file +//IpfsGet gets the content from IPFS for a given hash, and saves it into a file func IpfsGet(hash string, filename string) error { //create the pads directory //create the pads directory _ = os.Mkdir(IpfsStorage, os.ModePerm)
@@ -9,11 +9,14 @@ padArchiver ".."
"github.com/fatih/color" ) +//PadModel is the data struct of each pad in the list.json file type PadModel struct { Link string `json:"link"` Dir string `json:"dir"` Title string `json:"title"` } + +//ListModel is the struct of the data from the list.json file type ListModel struct { RepoID string `json:"repoid"` Pads []PadModel `json:"pads"`
@@ -6,12 +6,15 @@
"github.com/fatih/color" ) +//Storage is the directory where are stored the repos const Storage = "reposStorage" +//Repo is the directory where is placed the repository of pads type Repo struct { Dir string } +//OpenRepo opens a repo from the directory func OpenRepo(directory string) Repo { //if not exist create the repos directory _ = os.Mkdir(Storage, os.ModePerm)@@ -23,6 +26,7 @@ _ = os.Mkdir(repo.Dir, os.ModePerm)
return repo } +//StorePad gets a pad from the link, and stores it into local directory. Then also, adds the file to IPFS. 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 {
@@ -13,15 +13,20 @@ padArchiver ".."
"github.com/gorilla/mux" ) +//ItemModel is the model for each one of the files and directories in the directory of the pads type ItemModel struct { Name string Path string IsDir bool } + +//MenuModel is the struct for all the menu, containing Items type MenuModel struct { PageTitle string Items []ItemModel } + +//PageModel is the data model used in the html templates type PageModel struct { Title string MenuContent template.HTML@@ -100,7 +105,7 @@ content, err := fileToHTML(path)
check(err) var page PageModel - page.Title = path + page.Title = strings.Replace(path, padArchiver.Storage, "", -1) page.Content = template.HTML(content) page.MenuContent = generateMenuHTML("")
@@ -57,7 +57,7 @@ <button class="btn btn-outline-info my-2 my-sm-0" type="submit">Search</button>
</form> </nav> - <br><br> + <br> <div class="container"> <div class="row"> <div class="col-sm-3">
@@ -1,7 +1,9 @@
### Wellcome to the padArchiver. Select one pad from the side menu to visualize. - + This is the wellcome message, from the 'templates/wellcome.md' file. + +The complete code can be found in https://github.com/arnaucode/padArchiver