file_download_web.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "storage/file_download.h"
  9. class WebLoadManager;
  10. enum class WebRequestType {
  11. FullLoad,
  12. OnlySize,
  13. };
  14. class webFileLoader final : public FileLoader {
  15. public:
  16. webFileLoader(
  17. not_null<Main::Session*> session,
  18. const QString &url,
  19. const QString &to,
  20. LoadFromCloudSetting fromCloud,
  21. bool autoLoading,
  22. uint8 cacheTag);
  23. webFileLoader(
  24. not_null<Main::Session*> session,
  25. const QString &url,
  26. const QString &path,
  27. WebRequestType type);
  28. ~webFileLoader();
  29. [[nodiscard]] QString url() const;
  30. [[nodiscard]] WebRequestType requestType() const;
  31. [[nodiscard]] bool streamLoading() const;
  32. int64 currentOffset() const override;
  33. private:
  34. void cancelRequest();
  35. void cancelHook() override;
  36. void startLoading() override;
  37. Storage::Cache::Key cacheKey() const override;
  38. std::optional<MediaKey> fileLocationKey() const override;
  39. void loadProgress(
  40. qint64 ready,
  41. qint64 size,
  42. const QByteArray &streamed);
  43. void loadFinished(const QByteArray &data);
  44. void loadFailed();
  45. const QString _url;
  46. int64 _ready = 0;
  47. int64 _streamedOffset = 0;
  48. WebRequestType _requestType = {};
  49. std::shared_ptr<WebLoadManager> _manager;
  50. rpl::lifetime _managerLifetime;
  51. };