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
|
||||
Tool to store a pad (from the link) into IPFS and Git.
|
||||
# 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
|
||||
```
|
||||
|
||||

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

|
||||
|
||||
Binary file not shown.
@@ -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"]
|
||||
|
||||
@@ -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/apiServer
Binary file not shown.
Binary file not shown.
@@ -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">
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
</form>
|
||||
</nav>
|
||||
|
||||
<br><br>
|
||||
<br>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<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)
|
||||
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":
|
||||
|
||||
@@ -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
file.go
1
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 {
|
||||
|
||||
3
git.go
3
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)
|
||||
|
||||
8
ipfs.go
8
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)
|
||||
|
||||
Binary file not shown.
@@ -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
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"
|
||||
)
|
||||
|
||||
//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 {
|
||||
|
||||
@@ -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,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">
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
</form>
|
||||
</nav>
|
||||
|
||||
<br><br>
|
||||
<br>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<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