Skip to content

Commit

Permalink
allow refresh link even if referer is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
subhra74 committed Feb 12, 2023
1 parent dbdf703 commit 07c45fa
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
46 changes: 23 additions & 23 deletions app/XDM/XDM.Core/UI/LinkRefreshDialogUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static bool RefreshLink(DownloadItemBase item, IRefreshLinkDialog dialog)
{
try
{

if (item.DownloadType != "Http" && item.DownloadType != "Dash")
{
return false;
Expand All @@ -39,32 +38,33 @@ public static bool RefreshLink(DownloadItemBase item, IRefreshLinkDialog dialog)
return false;
}
Log.Debug("Referer: " + referer);
if (referer != null)

dialog.WatchingStopped += (a, b) =>
{
dialog.WatchingStopped += (a, b) =>
{
ApplicationContext.LinkRefresher.ClearWatchList();
};
ApplicationContext.LinkRefresher.ClearWatchList();
};

if (referer != null)
{
OpenBrowser(referer);
if (item.DownloadType == "Http")
{
var downloader = new SingleSourceHTTPDownloader(item.Id);
downloader.RestoreState();
ApplicationContext.LinkRefresher.RefreshedLinkReceived += (_, _) => dialog.LinkReceived();
ApplicationContext.LinkRefresher.AddToWatchList(downloader);
}
else if (item.DownloadType == "Dash")
{
var downloader = new DualSourceHTTPDownloader(item.Id);
downloader.RestoreState();
ApplicationContext.LinkRefresher.RefreshedLinkReceived += (_, _) => dialog.LinkReceived();
ApplicationContext.LinkRefresher.AddToWatchList(downloader);
}

dialog.ShowWindow();
return true;
}
if (item.DownloadType == "Http")
{
var downloader = new SingleSourceHTTPDownloader(item.Id);
downloader.RestoreState();
ApplicationContext.LinkRefresher.RefreshedLinkReceived += (_, _) => dialog.LinkReceived();
ApplicationContext.LinkRefresher.AddToWatchList(downloader);
}
else if (item.DownloadType == "Dash")
{
var downloader = new DualSourceHTTPDownloader(item.Id);
downloader.RestoreState();
ApplicationContext.LinkRefresher.RefreshedLinkReceived += (_, _) => dialog.LinkReceived();
ApplicationContext.LinkRefresher.AddToWatchList(downloader);
}

dialog.ShowWindow();
return true;
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion app/XDM/chrome-extension/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class App {
if (this.isMonitoringEnabled() && this.shouldTakeOver(url, download.filename)) {
chrome.downloads.cancel(
download.id,
() => chrome.downloads.erase(download.id)
() => chrome.downloads.erase({ id: download.id })
);
this.triggerDownload(url, download.filename,
download.referrer, download.fileSize, download.mime);
Expand Down
19 changes: 15 additions & 4 deletions app/XDM/chrome-extension/request-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ export default class RequestWatcher {
chrome.webRequest.onSendHeaders.addListener(
this.onSendHeadersEventCallback,
{ urls: ["http://*/*", "https://*/*"] },
navigator.userAgent.indexOf("Firefox") ? ["requestHeaders"] : ["requestHeaders", "extraHeaders"]
["extraHeaders", "requestHeaders"]
);

chrome.webRequest.onHeadersReceived.addListener(
this.onHeadersReceivedEventCallback,
{ urls: ["http://*/*", "https://*/*"] },
["responseHeaders"]
["extraHeaders", "responseHeaders"]
);

chrome.webRequest.onErrorOccurred.addListener(
Expand All @@ -148,7 +148,7 @@ export default class RequestWatcher {
}

createRequestData(req, res, title, tabUrl, tabId) {
var data = {
let data = {
url: res.url,
file: title,
requestHeaders: {},
Expand All @@ -160,13 +160,21 @@ export default class RequestWatcher {
tabId: tabId + ""
};

let cookies = [];

if (req.extraHeaders) {
req.extraHeaders.forEach(h => {
if (h.name === 'Cookie' || h.name === 'cookie') {
cookies.push(h.value);
}
this.addToDict(data.requestHeaders, h.name, h.value);
});
}
if (req.requestHeaders) {
req.requestHeaders.forEach(h => {
if (h.name === 'Cookie' || h.name === 'cookie') {
cookies.push(h.value);
}
this.addToDict(data.requestHeaders, h.name, h.value);
});
}
Expand All @@ -175,11 +183,14 @@ export default class RequestWatcher {
this.addToDict(data.responseHeaders, h.name, h.value);
});
}
if (cookies.length > 0) {
data.cookie = cookies.join(";");
}
return data;
}

addToDict(dict, key, value) {
var values = dict[key];
let values = dict[key];
if (values) {
values.push(value);
} else {
Expand Down

0 comments on commit 07c45fa

Please sign in to comment.