[backend] Download exported follow list directly instead of storing it as a file
This commit is contained in:
parent
137dc0d0e6
commit
95ae04e4af
2 changed files with 8 additions and 17 deletions
|
@ -1,5 +1,6 @@
|
|||
using System.Net;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
using AngleSharp.Text;
|
||||
using Iceshrimp.Backend.Controllers.Shared.Attributes;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
|
@ -68,9 +69,9 @@ public class SettingsController(DatabaseContext db, ImportExportService importEx
|
|||
}
|
||||
|
||||
[HttpPost("export/following")]
|
||||
[ProducesResults(HttpStatusCode.Accepted)]
|
||||
[ProducesResults(HttpStatusCode.OK)]
|
||||
[ProducesErrors(HttpStatusCode.BadRequest)]
|
||||
public async Task<AcceptedResult> ExportFollowing()
|
||||
public async Task<FileContentResult> ExportFollowing()
|
||||
{
|
||||
var user = HttpContext.GetUserOrFail();
|
||||
|
||||
|
@ -79,9 +80,9 @@ public class SettingsController(DatabaseContext db, ImportExportService importEx
|
|||
if (followCount < 1)
|
||||
throw GracefulException.BadRequest("You do not follow any users");
|
||||
|
||||
await importExportSvc.ExportFollowingAsync(user);
|
||||
|
||||
return Accepted();
|
||||
var following = await importExportSvc.ExportFollowingAsync(user);
|
||||
|
||||
return File(Encoding.UTF8.GetBytes(following), "text/csv", $"following-{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.csv");
|
||||
}
|
||||
|
||||
[HttpPost("import/following")]
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System.Text;
|
||||
using Iceshrimp.Backend.Core.Configuration;
|
||||
using Iceshrimp.Backend.Core.Database;
|
||||
using Iceshrimp.Backend.Core.Database.Tables;
|
||||
|
@ -14,12 +13,11 @@ public class ImportExportService(
|
|||
ILogger<UserService> logger,
|
||||
IOptions<Config.InstanceSection> instance,
|
||||
CacheService cacheSvc,
|
||||
DriveService driveSvc,
|
||||
UserService userSvc,
|
||||
ActivityPub.UserResolver userResolver
|
||||
)
|
||||
{
|
||||
public async Task ExportFollowingAsync(User user)
|
||||
public async Task<string> ExportFollowingAsync(User user)
|
||||
{
|
||||
var followees = await db.Followings
|
||||
.Include(p => p.Followee)
|
||||
|
@ -31,15 +29,7 @@ public class ImportExportService(
|
|||
.Select(p => p.GetFqn(instance.Value.AccountDomain))
|
||||
.ToListAsync();
|
||||
|
||||
var stream = new MemoryStream(Encoding.UTF8.GetBytes(string.Join("\n", followees)));
|
||||
|
||||
await driveSvc.StoreFile(stream, user,
|
||||
new DriveFileCreationRequest
|
||||
{
|
||||
Filename = $"following-{DateTime.UtcNow:yyyy-MM-dd-HH-mm-ss}.csv",
|
||||
IsSensitive = false,
|
||||
MimeType = "text/csv"
|
||||
}, true);
|
||||
return string.Join("\n", followees);
|
||||
}
|
||||
|
||||
public async Task ImportFollowingAsync(User user, List<string> fqns)
|
||||
|
|
Loading…
Add table
Reference in a new issue