169 lines
4.3 KiB
C++
169 lines
4.3 KiB
C++
// Copyright 2017-2020 David Romanski(Socke). All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Serialization/BufferArchive.h"
|
|
#include "HttpModule.h"
|
|
#include "Interfaces/IHttpRequest.h"
|
|
#include "Interfaces/IHttpResponse.h"
|
|
#include "Interfaces/IHttpRequest.h"
|
|
#include "GenericPlatform/GenericPlatformHttp.h"
|
|
#include "Kismet/BlueprintFunctionLibrary.h"
|
|
#include "Kismet/BlueprintAsyncActionBase.h"
|
|
#include "Async/Async.h"
|
|
#include "HAL/PlatformFileManager.h"
|
|
#include "HAL/FileManager.h"
|
|
#include "Misc/FileHelper.h"
|
|
#include "Misc/Paths.h"
|
|
#include "Misc/Base64.h"
|
|
#include "Misc/SecureHash.h"
|
|
#include "Containers/Queue.h"
|
|
#include "Modules/ModuleManager.h"
|
|
#include "Runtime/Launch/Resources/Version.h"
|
|
#include "WebCommunication.generated.h"
|
|
|
|
class UWebCommunicationRequestCompleteObject;
|
|
|
|
UENUM(BlueprintType)
|
|
enum class EHTTPWebComFileUpload : uint8
|
|
{
|
|
E_gd UMETA(DisplayName = "Game directory"),
|
|
E_ad UMETA(DisplayName = "Absolute directory")
|
|
};
|
|
|
|
UENUM()
|
|
enum class EHTTPWebComRequestType : uint8
|
|
{
|
|
GET UMETA(DisplayName = "GET"),
|
|
GETLowRamDownload UMETA(DisplayName = "GETLowRamDownload"),
|
|
PUT UMETA(DisplayName = "PUT"),
|
|
PUT_STREAM_MP UMETA(DisplayName = "PUT Stream (Multipart)"),
|
|
PUT_STREAM_BLANK UMETA(DisplayName = "PUT Stream (Blank)"),
|
|
PUT_STREAM_COPY UMETA(DisplayName = "PUT Stream (Copy)"),
|
|
POST UMETA(DisplayName = "POST"),
|
|
POST_UPLOAD UMETA(DisplayName = "POST_UPLOAD"),
|
|
INDIVIDUAL UMETA(DisplayName = "INDIVIDUAL"),
|
|
INDIVIDUAL_STREAM UMETA(DisplayName = "INDIVIDUAL_STEAM"),
|
|
INDIVIDUAL_BYTES UMETA(DisplayName = "INDIVIDUAL_BYTES")
|
|
};
|
|
|
|
UENUM(BlueprintType)
|
|
enum class EHTTPWebComIndividualType : uint8
|
|
{
|
|
E_STRING UMETA(DisplayName = "Content as String"),
|
|
E_STREAM UMETA(DisplayName = "Content as Stream (Filepath)"),
|
|
E_BYTES UMETA(DisplayName = "Content as Byte Array")
|
|
};
|
|
|
|
|
|
UENUM(BlueprintType)
|
|
enum class EHTTPWebComFileUploadType : uint8
|
|
{
|
|
PUT UMETA(DisplayName = "PUT"),
|
|
PUT_STREAM_BLANK UMETA(DisplayName = "PUT Stream (Blank)"),
|
|
PUT_STREAM_COPY UMETA(DisplayName = "PUT Stream (Copy)"),
|
|
PUT_STREAM_MP UMETA(DisplayName = "PUT Stream (Multipart)")
|
|
};
|
|
|
|
UENUM(BlueprintType)
|
|
enum class EHTTPWebComFileDownloadResumeType : uint8
|
|
{
|
|
E_OVERWRITE UMETA(DisplayName = "Overwrite"),
|
|
E_NOT_OVERWRITE UMETA(DisplayName = "Cancel Download"),
|
|
E_RESUME UMETA(DisplayName = "Resume")
|
|
};
|
|
|
|
UENUM(BlueprintType)
|
|
enum class EHTTPWebComFileBytesToFileActionType : uint8
|
|
{
|
|
E_OVERWRITE UMETA(DisplayName = "Overwrite"),
|
|
E_NOT_OVERWRITE UMETA(DisplayName = "Cancel Download")
|
|
};
|
|
|
|
USTRUCT(BlueprintType)
|
|
struct FhttpRequest
|
|
{
|
|
GENERATED_USTRUCT_BODY()
|
|
|
|
FString url;
|
|
UWebCommunicationRequestCompleteObject* request;
|
|
TMap<FString, FString> POSTData;
|
|
EHTTPWebComRequestType requestType;
|
|
|
|
EHTTPWebComFileUpload DirectoryType;
|
|
FString filePath;
|
|
TArray<FString> filePaths;
|
|
FString fileID;
|
|
TArray<FString> fileIDs;
|
|
int64 originalFileSize = 0;
|
|
|
|
TMap<FString, FString> header;
|
|
FString verb;
|
|
FString content;
|
|
TArray<uint8> binaryContent;
|
|
bool bindServerSendEvent = false;
|
|
bool bindDownloadProgressEvent = false;
|
|
bool bindUploadProgressEvent = false;
|
|
};
|
|
|
|
|
|
struct FfileToByteStruct
|
|
{
|
|
TArray<uint8> byteData;
|
|
EHTTPWebComFileUpload DirectoryType;
|
|
FString filePath;
|
|
EHTTPWebComFileBytesToFileActionType fileAction;
|
|
|
|
};
|
|
|
|
struct FWebcomTheadJob
|
|
{
|
|
int32 type = -1;
|
|
FHttpResponsePtr response;
|
|
bool bWasSuccessful = false;
|
|
FHttpRequestPtr request;
|
|
uint64 bytesSent = 0;
|
|
uint64 bytesReceived = 0;
|
|
|
|
};
|
|
|
|
|
|
#ifndef __FileFunctionsWebCom
|
|
#define __FileFunctionsWebCom
|
|
#include "FileFunctionsWebCom.h"
|
|
#endif
|
|
|
|
#ifndef __WebComCompleteObject
|
|
#define __WebComCompleteObject
|
|
#include "WebCommunicationRequestCompleteObject.h"
|
|
#endif
|
|
|
|
#ifndef __WebComLib
|
|
#define __WebComLib
|
|
#include "WebCommunicationBPLibrary.h"
|
|
#endif
|
|
|
|
#ifndef __UAsyncNodeHttpRequest
|
|
#define __UAsyncNodeHttpRequest
|
|
#include "UAsyncNodeHttpRequest.h"
|
|
#endif
|
|
|
|
#ifndef __UAsyncNodeHttpGoogleFileInfoRequest
|
|
#define __UAsyncNodeHttpGoogleFileInfoRequest
|
|
#include "UAsyncNodeHttpGoogleFileInfoRequest.h"
|
|
#endif
|
|
|
|
#ifndef __UAsyncNodeHttpDownloadUpload
|
|
#define __UAsyncNodeHttpDownloadUpload
|
|
#include "UAsyncNodeHttpDownloadUpload.h"
|
|
#endif
|
|
|
|
class FWebCommunicationModule : public IModuleInterface
|
|
{
|
|
public:
|
|
|
|
/** IModuleInterface implementation */
|
|
virtual void StartupModule() override;
|
|
virtual void ShutdownModule() override;
|
|
}; |