aboutsummaryrefslogtreecommitdiff
path: root/back-end/src/Endpoints
diff options
context:
space:
mode:
Diffstat (limited to 'back-end/src/Endpoints')
-rw-r--r--back-end/src/Endpoints/BookmarkEndpoint.cs39
1 files changed, 38 insertions, 1 deletions
diff --git a/back-end/src/Endpoints/BookmarkEndpoint.cs b/back-end/src/Endpoints/BookmarkEndpoint.cs
index ec46097..05b72d0 100644
--- a/back-end/src/Endpoints/BookmarkEndpoint.cs
+++ b/back-end/src/Endpoints/BookmarkEndpoint.cs
@@ -30,7 +30,9 @@ using FluentValidation.Results;
using Microsoft.EntityFrameworkCore;
using VNLib.Utils;
-using VNLib.Utils.Logging;
+using VNLib.Utils.IO;
+using VNLib.Utils.Memory;
+using VNLib.Net.Http;
using VNLib.Plugins;
using VNLib.Plugins.Essentials;
using VNLib.Plugins.Essentials.Accounts;
@@ -113,6 +115,41 @@ namespace SimpleBookmark.Endpoints
return VirtualOk(entity, webm);
}
+ /*
+ * Allow exporting the current user's bookmark collection as a
+ * netscape file for compatability.
+ *
+ * Future support for CSV file via an accept content type header
+ */
+ if(entity.QueryArgs.ContainsKey("export"))
+ {
+ if (entity.Server.Accepts(ContentType.Html))
+ {
+ //Get the collection of bookmarks
+ List<BookmarkEntry> list = Bookmarks.ListRental.Rent();
+ await Bookmarks.GetUserPageAsync(list, entity.Session.UserID, 0, (int)BmConfig.PerPersonQuota);
+
+ //Alloc memory stream for output
+ VnMemoryStream output = new(MemoryUtil.Shared, 16 * 1024, false);
+ try
+ {
+ //Write the bookmarks as a netscape file and return the file
+ ImportExportUtil.ExportToNetscapeFile(list, output);
+ output.Seek(0, System.IO.SeekOrigin.Begin);
+ return VirtualClose(entity, HttpStatusCode.OK, ContentType.Html, output);
+ }
+ catch
+ {
+ output.Dispose();
+ throw;
+ }
+ }
+ else
+ {
+ return VirtualClose(entity, HttpStatusCode.NotAcceptable);
+ }
+ }
+
//Get query parameters
_ = entity.QueryArgs.TryGetNonEmptyValue("limit", out string? limitS);
_ = uint.TryParse(limitS, out uint limit);