Stream Chat Unreal SDK
Loading...
Searching...
No Matches
ImageDownloadSubsystem.h
1// Copyright 2022 Stream.IO, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Subsystems/EngineSubsystem.h"
7
8#include "ImageDownloadSubsystem.generated.h"
9
10class UTexture2DDynamic;
11using FHttpResponsePtr = TSharedPtr<class IHttpResponse, ESPMode::ThreadSafe>;
12enum class EImageFormat : int8;
13
17UCLASS()
18class STREAMCHATUI_API UImageDownloadSubsystem final : public UEngineSubsystem
19{
20 GENERATED_BODY()
21
22public:
23 virtual void Initialize(FSubsystemCollectionBase& Collection) override;
24 virtual bool ShouldCreateSubsystem(UObject* Outer) const override;
25
26 void DownloadImage(const FString& Url, TFunction<void(UTexture2DDynamic*)>);
27
28private:
30 void CacheToMemory(const FString& Url, UTexture2DDynamic* Texture);
31 UTexture2DDynamic* QueryMemoryCache(const FString& Url) const;
32
34 void CacheToDisk(const FString& Url, const FHttpResponsePtr) const;
35 UTexture2DDynamic* QueryDiskCache(const FString& Url);
36
37 FString GetDiskPathForUrl(const FString& Url) const;
38
39 UPROPERTY(Transient)
40 TMap<FString, UTexture2DDynamic*> MemoryCache;
41
42 // folders to save image files into on disk
43 FString CacheFolder;
44};