79 lines
1.8 KiB
C++
79 lines
1.8 KiB
C++
#ifndef _UPLOADMANAGER_H
|
|
#define _UPLOADMANAGER_H
|
|
|
|
#include <SQLiteCpp/Database.h>
|
|
#include <SQLiteCpp/Exception.h>
|
|
#include <autothread.h>
|
|
#include <deque>
|
|
#include <siacurl.h>
|
|
#include <eventsystem.h>
|
|
#include <filepath.h>
|
|
|
|
NS_BEGIN(Sia)
|
|
NS_BEGIN(Api)
|
|
|
|
class SIADRIVE_EXPORTABLE CUploadManager :
|
|
public CAutoThread
|
|
{
|
|
public:
|
|
enum class _UploadStatus : unsigned
|
|
{
|
|
NotFound,
|
|
Queued,
|
|
Uploading,
|
|
Complete
|
|
};
|
|
|
|
enum class _UploadErrorCode
|
|
{
|
|
Success,
|
|
SourceFileNotFound,
|
|
DatabaseError
|
|
};
|
|
|
|
private:
|
|
typedef struct
|
|
{
|
|
std::uint64_t Id;
|
|
SString SiaPath;
|
|
SString FilePath;
|
|
SString TempPath;
|
|
_UploadStatus Status;
|
|
} UploadData;
|
|
|
|
public:
|
|
CUploadManager(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig);
|
|
|
|
public:
|
|
virtual ~CUploadManager();
|
|
|
|
private:
|
|
CSiaDriveConfig* _siaDriveConfig;
|
|
SQLite::Database _uploadDatabase;
|
|
std::mutex _uploadMutex;
|
|
|
|
private:
|
|
CSiaDriveConfig* GetSiaDriveConfig() const { return _siaDriveConfig; }
|
|
|
|
bool HandleFileRemove(const CSiaCurl& siaCurl, const SString& siaPath);
|
|
void DeleteFilesRemovedFromSia(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig, const bool& isStartup = false);
|
|
|
|
protected:
|
|
virtual void AutoThreadCallback(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig) override;
|
|
|
|
public:
|
|
static SString UploadStatusToString(const _UploadStatus& uploadStatus);
|
|
|
|
public:
|
|
CSiaError<_UploadErrorCode> AddOrUpdate(const SString& siaPath, SString filePath, const std::uint64_t& lastModified);
|
|
_UploadStatus GetUploadStatus(const SString& siaPath);
|
|
CSiaError<_UploadErrorCode> Remove(const SString& siaPath);
|
|
};
|
|
|
|
typedef CUploadManager::_UploadStatus UploadStatus;
|
|
typedef CUploadManager::_UploadErrorCode UploadErrorCode;
|
|
typedef CSiaError<CUploadManager::_UploadErrorCode> UploadError;
|
|
|
|
NS_END(2)
|
|
|
|
#endif //_UPLOADMANAGER_H
|