mirror of
https://github.com/arnaucube/padArchiver.git
synced 2026-02-07 03:36:49 +01:00
implemented webServer, and implemented listPadsImporter
This commit is contained in:
9
listPadsImporter/error.go
Normal file
9
listPadsImporter/error.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import "github.com/fatih/color"
|
||||
|
||||
func check(err error) {
|
||||
if err != nil {
|
||||
color.Red(err.Error())
|
||||
}
|
||||
}
|
||||
20
listPadsImporter/list.json
Normal file
20
listPadsImporter/list.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"repoid": "repo01",
|
||||
"pads": [
|
||||
{
|
||||
"link": "http://board.net/p/pad1",
|
||||
"dir": "Group1",
|
||||
"title": "Pad1"
|
||||
},
|
||||
{
|
||||
"link": "http://board.net/p/pad2",
|
||||
"dir": "Group1",
|
||||
"title": "Pad2"
|
||||
},
|
||||
{
|
||||
"link": "http://board.net/p/pad3",
|
||||
"dir": "Group2",
|
||||
"title": "Pad3"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
listPadsImporter/listPadsImporter
Executable file
BIN
listPadsImporter/listPadsImporter
Executable file
Binary file not shown.
66
listPadsImporter/main.go
Normal file
66
listPadsImporter/main.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
padArchiver ".."
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
type PadModel struct {
|
||||
Link string `json:"link"`
|
||||
Dir string `json:"dir"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
type ListModel struct {
|
||||
RepoID string `json:"repoid"`
|
||||
Pads []PadModel `json:"pads"`
|
||||
}
|
||||
|
||||
func readList(path string) ListModel {
|
||||
file, err := ioutil.ReadFile(path)
|
||||
check(err)
|
||||
content := string(file)
|
||||
var list ListModel
|
||||
json.Unmarshal([]byte(content), &list)
|
||||
return list
|
||||
}
|
||||
|
||||
func main() {
|
||||
asciiart := `
|
||||
.
|
||||
. _ _ _
|
||||
. | | /\ | | (_)
|
||||
_ __ __ _ __| | / \ _ __ ___| |__ ___ _____ _ __
|
||||
| '_ \ / _ |/ _ | / /\ \ | '__/ __| '_ \| \ \ / / _ \ '__|
|
||||
| |_) | (_| | (_| |/ ____ \| | | (__| | | | |\ V / __/ |
|
||||
| .__/ \__,_|\__,_/_/ \_\_| \___|_| |_|_| \_/ \___|_| - listPadsImporter
|
||||
| |
|
||||
|_|
|
||||
|
||||
`
|
||||
color.Blue(asciiart)
|
||||
fmt.Println(" v0.0.1")
|
||||
color.Blue("https://github.com/arnaucode/padArchiver")
|
||||
fmt.Println("")
|
||||
fmt.Println("")
|
||||
fmt.Println("")
|
||||
|
||||
list := readList("list.json")
|
||||
|
||||
//open the repo
|
||||
repo := padArchiver.OpenRepo(list.RepoID)
|
||||
fmt.Println("repo opened")
|
||||
for _, pad := range list.Pads {
|
||||
fmt.Println("importing pad:")
|
||||
fmt.Println(" link: " + pad.Link)
|
||||
fmt.Println(" dir: " + pad.Dir)
|
||||
fmt.Println(" title: " + pad.Title)
|
||||
ipfsHash, err := repo.StorePad(pad.Link, pad.Dir, pad.Title)
|
||||
check(err)
|
||||
fmt.Println(" ipfs hash: " + ipfsHash)
|
||||
}
|
||||
color.Green("listPadsImporter finished")
|
||||
}
|
||||
Reference in New Issue
Block a user