Skip to content

Commit

Permalink
migrateData button
Browse files Browse the repository at this point in the history
  • Loading branch information
rrelyea committed Jun 27, 2024
1 parent 530c73c commit e1929b1
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Pages/Profiles.razor
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
{
<button @onclick="@(e=>deleteProfile(e,profileName))">del</button>
<button @onclick="@(e=>copyToProfile(e,profileName))">copy to...</button>
@if (new Uri(Navigation.Uri).Host != "multifol.io") {
<br/>
<button @onclick="@(e=>migrateProfile(e,profileName))">migrate to multifol.io...</button>
}
}
}
</td>
Expand Down Expand Up @@ -211,6 +215,18 @@
log += $"\n{profileName} profile shared. Navigate any device to https://{domain}/copyFrom/{copyToCode} within 5 minutes.\n";
}

private async Task migrateProfile(EventArgs e, string profileName)
{
//TODO: what if not saved? this will get from localstorage.
var profileData = await ProfileUtilities.GetProfileData(profileName);
var jsonEncoding = "{ \"profileData\":'"+profileData+"'}";
var myHttpContent = new MyHttpContent(jsonEncoding);
var domain = "multifol.io";
var securityKeyResponse = await Http.PostAsync($"https://api.bogle.tools/api/migratedata", myHttpContent, CancellationToken.None);
var copyToCode = await securityKeyResponse.Content.ReadAsStringAsync();
log += $"\n{profileName} profile shared. Navigate any device to https://multifol.io/copyFrom/{copyToCode} within 5 minutes.\n";
}

private async Task deleteProfile(EventArgs e, string profileName)
{
await LocalStorageAccessor.RemoveAsync(profileName);
Expand Down
58 changes: 58 additions & 0 deletions api/MigrateData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Net.Http;
using System.Collections.Generic;

namespace api
{
public static class MigrateData
{
private static Dictionary<string, string> DataStorage = new();

[FunctionName("MigrateData")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("MigrateData processed a request.");

string copyCode = req.Query["copyCode"];
string profileData = req.Query["profileData"];

string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
copyCode = copyCode ?? data?.copyCode;
profileData = profileData ?? data?.profileData;

if (profileData != null)
{
var Http = new HttpClient();
var domain = "multifol.io";

var jsonEncoding = "{ \"profileData\":'"+profileData+"'}";
var myHttpContent = new MyHttpContent(jsonEncoding);
var securityKeyResponse = await Http.PostAsync($"https://api.{domain}/api/copydata", myHttpContent, CancellationToken.None);
return new OkObjectResult(securityKeyResponse.Content);
}
else if (copyCode != null)
{
var Http = new HttpClient();
var domain = "multifol.io";

var jsonEncoding = "{ 'copyCode':'"+copyCode?.Trim()+"'}";
var myHttpContent = new MyHttpContent(jsonEncoding);
var familyDataResponse = await Http.PostAsync($"https://api.{domain}/api/copydata", myHttpContent, CancellationToken.None);
return new OkObjectResult(familyDataResponse.Content);
}

return new BadRequestObjectResult(null);
}
}
}

0 comments on commit e1929b1

Please sign in to comment.