-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathComAtprotoRepo_DeleteRecord.cs
More file actions
87 lines (73 loc) · 2.34 KB
/
Copy pathComAtprotoRepo_DeleteRecord.cs
File metadata and controls
87 lines (73 loc) · 2.34 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System.Text.Json.Nodes;
using dnproto.repo;
using Microsoft.AspNetCore.Http;
namespace dnproto.pds.xrpc;
public class ComAtprotoRepo_DeleteRecord : BaseXrpcCommand
{
public IResult GetResponse()
{
IncrementStatistics();
Statistics.IncrementStatistics_ApplyWrites(HttpContext, Pds.PdsDb, Pds.Logger);
//
// Require auth
//
if(UserIsAuthenticated() == false)
{
var (response, statusCode) = GetAuthenticationFailureResponse();
return Results.Json(response, statusCode: statusCode);
}
//
// Get body input
//
JsonNode? requestBody = GetRequestBodyAsJson();
string? rkey, collection;
if(requestBody is null
|| ! CheckRequestBodyParam(requestBody, "collection", out collection)
|| ! CheckRequestBodyParam(requestBody, "rkey", out rkey)
|| string.IsNullOrEmpty(collection)
|| string.IsNullOrEmpty(rkey)
)
{
return Results.Json(new { error = "InvalidRequest", message = "Error: invalid params." }, statusCode: 400);
}
//
// Call UserRepo to delete record
//
Pds.UserRepo.ApplyWrites(new List<UserRepo.ApplyWritesOperation>
{
new UserRepo.ApplyWritesOperation
{
Type = UserRepo.ApplyWritesType.Delete,
Collection = collection,
Rkey = rkey
}
}
, GetCallerIpAddress(), GetCallerUserAgent());
//
// Get the new stuff
//
RepoCommit? repoCommit = Pds.PdsDb.GetRepoCommit();
//
// Return response
//
if(repoCommit is not null
&& repoCommit.Cid is not null
&& string.IsNullOrEmpty(repoCommit.Rev) == false
)
{
var responseObj = new JsonObject
{
["commit"] = new JsonObject
{
["cid"] = repoCommit.Cid.Base32,
["rev"] = repoCommit.Rev
}
};
return Results.Json(responseObj, statusCode: 200);
}
else
{
return Results.Json(new { error = "CreateRecordFailed", message = "Error creating record." }, statusCode: 400);
}
}
}