|
@@ -1,12 +1,6 @@
|
|
import { HttpClient } from "@angular/common/http";
|
|
import { HttpClient } from "@angular/common/http";
|
|
import { Injectable } from "@angular/core";
|
|
import { Injectable } from "@angular/core";
|
|
|
|
|
|
-/*
|
|
|
|
- Generated class for the P2pStorageIpfsProvider provider.
|
|
|
|
-
|
|
|
|
- See https://angular.io/guide/dependency-injection for more info on providers
|
|
|
|
- and Angular DI.
|
|
|
|
-*/
|
|
|
|
@Injectable()
|
|
@Injectable()
|
|
export class P2pStorageIpfsProvider {
|
|
export class P2pStorageIpfsProvider {
|
|
private infuraUrl = "https://ipfs.infura.io:5001/api/v0/";
|
|
private infuraUrl = "https://ipfs.infura.io:5001/api/v0/";
|
|
@@ -14,12 +8,28 @@ export class P2pStorageIpfsProvider {
|
|
constructor(public http: HttpClient) {}
|
|
constructor(public http: HttpClient) {}
|
|
|
|
|
|
public storeTweet(tweet) {
|
|
public storeTweet(tweet) {
|
|
|
|
+ return this.storeOnIPFS(tweet);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public storePublicKey(publicKeyHistory) {
|
|
|
|
+ return this.storeOnIPFS(publicKeyHistory);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private storeOnIPFS(json) {
|
|
const formData = new FormData();
|
|
const formData = new FormData();
|
|
- formData.append("data", JSON.stringify(tweet));
|
|
|
|
|
|
+ formData.append("data", JSON.stringify(json));
|
|
|
|
|
|
return this.http.post(this.infuraUrl + "add", formData).toPromise();
|
|
return this.http.post(this.infuraUrl + "add", formData).toPromise();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public async fetchJson(hash: string) {
|
|
|
|
+ const options = {
|
|
|
|
+ params: { arg: hash }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return await this.http.get(this.infuraUrl + "cat", options).toPromise();
|
|
|
|
+ }
|
|
|
|
+
|
|
public fetchTweet(hash: string) {
|
|
public fetchTweet(hash: string) {
|
|
const options = {
|
|
const options = {
|
|
params: { arg: hash }
|
|
params: { arg: hash }
|