Merge pull request #636 from daleglass-overte/rewrite-dropbox-urls

Rewrite Dropbox URLs to force downloads, even if the user uses a preview URL
This commit is contained in:
Dale Glass 2023-09-19 16:48:06 +02:00 committed by GitHub
commit 4969933970
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,7 @@
#include <shared/QtHelpers.h>
#include <Trace.h>
#include <Profile.h>
#include <QUrlQuery>
#include "NetworkAccessManager.h"
#include "NetworkLogging.h"
@ -700,6 +701,29 @@ void Resource::init(bool resetLoaded) {
} else if (!(_url.isValid())) {
_startedLoading = _failedToLoad = true;
}
// Dropbox by default creates URLs like:
// https://www.dropbox.com/scl/fi/xxx/avatar.fbx?rlkey=xxx&dl=0
//
// Which go to an HTTP page that allows previewing and downloading the file. To actually download,
// a link with dl=1 at the end is needed instead. Users may often use the HTTP page by mistake, but
// we can't do anything useful with it.
//
// So we just catch and forcefully rewrite it here.
if (_activeUrl.host() == "www.dropbox.com" ) {
if ( _activeUrl.hasQuery() ) {
QUrlQuery query(_activeUrl);
if (query.queryItemValue("dl") == "0") {
query.removeQueryItem("dl");
query.addQueryItem("dl", "1");
_activeUrl.setQuery(query);
qCDebug(networking) << "Rewrote Dropbox URL to force download";
}
}
}
}
void Resource::attemptRequest() {