mirror of
https://github.com/arnaucube/decentralized-blogging-platform.git
synced 2026-02-07 03:16:41 +01:00
post article to ipfs, and get from ipfs into article page working without being logged (headers conflict)
This commit is contained in:
@@ -3,9 +3,14 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
)
|
)
|
||||||
@@ -152,6 +157,21 @@ func NewPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
err = userCollection.Find(bson.M{"token": usertoken}).One(&user)
|
err = userCollection.Find(bson.M{"token": usertoken}).One(&user)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
|
//save the post.Content into an html file
|
||||||
|
err = ioutil.WriteFile(postsDir+"/"+"file.html", []byte(post.Content), 0644)
|
||||||
|
check(err)
|
||||||
|
//add the html file to ipfs
|
||||||
|
out, err := exec.Command("bash", "-c", "ipfs add "+postsDir+"/file.html").Output()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fmt.Println(out)
|
||||||
|
hash := strings.Split(string(out), " ")[1]
|
||||||
|
color.Blue(hash)
|
||||||
|
|
||||||
|
//save the hash to the post.content
|
||||||
|
post.Content = hash
|
||||||
|
|
||||||
//add date to post
|
//add date to post
|
||||||
post.Date = time.Now()
|
post.Date = time.Now()
|
||||||
|
|
||||||
|
|||||||
@@ -4,5 +4,6 @@
|
|||||||
"mongodb": {
|
"mongodb": {
|
||||||
"ip": "127.0.0.1:27017",
|
"ip": "127.0.0.1:27017",
|
||||||
"database": "decentralized-blogging-platform"
|
"database": "decentralized-blogging-platform"
|
||||||
}
|
},
|
||||||
|
"ipfsurl": "http://127.0.0.1:5001/api/v0/"
|
||||||
}
|
}
|
||||||
|
|||||||
3
main.go
3
main.go
@@ -12,6 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const keysDir = "keys"
|
const keysDir = "keys"
|
||||||
|
const postsDir = "ownposts"
|
||||||
const keysize = 2048
|
const keysize = 2048
|
||||||
const hashize = 1536
|
const hashize = 1536
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ func main() {
|
|||||||
//create models directory
|
//create models directory
|
||||||
_ = os.Mkdir(keysDir, os.ModePerm)
|
_ = os.Mkdir(keysDir, os.ModePerm)
|
||||||
//create models directory
|
//create models directory
|
||||||
_ = os.Mkdir("ownposts", os.ModePerm)
|
_ = os.Mkdir(postsDir, os.ModePerm)
|
||||||
|
|
||||||
initializeToken()
|
initializeToken()
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ type Config struct {
|
|||||||
APIPort string `json:"apiport"`
|
APIPort string `json:"apiport"`
|
||||||
WebPort string `json:"webport"`
|
WebPort string `json:"webport"`
|
||||||
Mongodb MongoConfig `json:"mongodb"`
|
Mongodb MongoConfig `json:"mongodb"`
|
||||||
|
IPFSurl string `json:"ipfsurl"`
|
||||||
}
|
}
|
||||||
type MongoConfig struct {
|
type MongoConfig struct {
|
||||||
IP string `json:"ip"`
|
IP string `json:"ip"`
|
||||||
|
|||||||
@@ -18,12 +18,23 @@
|
|||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
<div class="pull-right text-secondary">
|
||||||
|
<span class="row">
|
||||||
|
<div class="text-right">
|
||||||
|
{{post.date | date: "MMM d, y"}}
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
<span class="row">
|
||||||
|
<div class="text-right">
|
||||||
|
{{post.date | date: "HH:mm"}}h
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
<h5 class="card-title">{{post.title}}</h5>
|
<h5 class="card-title">{{post.title}}</h5>
|
||||||
<h6 class="card-subtitle mb-2 text-muted">{{post.subtitle}}</h6>
|
<h6 class="card-subtitle mb-2 text-muted">{{post.summary}}</h6>
|
||||||
<img ng-src="{{post.img}}" class="img-fluid" />
|
<img ng-src="{{post.img}}" class="img-fluid" />
|
||||||
<p class="card-text">{{post.content}}</p>
|
|
||||||
|
|
||||||
<div ng-include="'http://localhost:8080/ipfs/QmUv3dQuNREHnEFYs7JkqyxZjYfEXd4t9jej5jY2dPVaqU'"></div>
|
<div ng-include="'http://localhost:8080/ipfs/'+post.content"></div>
|
||||||
|
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<i title="Server" class="fa fa-heart ct_red300 fa-1x"></i> 37
|
<i title="Server" class="fa fa-heart ct_red300 fa-1x"></i> 37
|
||||||
|
|||||||
Reference in New Issue
Block a user