-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathComAtprotoRepo_DescribeRepo.cs
More file actions
61 lines (48 loc) · 1.7 KB
/
Copy pathComAtprotoRepo_DescribeRepo.cs
File metadata and controls
61 lines (48 loc) · 1.7 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
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using dnproto.repo;
using dnproto.ws;
using Microsoft.AspNetCore.Http;
namespace dnproto.pds.xrpc;
public class ComAtprotoRepo_DescribeRepo : BaseXrpcCommand
{
public IResult GetResponse()
{
IncrementStatistics();
//
// Get our did doc
//
string userDid = Pds.PdsDb.GetConfigProperty("UserDid");
string userHandle = Pds.PdsDb.GetConfigProperty("UserHandle");
ActorInfo? actorInfo = Pds.LocalFileSystem.ResolveActorInfo(userDid);
string didDocString = actorInfo?.DidDoc ?? "{}";
// Parse the did doc string to a JsonNode
JsonNode? didDocNode = JsonNode.Parse(didDocString);
// Get the collections
List<string> collections = Pds.PdsDb.GetUniqueCollections();
var response = new DescribeRepoResponse
{
Handle = userHandle,
Did = userDid,
DidDoc = didDocNode,
Collections = collections,
HandleIsCorrect = true
};
return Results.Json(response, contentType: "application/json");
}
}
public class DescribeRepoResponse
{
[JsonPropertyName("handle")]
public string Handle { get; set; } = string.Empty;
[JsonPropertyName("did")]
public string Did { get; set; } = string.Empty;
[JsonPropertyName("didDoc")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public JsonNode? DidDoc { get; set; }
[JsonPropertyName("collections")]
public List<string> Collections { get; set; } = new List<string>();
[JsonPropertyName("handleIsCorrect")]
public bool HandleIsCorrect { get; set; }
}