Browse Source

small update with some improvements, updated readme

master
arnaucode 6 years ago
parent
commit
9ecec88e7d
27 changed files with 58 additions and 16 deletions
  1. +16
    -3
      README.md
  2. BIN
      apiServer/apiServer
  3. +7
    -0
      apiServer/main.go
  4. +1
    -0
      apiServer/readConfig.go
  5. BIN
      build/apiServer
  6. BIN
      build/cli
  7. BIN
      build/listPadsImporter
  8. +1
    -1
      build/templates/menuTemplate.html
  9. +1
    -1
      build/templates/pageTemplate.html
  10. +3
    -1
      build/templates/wellcome.md
  11. BIN
      build/webServer
  12. BIN
      cli/cli
  13. +2
    -2
      cli/main.go
  14. +1
    -0
      etherpad.go
  15. +1
    -0
      file.go
  16. +2
    -1
      git.go
  17. +5
    -3
      ipfs.go
  18. BIN
      listPadsImporter/listPadsImporter
  19. +3
    -0
      listPadsImporter/main.go
  20. BIN
      padArchiver-cli.png
  21. BIN
      padArchiver-webServer.gif
  22. +4
    -0
      padArchiver.go
  23. +6
    -1
      webServer/main.go
  24. +1
    -1
      webServer/templates/menuTemplate.html
  25. +1
    -1
      webServer/templates/pageTemplate.html
  26. +3
    -1
      webServer/templates/wellcome.md
  27. BIN
      webServer/webServer

+ 16
- 3
README.md

@ -1,7 +1,14 @@
# padArchiver
Tool to store a pad (from the link) into IPFS and Git.
# padArchiver [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucode/padArchiver)](https://goreportcard.com/report/github.com/arnaucode/padArchiver)
All the necessary files are in the /build directory.
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. 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.
@ -10,6 +17,10 @@ To run, inside 'build' directory:
./webServer
```
![padArchiver-webServer](https://raw.githubusercontent.com/arnaucode/padArchiver/master/padArchiver-webServer.gif)
The html template can be easily changed.
## 2.- listPadsImporter
This is to import all pads from the json file 'list.json'.
Just need to edit the json file, for example:
@ -116,3 +127,5 @@ To run the CLI, just need to run inside the directory 'build':
./padArchiver-cli
```
And follow the instructions.
![padArchiver-cli](https://raw.githubusercontent.com/arnaucode/padArchiver/master/padArchiver-cli.png)

BIN
apiServer/apiServer


+ 7
- 0
apiServer/main.go

@ -13,12 +13,15 @@ import (
"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 @@ func main() {
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 @@ func GetReposList(w http.ResponseWriter, r *http.Request) {
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 @@ func GetRepoIDList(w http.ResponseWriter, r *http.Request) {
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"]

+ 1
- 0
apiServer/readConfig.go

@ -5,6 +5,7 @@ import (
"io/ioutil"
)
//Config is the configuration of the API server
type Config struct {
Port string `json:"port"`
}

BIN
build/apiServer


BIN
build/cli


BIN
build/listPadsImporter


+ 1
- 1
build/templates/menuTemplate.html

@ -1,6 +1,6 @@
<ul class="list-group">
{{range .Items}} {{if .IsDir}}
<br><br>
<br>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active" aria-current="page">

+ 1
- 1
build/templates/pageTemplate.html

@ -57,7 +57,7 @@
</form>
</nav>
<br><br>
<br>
<div class="container">
<div class="row">
<div class="col-sm-3">

+ 3
- 1
build/templates/wellcome.md
File diff suppressed because it is too large
View File


BIN
build/webServer


BIN
cli/cli


+ 2
- 2
cli/main.go

@ -35,7 +35,7 @@ func main() {
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 to select: `
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":

+ 1
- 0
etherpad.go

@ -8,6 +8,7 @@ import (
"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")

+ 1
- 0
file.go

@ -4,6 +4,7 @@ import (
"io/ioutil"
)
//AddLineToFile adds a line in the beginning of the file
func AddLineToFile(path string, line string) error {
fileBytes, err := ioutil.ReadFile(path)
if err != nil {

+ 2
- 1
git.go

@ -5,8 +5,9 @@ import (
"os/exec"
)
//TODO this is not finished
//GitUpdate updates the git
func (repo *Repo) GitUpdate(commitMsg string) error {
//TODO this is not finished
_, err := exec.Command("bash", "-c", "git pull origin master").Output()
if err != nil {
fmt.Println(err)

+ 5
- 3
ipfs.go

@ -7,11 +7,13 @@ import (
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 @@ func IpfsAdd(path string) (string, error) {
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)

BIN
listPadsImporter/listPadsImporter


+ 3
- 0
listPadsImporter/main.go

@ -9,11 +9,14 @@ import (
"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"`

BIN
padArchiver-cli.png

Before After
Width: 576  |  Height: 387  |  Size: 23 KiB

BIN
padArchiver-webServer.gif

Before After
Width: 800  |  Height: 405  |  Size: 4.7 MiB

+ 4
- 0
padArchiver.go

@ -6,12 +6,15 @@ import (
"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 @@ func OpenRepo(directory string) Repo {
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 {

+ 6
- 1
webServer/main.go

@ -13,15 +13,20 @@ import (
"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 @@ func getPage(w http.ResponseWriter, r *http.Request) {
check(err)
var page PageModel
page.Title = path
page.Title = strings.Replace(path, padArchiver.Storage, "", -1)
page.Content = template.HTML(content)
page.MenuContent = generateMenuHTML("")

+ 1
- 1
webServer/templates/menuTemplate.html

@ -1,6 +1,6 @@
<ul class="list-group">
{{range .Items}} {{if .IsDir}}
<br><br>
<br>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active" aria-current="page">

+ 1
- 1
webServer/templates/pageTemplate.html

@ -57,7 +57,7 @@
</form>
</nav>
<br><br>
<br>
<div class="container">
<div class="row">
<div class="col-sm-3">

+ 3
- 1
webServer/templates/wellcome.md
File diff suppressed because it is too large
View File


BIN
webServer/webServer


Loading…
Cancel
Save