aboutsummaryrefslogtreecommitdiff
path: root/back-end/src/Endpoints/BookmarkEndpoint.cs
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-02-02 21:14:19 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2024-02-02 21:14:19 -0500
commit52645b724834e669788a45edb9d135f243432540 (patch)
tree56a5ea56fdf339f00934b3e4cd88212ea3608b29 /back-end/src/Endpoints/BookmarkEndpoint.cs
parentdd5e5164262c5ff7ecf6db1003d41d81e6364c09 (diff)
download file formats, button tweaks, more cache infra
Diffstat (limited to 'back-end/src/Endpoints/BookmarkEndpoint.cs')
-rw-r--r--back-end/src/Endpoints/BookmarkEndpoint.cs44
1 files changed, 35 insertions, 9 deletions
diff --git a/back-end/src/Endpoints/BookmarkEndpoint.cs b/back-end/src/Endpoints/BookmarkEndpoint.cs
index 05b72d0..e6e388d 100644
--- a/back-end/src/Endpoints/BookmarkEndpoint.cs
+++ b/back-end/src/Endpoints/BookmarkEndpoint.cs
@@ -19,7 +19,6 @@ using System.Linq;
using System.Buffers;
using System.Text.Json;
using System.Collections;
-using SimpleBookmark.Model;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Text.Json.Serialization;
@@ -43,6 +42,8 @@ using VNLib.Plugins.Extensions.Loading.Sql;
using VNLib.Plugins.Extensions.Data.Extensions;
using VNLib.Plugins.Extensions.Validation;
+using SimpleBookmark.Model;
+
namespace SimpleBookmark.Endpoints
{
@@ -123,7 +124,11 @@ namespace SimpleBookmark.Endpoints
*/
if(entity.QueryArgs.ContainsKey("export"))
{
- if (entity.Server.Accepts(ContentType.Html))
+ bool html = entity.Server.Accept.Contains("text/html");
+ bool csv = entity.Server.Accept.Contains("text/csv");
+ bool json = entity.Server.Accept.Contains("application/json");
+
+ if (html | csv | json)
{
//Get the collection of bookmarks
List<BookmarkEntry> list = Bookmarks.ListRental.Rent();
@@ -134,20 +139,41 @@ namespace SimpleBookmark.Endpoints
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);
+ if (html)
+ {
+ ImportExportUtil.ExportToNetscapeFile(list, output);
+
+ output.Seek(0, System.IO.SeekOrigin.Begin);
+ return VirtualClose(entity, HttpStatusCode.OK, ContentType.Html, output);
+ }
+ else if(csv)
+ {
+ ImportExportUtil.ExportAsCsv(list, output);
+
+ output.Seek(0, System.IO.SeekOrigin.Begin);
+ return VirtualClose(entity, HttpStatusCode.OK, ContentType.Csv, output);
+ }
+ else if(json)
+ {
+ ImportExportUtil.ExportAsJson(list, output);
+
+ output.Seek(0, System.IO.SeekOrigin.Begin);
+ return VirtualClose(entity, HttpStatusCode.OK, ContentType.Json, output);
+ }
}
catch
{
output.Dispose();
throw;
}
+ finally
+ {
+ list.TrimExcess();
+ Bookmarks.ListRental.Return(list);
+ }
}
- else
- {
- return VirtualClose(entity, HttpStatusCode.NotAcceptable);
- }
+
+ return VirtualClose(entity, HttpStatusCode.NotAcceptable);
}
//Get query parameters