2026-01-30 21:15:18 +04:00
|
|
|
#pragma once
|
|
|
|
|
#include "logos_api.h"
|
|
|
|
|
#include "logos_sdk.h"
|
2026-02-17 11:27:03 +04:00
|
|
|
#include <QFile>
|
2026-01-30 21:15:18 +04:00
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QtQml/qqml.h>
|
|
|
|
|
|
|
|
|
|
static const int RET_OK = 0;
|
2026-02-10 13:27:11 +04:00
|
|
|
static const int RET_PROGRESS = 3;
|
2026-01-30 21:15:18 +04:00
|
|
|
|
2026-02-17 11:27:03 +04:00
|
|
|
// Add manual SPR from https://spr.codex.storage/devnet
|
|
|
|
|
static const QStringList BOOTSTRAP_NODES = {
|
|
|
|
|
"spr:CiUIAhIhA-VlcoiRm02KyIzrcTP-ljFpzTljfBRRKTIvhMIwqBqWEgIDARpJCicAJQgCEiED5WVyiJGbTYrIjOtxM_6WMWnNOWN8FFEpMi-"
|
|
|
|
|
"EwjCoGpYQs8n8wQYaCwoJBHTKubmRAnU6GgsKCQR0yrm5kQJ1OipHMEUCIQDwUNsfReB4ty7JFS5WVQ6n1fcko89qVAOfQEHixa03rgIgan2-"
|
|
|
|
|
"uFNDT-r4s9TOkLe9YBkCbsRWYCHGGVJ25rLj0QE",
|
|
|
|
|
"spr:CiUIAhIhApIj9p6zJDRbw2NoCo-"
|
|
|
|
|
"tj98Y760YbppRiEpGIE1yGaMzEgIDARpJCicAJQgCEiECkiP2nrMkNFvDY2gKj62P3xjvrRhumlGISkYgTXIZozMQvcz8wQYaCwoJBAWhF3WRAnVEG"
|
|
|
|
|
"gsKCQQFoRd1kQJ1RCpGMEQCIFZB84O_nzPNuViqEGRL1vJTjHBJ-i5ZDgFL5XZxm4HAAiB8rbLHkUdFfWdiOmlencYVn0noSMRHzn4lJYoShuVzlw",
|
|
|
|
|
"spr:CiUIAhIhApqRgeWRPSXocTS9RFkQmwTZRG-"
|
|
|
|
|
"Cdt7UR2N7POoz606ZEgIDARpJCicAJQgCEiECmpGB5ZE9JehxNL1EWRCbBNlEb4J23tRHY3s86jPrTpkQj8_"
|
|
|
|
|
"8wQYaCwoJBAXfEfiRAnVOGgsKCQQF3xH4kQJ1TipGMEQCIGWJMsF57N1iIEQgTH7IrVOgEgv0J2P2v3jvQr5Cjy-RAiAy4aiZ8QtyDvCfl_K_"
|
|
|
|
|
"w6SyZ9csFGkRNTpirq_M_QNgKw"};
|
|
|
|
|
|
2026-01-30 21:15:18 +04:00
|
|
|
class StorageBackend : public QObject {
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
QML_ELEMENT
|
2026-02-10 13:27:11 +04:00
|
|
|
Q_PROPERTY(QString debugLogs READ debugLogs NOTIFY debugLogsChanged)
|
2026-02-17 11:27:03 +04:00
|
|
|
Q_PROPERTY(StorageStatus status READ status WRITE status NOTIFY statusChanged)
|
2026-02-13 20:16:27 +04:00
|
|
|
Q_PROPERTY(QString cid READ cid NOTIFY cidChanged)
|
|
|
|
|
Q_PROPERTY(QString configJson READ configJson NOTIFY configJsonChanged)
|
2026-02-15 20:14:44 +04:00
|
|
|
Q_PROPERTY(int uploadProgress READ uploadProgress NOTIFY uploadProgressChanged)
|
|
|
|
|
Q_PROPERTY(QString uploadStatus READ uploadStatus NOTIFY uploadStatusChanged)
|
2026-01-30 21:15:18 +04:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum StorageStatus { Stopped = 0, Starting, Running, Stopping, Destroyed };
|
|
|
|
|
Q_ENUM(StorageStatus)
|
|
|
|
|
|
2026-02-13 20:16:27 +04:00
|
|
|
QString cid() const;
|
2026-02-10 13:27:11 +04:00
|
|
|
QString debugLogs() const;
|
2026-02-13 20:16:27 +04:00
|
|
|
StorageStatus status() const;
|
|
|
|
|
QString configJson() const;
|
2026-02-15 20:14:44 +04:00
|
|
|
int uploadProgress() const;
|
|
|
|
|
QString uploadStatus() const;
|
2026-01-30 21:15:18 +04:00
|
|
|
|
2026-02-17 11:27:03 +04:00
|
|
|
Q_INVOKABLE static QString defaultDataDir();
|
|
|
|
|
|
2026-01-30 21:15:18 +04:00
|
|
|
explicit StorageBackend(LogosAPI* logosAPI = nullptr, QObject* parent = nullptr);
|
|
|
|
|
~StorageBackend();
|
|
|
|
|
|
|
|
|
|
public slots:
|
2026-02-13 20:16:27 +04:00
|
|
|
LogosResult start(const QString& configJson = "");
|
2026-01-30 21:15:18 +04:00
|
|
|
void destroy();
|
|
|
|
|
void stop();
|
2026-02-13 20:16:27 +04:00
|
|
|
void tryPeerConnect(const QString& peerId);
|
2026-02-10 13:27:11 +04:00
|
|
|
void tryDebug();
|
|
|
|
|
void tryUpload();
|
|
|
|
|
void tryUploadFinalize();
|
|
|
|
|
void exists(const QString& cid);
|
|
|
|
|
void remove(const QString& cid);
|
|
|
|
|
void fetch(const QString& cid);
|
|
|
|
|
void tryUploadFile(const QUrl& url);
|
|
|
|
|
void tryDownloadFile(const QString& cid, const QUrl& url);
|
|
|
|
|
void dataDir();
|
|
|
|
|
void version();
|
|
|
|
|
void spr();
|
|
|
|
|
void showPeerId();
|
|
|
|
|
void downloadManifest(const QString& cid);
|
|
|
|
|
void downloadManifests();
|
|
|
|
|
void space();
|
2026-02-17 11:27:03 +04:00
|
|
|
bool validateDataDir(const QString& path);
|
2026-02-13 20:16:27 +04:00
|
|
|
LogosResult init(const QString& configJson);
|
2026-02-10 13:27:11 +04:00
|
|
|
void updateLogLevel(const QString& logLevel);
|
2026-02-17 11:27:03 +04:00
|
|
|
void reloadIfChanged(const QString& configJson);
|
|
|
|
|
void status(StorageStatus status);
|
|
|
|
|
QString buildConfig(const QString& dataDir, int discPort, int tcpPort);
|
|
|
|
|
QString buildConfigFromFile(const QString& path);
|
2026-02-10 13:27:11 +04:00
|
|
|
|
2026-01-30 21:15:18 +04:00
|
|
|
signals:
|
2026-02-17 11:27:03 +04:00
|
|
|
void startCompleted();
|
|
|
|
|
void startFailed(const QString& error);
|
2026-01-30 21:15:18 +04:00
|
|
|
void statusChanged();
|
2026-02-10 13:27:11 +04:00
|
|
|
void debugLogsChanged();
|
2026-02-17 11:27:03 +04:00
|
|
|
void stopCompleted();
|
2026-02-13 20:16:27 +04:00
|
|
|
void cidChanged();
|
|
|
|
|
void configJsonChanged();
|
2026-02-15 20:14:44 +04:00
|
|
|
void uploadProgressChanged();
|
|
|
|
|
void uploadStatusChanged();
|
2026-01-30 21:15:18 +04:00
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
|
|
|
|
|
private:
|
2026-02-13 20:16:27 +04:00
|
|
|
void setStatus(StorageStatus newStatus);
|
2026-02-10 13:27:11 +04:00
|
|
|
void peerConnect(const QString& peerId);
|
|
|
|
|
void debug(const QString& log);
|
2026-01-30 21:15:18 +04:00
|
|
|
|
|
|
|
|
LogosAPI* m_logosAPI;
|
|
|
|
|
LogosModules* m_logos;
|
2026-02-13 20:16:27 +04:00
|
|
|
StorageStatus m_status;
|
2026-02-10 13:27:11 +04:00
|
|
|
QString m_debugLogs;
|
2026-02-13 20:16:27 +04:00
|
|
|
QString m_cid;
|
|
|
|
|
QString m_configJson;
|
2026-02-15 20:14:44 +04:00
|
|
|
int m_uploadProgress = 0;
|
|
|
|
|
QString m_uploadStatus = "";
|
|
|
|
|
qint64 m_uploadTotalBytes = 0;
|
|
|
|
|
qint64 m_uploadedBytes = 0;
|
2026-01-30 21:15:18 +04:00
|
|
|
};
|