-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathComAtprotoRepo_ListRecords.cs
More file actions
71 lines (54 loc) · 2.02 KB
/
Copy pathComAtprotoRepo_ListRecords.cs
File metadata and controls
71 lines (54 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Text.Json.Nodes;
using dnproto.repo;
using dnproto.ws;
using Microsoft.AspNetCore.Http;
namespace dnproto.pds.xrpc;
public class ComAtprotoRepo_ListRecords : BaseXrpcCommand
{
public IResult GetResponse()
{
IncrementStatistics();
//
// Get param
//
string? collection = HttpContext.Request.Query.ContainsKey("collection") ? (string?) HttpContext.Request.Query["collection"] : null;
if(collection == null)
{
return Results.Json(new { error = "InvalidRequest", message = "Error: Param 'collection' is required." }, statusCode: 400);
}
string? cursor = HttpContext.Request.Query.ContainsKey("cursor") ? (string?) HttpContext.Request.Query["cursor"] : null;
string? limitStr = HttpContext.Request.Query.ContainsKey("limit") ? (string?) HttpContext.Request.Query["limit"] : null;
string? reverseStr = HttpContext.Request.Query.ContainsKey("reverse") ? (string?) HttpContext.Request.Query["reverse"] : null;
int limit = 100;
if(limitStr != null)
{
int.TryParse(limitStr, out limit);
}
bool reverse = false;
if(reverseStr != null)
{
bool.TryParse(reverseStr, out reverse);
}
//
// Retrieve record
//
List<(string rkey, RepoRecord)> records = Pds.PdsDb.ListRepoRecordsByCollection(collection!, limit, cursor, reverse);
//
// Return value
//
var returnRecords = new JsonArray();
foreach(var r in records)
{
returnRecords.Add(new JsonObject
{
["uri"] = $"at://{Pds.PdsDb.GetConfigProperty("UserDid")}/{collection}/{r.rkey}",
["cid"] = r.Item2.Cid.Base32,
["value"] = r.Item2.JsonString != null ? JsonNode.Parse(r.Item2.JsonString)! : null
});
}
return Results.Json(new JsonObject
{
["records"] = returnRecords,
}, statusCode: 200);
}
}