Skip to content

Commit

Permalink
fix mail link gra
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed Apr 24, 2024
1 parent b68ed5c commit 756cae1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
7 changes: 5 additions & 2 deletions MailGrabber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ internal List<Tuple<string,string>> FindUrl(string sender, string regexPatternDo
workspaceUrl = match.Value;
break;
}

urls.Add(new Tuple<string, string>(dlUrl,workspaceUrl));

if (!string.IsNullOrEmpty(dlUrl) && !string.IsNullOrEmpty(workspaceUrl))
{
urls.Add(new Tuple<string, string>(dlUrl, workspaceUrl));
}
}

client.Disconnect(true);
Expand Down
32 changes: 22 additions & 10 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OpenQA.Selenium;
using System.Diagnostics;
using OpenQA.Selenium;

namespace NotionBackupTool;

Expand All @@ -18,6 +19,15 @@ static string GetConfig(string envName, string defaultValue = "")

static async Task Main()
{
// Wait for debugger
/*while (!Debugger.IsAttached) // wait here until debugger is attached
{
Console.WriteLine("Waiting for debugger..");
System.Threading.Thread.Sleep(1000); // prevent tight loop
}*/



string mode = GetConfig("MODE");

string webDriverEndpoint = GetConfig("WEBDRIVER_URL", "http://localhost:4444");
Expand Down Expand Up @@ -104,15 +114,6 @@ async Task<Cookie> FileCookie()
int ct = 0;
foreach (Tuple<string, string> urls in downloadUrls)
{
Console.WriteLine($"Processing download #{ct}");
var req = new HttpRequestMessage(HttpMethod.Get, urls.Item1);
req.Headers.Add("cookie", $"file_token={fileCookieValue}");

var response = await hc.SendAsync(req, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();

string datetime = DateTime.UtcNow.ToString("s").Replace(':', '-');

// map workspace
string workspaceId = urls.Item2.Split('/').Last();
string workspaceName = workspaces.FirstOrDefault(x => x.Id == workspaceId)?.Name ?? String.Empty;
Expand All @@ -123,6 +124,17 @@ async Task<Cookie> FileCookie()
workspaceName = workspaceId;
}

// Start download
Console.WriteLine($"Processing download #{ct}");
var req = new HttpRequestMessage(HttpMethod.Get, urls.Item1);
req.Headers.Add("cookie", $"file_token={fileCookieValue}");

var response = await hc.SendAsync(req, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();

string datetime = DateTime.UtcNow.ToString("s").Replace(':', '-');


string dlFilename = Path.Combine(temporaryDir, $"notion-{workspaceName}-{datetime}.zip");
Console.WriteLine("Downloading...");
await using Stream dlStream = await response.Content.ReadAsStreamAsync();
Expand Down

0 comments on commit 756cae1

Please sign in to comment.