Skip to content

Commit

Permalink
add a IpfsGet API access to actually write files on disk
Browse files Browse the repository at this point in the history
Will not work, ipfs/kubo#1210
  • Loading branch information
MichaelMure committed May 8, 2015
1 parent db2dc57 commit d4e678e
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/Arbore-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ SOURCES += main.cpp\
downloadmodel.cpp \
downloaddelegate.cpp \
ipfs/ipfsid.cpp \
ipfs/ipfspeer.cpp
ipfs/ipfspeer.cpp \
ipfs/ipfsget.cpp

HEADERS += mainwindow.h \
ipfs/ipfs.h \
Expand All @@ -35,6 +36,7 @@ HEADERS += mainwindow.h \
downloadmodel.h \
downloaddelegate.h \
ipfs/ipfsid.h \
ipfs/abstractipfscommand.h
ipfs/abstractipfscommand.h \
ipfs/ipfsget.h

FORMS += mainwindow.ui
1 change: 0 additions & 1 deletion src/ipfs/abstractipfscommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class AbstractIpfsCommand : public QObject
explicit AbstractIpfsCommand(QObject *parent = 0) : QObject(parent) {}
virtual void init() = 0;
virtual void on_reply(const QJsonObject *json) = 0;
virtual bool valid_data() const { return true; }

protected:
virtual ~AbstractIpfsCommand() {}
Expand Down
1 change: 1 addition & 0 deletions src/ipfs/ipfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void Ipfs::init()

void Ipfs::init_commands()
{
get.init();
id.init();
pin.init();
swarm.init();
Expand Down
2 changes: 2 additions & 0 deletions src/ipfs/ipfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QObject>
#include <QProcess>
#include <QTimer>
#include "ipfs/ipfsget.h"
#include "ipfs/ipfsid.h"
#include "ipfs/ipfspin.h"
#include "ipfs/ipfsswarm.h"
Expand All @@ -20,6 +21,7 @@ class Ipfs : public QObject
static Ipfs& instance();

// IPFS API access
IpfsGet get;
IpfsId id;
IpfsPin pin;
IpfsSwarm swarm;
Expand Down
33 changes: 33 additions & 0 deletions src/ipfs/ipfsget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "ipfsget.h"
#include "ipfs/ipfs.h"

#include <QUrl>
#include <QUrlQuery>

const QString API_COMMAND = "get";

IpfsGet::IpfsGet(QObject *parent)
: AbstractIpfsCommand(parent)
{

}

void IpfsGet::write_on_disk(const IpfsHash &hash, const QString &path)
{
QUrl url = Ipfs::instance().api_url(API_COMMAND);
QUrlQuery query;

query.addQueryItem("arg", hash.ToString());
query.addQueryItem("o", path);

url.setQuery(query);
Ipfs::instance().query(url, this);
}

void IpfsGet::init() {}

void IpfsGet::on_reply(const QJsonObject *json)
{
Q_UNUSED(json);
}

24 changes: 24 additions & 0 deletions src/ipfs/ipfsget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef IPFSGET_H
#define IPFSGET_H

#include "ipfs/abstractipfscommand.h"
#include "ipfs/ipfshash.h"
#include <QObject>

class IpfsGet : public AbstractIpfsCommand
{
Q_OBJECT
public:
explicit IpfsGet(QObject *parent = 0);
virtual ~IpfsGet() {}

/* Will not work, https://github.com/ipfs/go-ipfs/issues/1210 */
void write_on_disk(const IpfsHash &hash, const QString &path);

// AbstractIpfsCommand interface
public:
void init();
void on_reply(const QJsonObject *json);
};

#endif // IPFSGET_H
2 changes: 1 addition & 1 deletion src/ipfs/ipfspin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ IpfsPin::IpfsPin(QObject *parent)

void IpfsPin::init() { }

void IpfsPin::add_pin(IpfsHash &hash, bool recursive)
void IpfsPin::add_pin(const IpfsHash &hash, bool recursive)
{
QUrl url = Ipfs::instance().api_url(API_COMMAND + "/add");
QUrlQuery query;
Expand Down
2 changes: 1 addition & 1 deletion src/ipfs/ipfspin.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class IpfsPin : public AbstractIpfsCommand
explicit IpfsPin(QObject *parent = 0);
virtual ~IpfsPin() {}

void add_pin(IpfsHash &hash, bool recursive = false);
void add_pin(const IpfsHash &hash, bool recursive = false);
void ls_pin(IpfsPinType pin_type = DIRECT);

// AbstractIpfsCommand interface
Expand Down

0 comments on commit d4e678e

Please sign in to comment.