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 ## 1.- webServer
This is a webserver that automatically generates a web from the pads directories and files stored. 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 ./webServer
``` ```
![padArchiver-webServer](https://raw.githubusercontent.com/arnaucode/padArchiver/master/padArchiver-webServer.gif)
The html template can be easily changed.
## 2.- listPadsImporter ## 2.- listPadsImporter
This is to import all pads from the json file 'list.json'. This is to import all pads from the json file 'list.json'.
Just need to edit the json file, for example: 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 ./padArchiver-cli
``` ```
And follow the instructions. 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" "github.com/gorilla/mux"
) )
//PadModel is the data structure for each pad
type PadModel struct { type PadModel struct {
Link string `json:"link"` Link string `json:"link"`
Dir string `json:"dir"` Dir string `json:"dir"`
Title string `json:"title"` Title string `json:"title"`
IpfsHash string `json:"ipfsHash"` IpfsHash string `json:"ipfsHash"`
} }
//Repo contains all the pads --currently not used--
type Repo struct { type Repo struct {
Pads []string `json:"pads"` Pads []string `json:"pads"`
} }
@ -37,6 +40,7 @@ func main() {
log.Fatal(http.ListenAndServe(":"+config.Port, router)) 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) { func GetReposList(w http.ResponseWriter, r *http.Request) {
file, err := os.Open(padArchiver.Storage) file, err := os.Open(padArchiver.Storage)
if err != nil { if err != nil {
@ -56,6 +60,7 @@ func GetReposList(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, string(jResp)) fmt.Fprintln(w, string(jResp))
} }
//GetRepoIDList is the endpoint to get one repo by id
func GetRepoIDList(w http.ResponseWriter, r *http.Request) { func GetRepoIDList(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
repoid := vars["repoid"] repoid := vars["repoid"]
@ -74,6 +79,8 @@ func GetRepoIDList(w http.ResponseWriter, r *http.Request) {
check(err) check(err)
fmt.Fprintln(w, string(jResp)) 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) { func PostStorePad(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
repoid := vars["repoid"] repoid := vars["repoid"]

+ 1
- 0
apiServer/readConfig.go

@ -5,6 +5,7 @@ import (
"io/ioutil" "io/ioutil"
) )
//Config is the configuration of the API server
type Config struct { type Config struct {
Port string `json:"port"` 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"> <ul class="list-group">
{{range .Items}} {{if .IsDir}} {{range .Items}} {{if .IsDir}}
<br><br>
<br>
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb"> <ol class="breadcrumb">
<li class="breadcrumb-item active" aria-current="page"> <li class="breadcrumb-item active" aria-current="page">

+ 1
- 1
build/templates/pageTemplate.html

@ -57,7 +57,7 @@
</form> </form>
</nav> </nav>
<br><br>
<br>
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-sm-3"> <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) newcommand := bufio.NewReader(os.Stdin)
fmt.Print("Please select command number") fmt.Print("Please select command number")
options := ` options := `
1 - Store Pad (to IPFS, Git, and send Telegram notification)
1 - Store Pad (to local directory and IPFS)
2 - IPFS hash to file 2 - IPFS hash to file
0 - Exit cli 0 - Exit cli
option to select: ` option to select: `
@ -47,7 +47,7 @@ option to select: `
switch option { switch option {
case "1": case "1":
fmt.Println("selected 1 - Store Pad (to IPFS and Git)")
fmt.Println("selected 1 - Store Pad (to local directory and IPFS)")
option1() option1()
break break
case "2": case "2":

+ 1
- 0
etherpad.go

@ -8,6 +8,7 @@ import (
"os" "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) { 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" { if extension != "md" && extension != "txt" && extension != "html" && extension != "pdf" && extension != "odt" {
return "", errors.New("No valid extension") return "", errors.New("No valid extension")

+ 1
- 0
file.go

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

+ 2
- 1
git.go

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

+ 5
- 3
ipfs.go

@ -7,11 +7,13 @@ import (
sh "github.com/ipfs/go-ipfs-api" 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" const IpfsStorage = "ipfsStorage"
//GettedPads is the directory where are stored the pads that are getted from the links
const GettedPads = "ipfsStorage/gettedPads" 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) { func IpfsAdd(path string) (string, error) {
//connect to ipfs shell //connect to ipfs shell
s := sh.NewShell("localhost:5001") s := sh.NewShell("localhost:5001")
@ -24,7 +26,7 @@ func IpfsAdd(path string) (string, error) {
return ipfsHash, nil 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 func IpfsGet(hash string, filename string) error { //create the pads directory
//create the pads directory //create the pads directory
_ = os.Mkdir(IpfsStorage, os.ModePerm) _ = os.Mkdir(IpfsStorage, os.ModePerm)

BIN
listPadsImporter/listPadsImporter


+ 3
- 0
listPadsImporter/main.go

@ -9,11 +9,14 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
) )
//PadModel is the data struct of each pad in the list.json file
type PadModel struct { type PadModel struct {
Link string `json:"link"` Link string `json:"link"`
Dir string `json:"dir"` Dir string `json:"dir"`
Title string `json:"title"` Title string `json:"title"`
} }
//ListModel is the struct of the data from the list.json file
type ListModel struct { type ListModel struct {
RepoID string `json:"repoid"` RepoID string `json:"repoid"`
Pads []PadModel `json:"pads"` 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" "github.com/fatih/color"
) )
//Storage is the directory where are stored the repos
const Storage = "reposStorage" const Storage = "reposStorage"
//Repo is the directory where is placed the repository of pads
type Repo struct { type Repo struct {
Dir string Dir string
} }
//OpenRepo opens a repo from the directory
func OpenRepo(directory string) Repo { func OpenRepo(directory string) Repo {
//if not exist create the repos directory //if not exist create the repos directory
_ = os.Mkdir(Storage, os.ModePerm) _ = os.Mkdir(Storage, os.ModePerm)
@ -23,6 +26,7 @@ func OpenRepo(directory string) Repo {
return 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) { func (repo *Repo) StorePad(link string, directory string, title string, ipfsActive bool) (string, error) {
path, err := repo.GetPad(link, "md", directory, title) path, err := repo.GetPad(link, "md", directory, title)
if err != nil { if err != nil {

+ 6
- 1
webServer/main.go

@ -13,15 +13,20 @@ import (
"github.com/gorilla/mux" "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 { type ItemModel struct {
Name string Name string
Path string Path string
IsDir bool IsDir bool
} }
//MenuModel is the struct for all the menu, containing Items
type MenuModel struct { type MenuModel struct {
PageTitle string PageTitle string
Items []ItemModel Items []ItemModel
} }
//PageModel is the data model used in the html templates
type PageModel struct { type PageModel struct {
Title string Title string
MenuContent template.HTML MenuContent template.HTML
@ -100,7 +105,7 @@ func getPage(w http.ResponseWriter, r *http.Request) {
check(err) check(err)
var page PageModel var page PageModel
page.Title = path
page.Title = strings.Replace(path, padArchiver.Storage, "", -1)
page.Content = template.HTML(content) page.Content = template.HTML(content)
page.MenuContent = generateMenuHTML("") page.MenuContent = generateMenuHTML("")

+ 1
- 1
webServer/templates/menuTemplate.html

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

+ 1
- 1
webServer/templates/pageTemplate.html

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