Use StorageFileLocation in mtpFileLoader.

This commit is contained in:
John Preston 2019-03-25 15:50:42 +04:00
parent 95023ca770
commit 8759d637ff
13 changed files with 167 additions and 230 deletions

View File

@ -851,7 +851,7 @@ void DocumentData::save(
status = FileReady; status = FileReady;
if (hasWebLocation()) { if (hasWebLocation()) {
_loader = new mtpFileLoader( _loader = new mtpFileLoader(
&_urlLocation, _urlLocation,
size, size,
fromCloud, fromCloud,
autoLoading, autoLoading,
@ -865,10 +865,14 @@ void DocumentData::save(
cacheTag()); cacheTag());
} else { } else {
_loader = new mtpFileLoader( _loader = new mtpFileLoader(
_dc, StorageFileLocation(
id, _dc,
_access, session().userId(),
_fileReference, MTP_inputDocumentFileLocation(
MTP_long(id),
MTP_long(_access),
MTP_bytes(_fileReference),
MTP_string(QString()))),
origin, origin,
locationType(), locationType(),
toFile, toFile,
@ -1209,7 +1213,7 @@ auto DocumentData::createStreamingLoader(Data::FileOrigin origin) const
} }
bool DocumentData::hasWebLocation() const { bool DocumentData::hasWebLocation() const {
return _urlLocation.dc() != 0 && _urlLocation.accessHash() != 0; return !_urlLocation.url().isEmpty();
} }
bool DocumentData::isNull() const { bool DocumentData::isNull() const {

View File

@ -403,7 +403,7 @@ bool MediaPhoto::updateSentMedia(const MTPMessageMedia &media) {
return; return;
} }
parent()->history()->owner().cache().putIfEmpty( parent()->history()->owner().cache().putIfEmpty(
Data::StorageCacheKey(key), key.file().cacheKey(),
Storage::Cache::Database::TaggedValue( Storage::Cache::Database::TaggedValue(
std::move(size.bytes), std::move(size.bytes),
Data::kImageCacheTag)); Data::kImageCacheTag));

View File

@ -2029,7 +2029,6 @@ DocumentData *Session::documentFromWeb(
int32(0), // data.vsize.v int32(0), // data.vsize.v
StorageImageLocation()); StorageImageLocation());
result->setWebLocation(WebFileLocation( result->setWebLocation(WebFileLocation(
Global::WebFileDcId(),
data.vurl.v, data.vurl.v,
data.vaccess_hash.v)); data.vaccess_hash.v));
return result; return result;

View File

@ -61,12 +61,9 @@ Storage::Cache::Key DocumentThumbCacheKey(int32 dcId, uint64 id) {
}; };
} }
Storage::Cache::Key StorageCacheKey(const StorageImageLocation &location) {
return location.file().cacheKey();
}
Storage::Cache::Key WebDocumentCacheKey(const WebFileLocation &location) { Storage::Cache::Key WebDocumentCacheKey(const WebFileLocation &location) {
const auto dcId = uint64(location.dc()) & 0xFFULL; const auto CacheDcId = cTestMode() ? 2 : 4;
const auto dcId = uint64(CacheDcId) & 0xFFULL;
const auto &url = location.url(); const auto &url = location.url();
const auto hash = openssl::Sha256(bytes::make_span(url)); const auto hash = openssl::Sha256(bytes::make_span(url));
const auto bytes = bytes::make_span(hash); const auto bytes = bytes::make_span(hash);

View File

@ -44,7 +44,6 @@ struct UploadState {
Storage::Cache::Key DocumentCacheKey(int32 dcId, uint64 id); Storage::Cache::Key DocumentCacheKey(int32 dcId, uint64 id);
Storage::Cache::Key DocumentThumbCacheKey(int32 dcId, uint64 id); Storage::Cache::Key DocumentThumbCacheKey(int32 dcId, uint64 id);
Storage::Cache::Key StorageCacheKey(const StorageImageLocation &location);
Storage::Cache::Key WebDocumentCacheKey(const WebFileLocation &location); Storage::Cache::Key WebDocumentCacheKey(const WebFileLocation &location);
Storage::Cache::Key UrlCacheKey(const QString &location); Storage::Cache::Key UrlCacheKey(const QString &location);
Storage::Cache::Key GeoPointCacheKey(const GeoPointLocation &location); Storage::Cache::Key GeoPointCacheKey(const GeoPointLocation &location);

View File

@ -1246,7 +1246,7 @@ void MainWidget::exportTopBarHeightUpdated() {
} }
void MainWidget::documentLoadProgress(FileLoader *loader) { void MainWidget::documentLoadProgress(FileLoader *loader) {
if (auto documentId = loader ? loader->objId() : 0) { if (const auto documentId = loader ? loader->objId() : 0) {
documentLoadProgress(session().data().document(documentId)); documentLoadProgress(session().data().document(documentId));
} }
} }
@ -1261,10 +1261,10 @@ void MainWidget::documentLoadProgress(DocumentData *document) {
} }
void MainWidget::documentLoadFailed(FileLoader *loader, bool started) { void MainWidget::documentLoadFailed(FileLoader *loader, bool started) {
auto documentId = loader ? loader->objId() : 0; const auto documentId = loader ? loader->objId() : 0;
if (!documentId) return; if (!documentId) return;
auto document = session().data().document(documentId); const auto document = session().data().document(documentId);
if (started) { if (started) {
const auto origin = loader->fileOrigin(); const auto origin = loader->fileOrigin();
const auto failedFileName = loader->fileName(); const auto failedFileName = loader->fileName();

View File

@ -1712,10 +1712,12 @@ void FormController::loadFile(File &file) {
const auto [j, ok] = _fileLoaders.emplace( const auto [j, ok] = _fileLoaders.emplace(
key, key,
std::make_unique<mtpFileLoader>( std::make_unique<mtpFileLoader>(
file.dcId, StorageFileLocation(
file.id, file.dcId,
file.accessHash, Auth().userId(),
QByteArray(), // file_reference MTP_inputSecureFileLocation(
MTP_long(file.id),
MTP_long(file.accessHash))),
Data::FileOrigin(), Data::FileOrigin(),
SecureFileLocation, SecureFileLocation,
QString(), QString(),

View File

@ -527,36 +527,7 @@ void FileLoader::startLoading(bool loadFirst, bool prior) {
} }
mtpFileLoader::mtpFileLoader( mtpFileLoader::mtpFileLoader(
not_null<StorageImageLocation*> location, const StorageFileLocation &location,
Data::FileOrigin origin,
int32 size,
LoadFromCloudSetting fromCloud,
bool autoLoading,
uint8 cacheTag)
: FileLoader(
QString(),
size,
UnknownFileLocation,
LoadToCacheAsWell,
fromCloud,
autoLoading,
cacheTag)
, _dcId(location->file().dcId())
, _location(location)
, _origin(origin) {
auto shiftedDcId = MTP::downloadDcId(_dcId, 0);
auto i = queues.find(shiftedDcId);
if (i == queues.cend()) {
i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries));
}
_queue = &i.value();
}
mtpFileLoader::mtpFileLoader(
int32 dc,
uint64 id,
uint64 accessHash,
const QByteArray &fileReference,
Data::FileOrigin origin, Data::FileOrigin origin,
LocationType type, LocationType type,
const QString &to, const QString &to,
@ -573,12 +544,9 @@ mtpFileLoader::mtpFileLoader(
fromCloud, fromCloud,
autoLoading, autoLoading,
cacheTag) cacheTag)
, _dcId(dc) , _location(location)
, _id(id)
, _accessHash(accessHash)
, _fileReference(fileReference)
, _origin(origin) { , _origin(origin) {
auto shiftedDcId = MTP::downloadDcId(_dcId, 0); auto shiftedDcId = MTP::downloadDcId(dcId(), 0);
auto i = queues.find(shiftedDcId); auto i = queues.find(shiftedDcId);
if (i == queues.cend()) { if (i == queues.cend()) {
i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries)); i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries));
@ -587,7 +555,7 @@ mtpFileLoader::mtpFileLoader(
} }
mtpFileLoader::mtpFileLoader( mtpFileLoader::mtpFileLoader(
const WebFileLocation *location, const WebFileLocation &location,
int32 size, int32 size,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading, bool autoLoading,
@ -600,9 +568,8 @@ mtpFileLoader::mtpFileLoader(
fromCloud, fromCloud,
autoLoading, autoLoading,
cacheTag) cacheTag)
, _dcId(location->dc()) , _location(location) {
, _urlLocation(location) { auto shiftedDcId = MTP::downloadDcId(dcId(), 0);
auto shiftedDcId = MTP::downloadDcId(_dcId, 0);
auto i = queues.find(shiftedDcId); auto i = queues.find(shiftedDcId);
if (i == queues.cend()) { if (i == queues.cend()) {
i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries)); i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries));
@ -611,7 +578,7 @@ mtpFileLoader::mtpFileLoader(
} }
mtpFileLoader::mtpFileLoader( mtpFileLoader::mtpFileLoader(
const GeoPointLocation *location, const GeoPointLocation &location,
int32 size, int32 size,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading, bool autoLoading,
@ -624,9 +591,8 @@ mtpFileLoader::mtpFileLoader(
fromCloud, fromCloud,
autoLoading, autoLoading,
cacheTag) cacheTag)
, _dcId(Global::WebFileDcId()) , _location(location) {
, _geoLocation(location) { auto shiftedDcId = MTP::downloadDcId(dcId(), 0);
auto shiftedDcId = MTP::downloadDcId(_dcId, 0);
auto i = queues.find(shiftedDcId); auto i = queues.find(shiftedDcId);
if (i == queues.cend()) { if (i == queues.cend()) {
i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries)); i = queues.insert(shiftedDcId, FileLoaderQueue(kMaxFileQueries));
@ -635,33 +601,34 @@ mtpFileLoader::mtpFileLoader(
} }
int32 mtpFileLoader::currentOffset(bool includeSkipped) const { int32 mtpFileLoader::currentOffset(bool includeSkipped) const {
return (_fileIsOpen ? _file.size() : _data.size()) - (includeSkipped ? 0 : _skippedBytes); return (_fileIsOpen ? _file.size() : _data.size())
- (includeSkipped ? 0 : _skippedBytes);
} }
Data::FileOrigin mtpFileLoader::fileOrigin() const { Data::FileOrigin mtpFileLoader::fileOrigin() const {
return _origin; return _origin;
} }
uint64 mtpFileLoader::objId() const {
if (const auto storage = base::get_if<StorageFileLocation>(&_location)) {
return storage->objectId();
}
return 0;
}
void mtpFileLoader::refreshFileReferenceFrom( void mtpFileLoader::refreshFileReferenceFrom(
const Data::UpdatedFileReferences &updates, const Data::UpdatedFileReferences &updates,
int requestId, int requestId,
const QByteArray &current) { const QByteArray &current) {
if (_location) { if (const auto storage = base::get_if<StorageFileLocation>(&_location)) {
_location->refreshFileReference(updates); storage->refreshFileReference(updates);
if (_location->fileReference() == current) { if (storage->fileReference() == current) {
cancel(true); cancel(true);
return; return;
} }
} else { } else {
const auto i = updates.data.find( cancel(true);
Data::DocumentFileLocationId{ _id }); return;
if (i != end(updates.data) && !i->second.isEmpty()) {
_fileReference = i->second;
}
if (_fileReference == current) {
cancel(true);
return;
}
} }
const auto offset = finishSentRequestGetOffset(requestId); const auto offset = finishSentRequestGetOffset(requestId);
makeRequest(offset); makeRequest(offset);
@ -679,6 +646,13 @@ bool mtpFileLoader::loadPart() {
return true; return true;
} }
MTP::DcId mtpFileLoader::dcId() const {
if (const auto storage = base::get_if<StorageFileLocation>(&_location)) {
return storage->dcId();
}
return Global::WebFileDcId();
}
int mtpFileLoader::partSize() const { int mtpFileLoader::partSize() const {
return kDownloadCdnPartSize; return kDownloadCdnPartSize;
@ -697,103 +671,82 @@ int mtpFileLoader::partSize() const {
mtpFileLoader::RequestData mtpFileLoader::prepareRequest(int offset) const { mtpFileLoader::RequestData mtpFileLoader::prepareRequest(int offset) const {
auto result = RequestData(); auto result = RequestData();
result.dcId = _cdnDcId ? _cdnDcId : _dcId; result.dcId = _cdnDcId ? _cdnDcId : dcId();
result.dcIndex = _size ? _downloader->chooseDcIndexForRequest(result.dcId) : 0; result.dcIndex = _size
? _downloader->chooseDcIndexForRequest(result.dcId)
: 0;
result.offset = offset; result.offset = offset;
return result; return result;
} }
mtpRequestId mtpFileLoader::sendRequest(const RequestData &requestData) {
const auto offset = requestData.offset;
const auto limit = partSize();
const auto shiftedDcId = MTP::downloadDcId(
requestData.dcId,
requestData.dcIndex);
if (_cdnDcId) {
Assert(requestData.dcId == _cdnDcId);
return MTP::send(
MTPupload_GetCdnFile(
MTP_bytes(_cdnToken),
MTP_int(offset),
MTP_int(limit)),
rpcDone(&mtpFileLoader::cdnPartLoaded),
rpcFail(&mtpFileLoader::cdnPartFailed),
shiftedDcId,
50);
}
return _location.match([&](const WebFileLocation &location) {
return MTP::send(
MTPupload_GetWebFile(
MTP_inputWebFileLocation(
MTP_bytes(location.url()),
MTP_long(location.accessHash())),
MTP_int(offset),
MTP_int(limit)),
rpcDone(&mtpFileLoader::webPartLoaded),
rpcFail(&mtpFileLoader::partFailed),
shiftedDcId,
50);
}, [&](const GeoPointLocation &location) {
return MTP::send(
MTPupload_GetWebFile(
MTP_inputWebFileGeoPointLocation(
MTP_inputGeoPoint(
MTP_double(location.lat),
MTP_double(location.lon)),
MTP_long(location.access),
MTP_int(location.width),
MTP_int(location.height),
MTP_int(location.zoom),
MTP_int(location.scale)),
MTP_int(offset),
MTP_int(limit)),
rpcDone(&mtpFileLoader::webPartLoaded),
rpcFail(&mtpFileLoader::partFailed),
shiftedDcId,
50);
}, [&](const StorageFileLocation &location) {
return MTP::send(
MTPupload_GetFile(
location.tl(Auth().userId()),
MTP_int(offset),
MTP_int(limit)),
rpcDone(&mtpFileLoader::normalPartLoaded),
rpcFail(
&mtpFileLoader::normalPartFailed,
location.fileReference()),
shiftedDcId,
50);
});
}
void mtpFileLoader::makeRequest(int offset) { void mtpFileLoader::makeRequest(int offset) {
Expects(!_finished); Expects(!_finished);
auto requestData = prepareRequest(offset); auto requestData = prepareRequest(offset);
auto send = [this, &requestData] { placeSentRequest(sendRequest(requestData), requestData);
auto offset = requestData.offset;
auto limit = partSize();
auto shiftedDcId = MTP::downloadDcId(requestData.dcId, requestData.dcIndex);
if (_cdnDcId) {
Assert(requestData.dcId == _cdnDcId);
return MTP::send(
MTPupload_GetCdnFile(
MTP_bytes(_cdnToken),
MTP_int(offset),
MTP_int(limit)),
rpcDone(&mtpFileLoader::cdnPartLoaded),
rpcFail(&mtpFileLoader::cdnPartFailed),
shiftedDcId,
50);
} else if (_urlLocation) {
Assert(requestData.dcId == _dcId);
return MTP::send(
MTPupload_GetWebFile(
MTP_inputWebFileLocation(
MTP_bytes(_urlLocation->url()),
MTP_long(_urlLocation->accessHash())),
MTP_int(offset),
MTP_int(limit)),
rpcDone(&mtpFileLoader::webPartLoaded),
rpcFail(&mtpFileLoader::partFailed),
shiftedDcId,
50);
} else if (_geoLocation) {
Assert(requestData.dcId == _dcId);
return MTP::send(
MTPupload_GetWebFile(
MTP_inputWebFileGeoPointLocation(
MTP_inputGeoPoint(
MTP_double(_geoLocation->lat),
MTP_double(_geoLocation->lon)),
MTP_long(_geoLocation->access),
MTP_int(_geoLocation->width),
MTP_int(_geoLocation->height),
MTP_int(_geoLocation->zoom),
MTP_int(_geoLocation->scale)),
MTP_int(offset),
MTP_int(limit)),
rpcDone(&mtpFileLoader::webPartLoaded),
rpcFail(&mtpFileLoader::partFailed),
shiftedDcId,
50);
} else {
Assert(requestData.dcId == _dcId);
return MTP::send(
MTPupload_GetFile(
computeLocation(),
MTP_int(offset),
MTP_int(limit)),
rpcDone(&mtpFileLoader::normalPartLoaded),
rpcFail(
&mtpFileLoader::normalPartFailed,
computeFileReference()),
shiftedDcId,
50);
}
};
placeSentRequest(send(), requestData);
}
MTPInputFileLocation mtpFileLoader::computeLocation() const {
if (_location) {
return _location->file().tl(Auth().userId());
} else if (_locationType == SecureFileLocation) {
return MTP_inputSecureFileLocation(
MTP_long(_id),
MTP_long(_accessHash));
}
return MTP_inputDocumentFileLocation(
MTP_long(_id),
MTP_long(_accessHash),
MTP_bytes(_fileReference),
MTP_string(QString()));
}
QByteArray mtpFileLoader::computeFileReference() const {
if (_location) {
return _location->fileReference();
} else if (_locationType == SecureFileLocation) {
return QByteArray();
}
return _fileReference;
} }
void mtpFileLoader::requestMoreCdnFileHashes() { void mtpFileLoader::requestMoreCdnFileHashes() {
@ -805,10 +758,12 @@ void mtpFileLoader::requestMoreCdnFileHashes() {
auto offset = _cdnUncheckedParts.cbegin()->first; auto offset = _cdnUncheckedParts.cbegin()->first;
auto requestData = RequestData(); auto requestData = RequestData();
requestData.dcId = _dcId; requestData.dcId = dcId();
requestData.dcIndex = 0; requestData.dcIndex = 0;
requestData.offset = offset; requestData.offset = offset;
auto shiftedDcId = MTP::downloadDcId(requestData.dcId, requestData.dcIndex); auto shiftedDcId = MTP::downloadDcId(
requestData.dcId,
requestData.dcIndex);
auto requestId = _cdnHashesRequestId = MTP::send( auto requestId = _cdnHashesRequestId = MTP::send(
MTPupload_GetCdnFileHashes( MTPupload_GetCdnFileHashes(
MTP_bytes(_cdnToken), MTP_bytes(_cdnToken),
@ -856,7 +811,7 @@ void mtpFileLoader::cdnPartLoaded(const MTPupload_CdnFile &result, mtpRequestId
auto offset = finishSentRequestGetOffset(requestId); auto offset = finishSentRequestGetOffset(requestId);
if (result.type() == mtpc_upload_cdnFileReuploadNeeded) { if (result.type() == mtpc_upload_cdnFileReuploadNeeded) {
auto requestData = RequestData(); auto requestData = RequestData();
requestData.dcId = _dcId; requestData.dcId = dcId();
requestData.dcIndex = 0; requestData.dcIndex = 0;
requestData.offset = offset; requestData.offset = offset;
auto shiftedDcId = MTP::downloadDcId(requestData.dcId, requestData.dcIndex); auto shiftedDcId = MTP::downloadDcId(requestData.dcId, requestData.dcIndex);
@ -1057,10 +1012,10 @@ bool mtpFileLoader::feedPart(int offset, bytes::const_span buffer) {
if (_locationType != UnknownFileLocation if (_locationType != UnknownFileLocation
&& !_filename.isEmpty()) { && !_filename.isEmpty()) {
Local::writeFileLocation( Local::writeFileLocation(
mediaKey(_locationType, _dcId, _id), mediaKey(_locationType, dcId(), objId()),
FileLocation(_filename)); FileLocation(_filename));
} }
if (_urlLocation if (_location.is<WebFileLocation>()
|| _locationType == UnknownFileLocation || _locationType == UnknownFileLocation
|| _toCache == LoadToCacheAsWell) { || _toCache == LoadToCacheAsWell) {
if (const auto key = cacheKey()) { if (const auto key = cacheKey()) {
@ -1214,16 +1169,15 @@ void mtpFileLoader::changeCDNParams(
} }
std::optional<Storage::Cache::Key> mtpFileLoader::cacheKey() const { std::optional<Storage::Cache::Key> mtpFileLoader::cacheKey() const {
if (_urlLocation) { return _location.match([&](const WebFileLocation &location) {
return Data::WebDocumentCacheKey(*_urlLocation); return std::make_optional(Data::WebDocumentCacheKey(location));
} else if (_geoLocation) { }, [&](const GeoPointLocation &location) {
return Data::GeoPointCacheKey(*_geoLocation); return std::make_optional(Data::GeoPointCacheKey(location));
} else if (_location) { }, [&](const StorageFileLocation &location) {
return Data::StorageCacheKey(*_location); return (_toCache == LoadToCacheAsWell)
} else if (_toCache == LoadToCacheAsWell && _id != 0) { ? std::make_optional(location.cacheKey())
return Data::DocumentCacheKey(_dcId, _id); : std::nullopt;
} });
return std::nullopt;
} }
mtpFileLoader::~mtpFileLoader() { mtpFileLoader::~mtpFileLoader() {

View File

@ -205,17 +205,7 @@ class WebFileLocation;
class mtpFileLoader : public FileLoader, public RPCSender { class mtpFileLoader : public FileLoader, public RPCSender {
public: public:
mtpFileLoader( mtpFileLoader(
not_null<StorageImageLocation*> location, const StorageFileLocation &location,
Data::FileOrigin origin,
int32 size,
LoadFromCloudSetting fromCloud,
bool autoLoading,
uint8 cacheTag);
mtpFileLoader(
int32 dc,
uint64 id,
uint64 accessHash,
const QByteArray &fileReference,
Data::FileOrigin origin, Data::FileOrigin origin,
LocationType type, LocationType type,
const QString &toFile, const QString &toFile,
@ -225,13 +215,13 @@ public:
bool autoLoading, bool autoLoading,
uint8 cacheTag); uint8 cacheTag);
mtpFileLoader( mtpFileLoader(
const WebFileLocation *location, const WebFileLocation &location,
int32 size, int32 size,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading, bool autoLoading,
uint8 cacheTag); uint8 cacheTag);
mtpFileLoader( mtpFileLoader(
const GeoPointLocation *location, const GeoPointLocation &location,
int32 size, int32 size,
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading, bool autoLoading,
@ -240,9 +230,7 @@ public:
int32 currentOffset(bool includeSkipped = false) const override; int32 currentOffset(bool includeSkipped = false) const override;
Data::FileOrigin fileOrigin() const override; Data::FileOrigin fileOrigin() const override;
uint64 objId() const override { uint64 objId() const override;
return _id;
}
void stop() override { void stop() override {
rpcInvalidate(); rpcInvalidate();
@ -269,12 +257,11 @@ private:
std::optional<Storage::Cache::Key> cacheKey() const override; std::optional<Storage::Cache::Key> cacheKey() const override;
void cancelRequests() override; void cancelRequests() override;
MTP::DcId dcId() const;
int partSize() const; int partSize() const;
RequestData prepareRequest(int offset) const; RequestData prepareRequest(int offset) const;
void makeRequest(int offset); void makeRequest(int offset);
[[nodiscard]] MTPInputFileLocation computeLocation() const;
[[nodiscard]] QByteArray computeFileReference() const;
bool loadPart() override; bool loadPart() override;
void normalPartLoaded(const MTPupload_File &result, mtpRequestId requestId); void normalPartLoaded(const MTPupload_File &result, mtpRequestId requestId);
void webPartLoaded(const MTPupload_WebFile &result, mtpRequestId requestId); void webPartLoaded(const MTPupload_WebFile &result, mtpRequestId requestId);
@ -290,6 +277,7 @@ private:
bool normalPartFailed(QByteArray fileReference, const RPCError &error, mtpRequestId requestId); bool normalPartFailed(QByteArray fileReference, const RPCError &error, mtpRequestId requestId);
bool cdnPartFailed(const RPCError &error, mtpRequestId requestId); bool cdnPartFailed(const RPCError &error, mtpRequestId requestId);
mtpRequestId sendRequest(const RequestData &requestData);
void placeSentRequest(mtpRequestId requestId, const RequestData &requestData); void placeSentRequest(mtpRequestId requestId, const RequestData &requestData);
int finishSentRequestGetOffset(mtpRequestId requestId); int finishSentRequestGetOffset(mtpRequestId requestId);
void switchToCDN(int offset, const MTPDupload_fileCdnRedirect &redirect); void switchToCDN(int offset, const MTPDupload_fileCdnRedirect &redirect);
@ -309,15 +297,10 @@ private:
int32 _skippedBytes = 0; int32 _skippedBytes = 0;
int32 _nextRequestOffset = 0; int32 _nextRequestOffset = 0;
MTP::DcId _dcId = 0; // for photo locations base::variant<
StorageImageLocation *_location = nullptr; StorageFileLocation,
WebFileLocation,
uint64 _id = 0; // for document locations GeoPointLocation> _location;
uint64 _accessHash = 0;
QByteArray _fileReference;
const WebFileLocation *_urlLocation = nullptr; // for webdocument locations
const GeoPointLocation *_geoLocation = nullptr; // for webdocument locations
Data::FileOrigin _origin; Data::FileOrigin _origin;

View File

@ -347,7 +347,6 @@ ImagePtr Create(const MTPDwebDocument &document) {
auto filesize = 0; // document.vsize.v; auto filesize = 0; // document.vsize.v;
return Create( return Create(
WebFileLocation( WebFileLocation(
Global::WebFileDcId(),
document.vurl.v, document.vurl.v,
document.vaccess_hash.v), document.vaccess_hash.v),
size.width(), size.width(),
@ -375,7 +374,6 @@ ImagePtr Create(const MTPDwebDocument &document, QSize box) {
auto filesize = 0; // document.vsize.v; auto filesize = 0; // document.vsize.v;
return Create( return Create(
WebFileLocation( WebFileLocation(
Global::WebFileDcId(),
document.vurl.v, document.vurl.v,
document.vaccess_hash.v), document.vaccess_hash.v),
box, box,

View File

@ -150,6 +150,10 @@ int32 StorageFileLocation::dcId() const {
return _dcId; return _dcId;
} }
uint64 StorageFileLocation::objectId() const {
return _id;
}
MTPInputFileLocation StorageFileLocation::tl(int32 self) const { MTPInputFileLocation StorageFileLocation::tl(int32 self) const {
switch (_type) { switch (_type) {
case Type::Legacy: case Type::Legacy:

View File

@ -73,6 +73,7 @@ public:
uint64 accessHash) const; uint64 accessHash) const;
[[nodiscard]] int32 dcId() const; [[nodiscard]] int32 dcId() const;
[[nodiscard]] uint64 objectId() const;
[[nodiscard]] MTPInputFileLocation tl(int32 self) const; [[nodiscard]] MTPInputFileLocation tl(int32 self) const;
[[nodiscard]] QByteArray serialize() const; [[nodiscard]] QByteArray serialize() const;
@ -194,16 +195,12 @@ inline bool operator!=(
class WebFileLocation { class WebFileLocation {
public: public:
WebFileLocation() = default; WebFileLocation() = default;
WebFileLocation(int32 dc, const QByteArray &url, uint64 accessHash) WebFileLocation(const QByteArray &url, uint64 accessHash)
: _accessHash(accessHash) : _accessHash(accessHash)
, _url(url) , _url(url) {
, _dc(dc) {
} }
bool isNull() const { bool isNull() const {
return !_dc; return _url.isEmpty();
}
int32 dc() const {
return _dc;
} }
uint64 accessHash() const { uint64 accessHash() const {
return _accessHash; return _accessHash;
@ -217,13 +214,11 @@ public:
private: private:
uint64 _accessHash = 0; uint64 _accessHash = 0;
QByteArray _url; QByteArray _url;
int32 _dc = 0;
friend inline bool operator==( friend inline bool operator==(
const WebFileLocation &a, const WebFileLocation &a,
const WebFileLocation &b) { const WebFileLocation &b) {
return (a._dc == b._dc) return (a._accessHash == b._accessHash)
&& (a._accessHash == b._accessHash)
&& (a._url == b._url); && (a._url == b._url);
} }
@ -290,7 +285,6 @@ inline InMemoryKey inMemoryKey(const WebFileLocation &location) {
bytes::copy( bytes::copy(
bytes::object_as_span(&result), bytes::object_as_span(&result),
bytes::make_span(sha).subspan(0, sizeof(result))); bytes::make_span(sha).subspan(0, sizeof(result)));
result.first |= (uint64(uint16(location.dc())) << 56);
return result; return result;
} }

View File

@ -338,7 +338,7 @@ void RemoteSource::setImageBytes(const QByteArray &bytes) {
&& !bytes.isEmpty() && !bytes.isEmpty()
&& bytes.size() <= Storage::kMaxFileInMemory) { && bytes.size() <= Storage::kMaxFileInMemory) {
Auth().data().cache().putIfEmpty( Auth().data().cache().putIfEmpty(
Data::StorageCacheKey(location), location.file().cacheKey(),
Storage::Cache::Database::TaggedValue( Storage::Cache::Database::TaggedValue(
base::duplicate(bytes), base::duplicate(bytes),
Data::kImageCacheTag)); Data::kImageCacheTag));
@ -473,7 +473,7 @@ const StorageImageLocation &StorageSource::location() {
std::optional<Storage::Cache::Key> StorageSource::cacheKey() { std::optional<Storage::Cache::Key> StorageSource::cacheKey() {
return _location.valid() return _location.valid()
? base::make_optional(Data::StorageCacheKey(_location)) ? base::make_optional(_location.file().cacheKey())
: std::nullopt; : std::nullopt;
} }
@ -508,9 +508,12 @@ FileLoader *StorageSource::createLoader(
bool autoLoading) { bool autoLoading) {
return _location.valid() return _location.valid()
? new mtpFileLoader( ? new mtpFileLoader(
&_location, _location.file(),
origin, origin,
UnknownFileLocation,
QString(),
_size, _size,
LoadToCacheAsWell,
fromCloud, fromCloud,
autoLoading, autoLoading,
Data::kImageCacheTag) Data::kImageCacheTag)
@ -576,7 +579,7 @@ FileLoader *WebCachedSource::createLoader(
return _location.isNull() return _location.isNull()
? nullptr ? nullptr
: new mtpFileLoader( : new mtpFileLoader(
&_location, _location,
_size, _size,
fromCloud, fromCloud,
autoLoading, autoLoading,
@ -624,11 +627,11 @@ FileLoader *GeoPointSource::createLoader(
LoadFromCloudSetting fromCloud, LoadFromCloudSetting fromCloud,
bool autoLoading) { bool autoLoading) {
return new mtpFileLoader( return new mtpFileLoader(
&_location, _location,
_size, _size,
fromCloud, fromCloud,
autoLoading, autoLoading,
Data::kImageCacheTag); Data::kImageCacheTag);
} }
DelayedStorageSource::DelayedStorageSource() DelayedStorageSource::DelayedStorageSource()