mirror of
https://github.com/arnaucube/padArchiver.git
synced 2026-02-06 19:26:48 +01:00
small update with some improvements, updated readme
This commit is contained in:
19
README.md
19
README.md
@@ -1,7 +1,14 @@
|
|||||||
# padArchiver
|
# padArchiver [](https://goreportcard.com/report/github.com/arnaucode/padArchiver)
|
||||||
Tool to store a pad (from the link) into IPFS and Git.
|
|
||||||
|
|
||||||
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
|
||||||
```
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|||||||
Binary file not shown.
@@ -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"]
|
||||||
|
|||||||
@@ -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/apiServer
Binary file not shown.
Binary file not shown.
@@ -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">
|
||||||
|
|||||||
@@ -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">
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
BIN
build/webServer
BIN
build/webServer
Binary file not shown.
@@ -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":
|
||||||
|
|||||||
@@ -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
file.go
1
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 {
|
||||||
|
|||||||
3
git.go
3
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)
|
||||||
|
|||||||
8
ipfs.go
8
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)
|
||||||
|
|||||||
Binary file not shown.
@@ -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
Normal file
BIN
padArchiver-cli.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
BIN
padArchiver-webServer.gif
Normal file
BIN
padArchiver-webServer.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.7 MiB |
@@ -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 {
|
||||||
|
|||||||
@@ -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,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">
|
||||||
|
|||||||
@@ -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">
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
Reference in New Issue
Block a user