Skip to content

Commit 1f8d960

Browse files
committed
refactor: adjust PinkSea.Gateway based on the new lexicons.
1 parent eeb60b0 commit 1f8d960

File tree

6 files changed

+61
-26
lines changed

6 files changed

+61
-26
lines changed

PinkSea.Gateway/Lexicons/Author.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace PinkSea.Gateway.Lexicons;
4+
5+
/// <summary>
6+
/// The "com.shinolabs.pinksea.appViewDefs#author" object.
7+
/// </summary>
8+
public class Author
9+
{
10+
/// <summary>
11+
/// The DID of the author.
12+
/// </summary>
13+
[JsonPropertyName("did")]
14+
public required string Did { get; set; }
15+
16+
/// <summary>
17+
/// The handle of the author.
18+
/// </summary>
19+
[JsonPropertyName("handle")]
20+
public required string Handle { get; set; }
21+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace PinkSea.Gateway.Lexicons;
2+
3+
/// <summary>
4+
/// The response for the "com.shinolabs.pinksea.getOekaki" call.
5+
/// </summary>
6+
public class GetOekakiResponse
7+
{
8+
/// <summary>
9+
/// The parent post.
10+
/// </summary>
11+
public required OekakiDto Parent { get; set; }
12+
}

PinkSea.Gateway/OekakiDto.cs renamed to PinkSea.Gateway/Lexicons/OekakiDto.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
1-
namespace PinkSea.Gateway;
1+
using System.Text.Json.Serialization;
22

3+
namespace PinkSea.Gateway.Lexicons;
4+
5+
/// <summary>
6+
/// The "com.shinolabs.pinksea.appViewDefs#hydratedOekaki" type.
7+
/// </summary>
38
public class OekakiDto
49
{
510
/// <summary>
6-
/// The oekaki record key.
7-
/// </summary>
8-
public required string OekakiRecordKey { get; set; }
9-
10-
/// <summary>
11-
/// The DID of the author.
12-
/// </summary>
13-
public required string AuthorDid { get; set; }
14-
15-
/// <summary>
16-
/// The handle of the author.
11+
/// The author of the oekaki.
1712
/// </summary>
18-
public required string AuthorHandle { get; set; }
13+
[JsonPropertyName("author")]
14+
public required Author Author { get; set; }
1915

2016
/// <summary>
2117
/// The image link.
2218
/// </summary>
19+
[JsonPropertyName("image")]
2320
public required string ImageLink { get; set; }
2421

2522
/// <summary>
2623
/// The AT protocol link.
2724
/// </summary>
25+
[JsonPropertyName("at")]
2826
public required string AtProtoLink { get; set; }
2927

3028
/// <summary>
3129
/// The oekaki CID.
3230
/// </summary>
33-
public required string OekakiCid { get; set; }
31+
[JsonPropertyName("cid")]
32+
public required string Cid { get; set; }
3433

3534
/// <summary>
3635
/// The creation time.
3736
/// </summary>
37+
[JsonPropertyName("creationTime")]
3838
public required DateTimeOffset CreationTime { get; set; }
3939

4040
/// <summary>
4141
/// Is this oekaki NSFW?
4242
/// </summary>
43+
[JsonPropertyName("nsfw")]
4344
public required bool Nsfw { get; set; }
4445

4546
/// <summary>
4647
/// The tags for this oekaki post.
4748
/// </summary>
49+
[JsonPropertyName("tags")]
4850
public string[]? Tags { get; set; }
4951

5052
/// <summary>

PinkSea.Gateway/OekakiResponse.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

PinkSea.Gateway/Services/MetaGeneratorService.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.Caching.Memory;
22
using Microsoft.Extensions.Options;
3+
using PinkSea.Gateway.Lexicons;
34
using PinkSea.Gateway.Models;
45

56
namespace PinkSea.Gateway.Services;
@@ -27,7 +28,7 @@ public Task<string> GetOekakiMetaFor(string did, string rkey)
2728
async cacheEntry =>
2829
{
2930
using var client = httpClientFactory.CreateClient("pinksea-xrpc");
30-
var resp = await client.GetFromJsonAsync<OekakiResponse>(string.Format(endpointTemplate, did, rkey));
31+
var resp = await client.GetFromJsonAsync<GetOekakiResponse>(string.Format(endpointTemplate, did, rkey));
3132

3233
cacheEntry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(cacheExpiry);
3334

@@ -60,16 +61,21 @@ public string GetRegularMeta()
6061
/// </summary>
6162
/// <param name="resp">The response.</param>
6263
/// <returns>The formatted oekaki response.</returns>
63-
private string FormatOekakiResponse(OekakiResponse resp)
64+
private string FormatOekakiResponse(GetOekakiResponse resp)
6465
{
66+
var rkey = resp.Parent
67+
.AtProtoLink
68+
.Split('/')
69+
.Last();
70+
6571
return $"""
66-
<link rel="alternate" href="at://{resp.Parent.AuthorDid}/com.shinolabs.pinksea.oekaki/{resp.Parent.OekakiRecordKey}" />
72+
<link rel="alternate" href="{resp.Parent.AtProtoLink}" />
6773
<meta name="application-name" content="PinkSea">
6874
<meta name="generator" content="PinkSea.Gateway">
6975
<meta property="og:site_name" content="PinkSea" />
70-
<meta property="og:title" content="{resp!.Parent.AuthorHandle}'s oekaki" />
76+
<meta property="og:title" content="{resp!.Parent.Author.Handle}'s oekaki" />
7177
<meta property="og:type" content="website" />
72-
<meta property="og:url" content="{options.Value.FrontEndEndpoint}/{resp.Parent.AuthorDid}/oekaki/{resp.Parent.OekakiRecordKey}" />
78+
<meta property="og:url" content="{options.Value.FrontEndEndpoint}/{resp.Parent.Author.Did}/oekaki/{rkey}" />
7379
<meta property="og:image" content="{resp!.Parent.ImageLink}" />
7480
<meta property="og:description" content="{resp!.Parent.Alt}" />
7581
<meta name="theme-color" content="#FFB6C1">
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"GatewaySettings": {
3-
"AppViewEndpoint": "https://api.pinksea.art",
3+
"PinkSeaEndpoint": "https://api.pinksea.art",
44
"FrontEndEndpoint": "https://pinksea.art"
55
}
66
}

0 commit comments

Comments
 (0)