a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[backend/federation] Refactor LdHelpers, move contexts to non-nested directory, load contexts relative to assembly location instead of working directory

+34 -44
Iceshrimp.Backend/Core/Federation/ActivityStreams/Contexts/default.json Iceshrimp.Backend/Core/Federation/ActivityStreams/Contexts/iceshrimp.json
+22 -44
Iceshrimp.Backend/Core/Federation/ActivityStreams/LDHelpers.cs Iceshrimp.Backend/Core/Federation/ActivityStreams/LdHelpers.cs
··· 1 1 using System.Collections.Concurrent; 2 + using System.Reflection; 2 3 using Iceshrimp.Backend.Core.Configuration; 3 4 using Iceshrimp.Backend.Core.Database.Tables; 4 5 using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types; ··· 12 13 13 14 public static class LdHelpers 14 15 { 16 + private static readonly string? AssemblyLocation = 17 + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? ""; 18 + 19 + private static readonly string Prefix = Path.Combine(AssemblyLocation, "contexts"); 20 + 21 + private static JToken GetPreloadedDocument(string filename) => 22 + JToken.Parse(File.ReadAllText(Path.Combine(Prefix, filename))); 23 + 24 + private static RemoteDocument GetPreloadedContext(string filename) => new() 25 + { 26 + Document = GetPreloadedDocument(filename) 27 + }; 28 + 15 29 private static readonly Dictionary<string, RemoteDocument> PreloadedContexts = new() 16 30 { 17 - { 18 - "https://www.w3.org/ns/activitystreams", new RemoteDocument 19 - { 20 - DocumentUrl = new Uri("https://www.w3.org/ns/activitystreams"), 21 - Document = JToken.Parse(File.ReadAllText(Path.Combine("Core", "Federation", "ActivityStreams", 22 - "Contexts", "as.json"))) 23 - } 24 - }, 25 - { 26 - "https://w3id.org/security/v1", new RemoteDocument 27 - { 28 - DocumentUrl = new Uri("https://w3c-ccg.github.io/security-vocab/contexts/security-v1.jsonld"), 29 - Document = JToken.Parse(File.ReadAllText(Path.Combine("Core", "Federation", "ActivityStreams", 30 - "Contexts", "security.json"))) 31 - } 32 - }, 33 - { 34 - "http://joinmastodon.org/ns", new RemoteDocument 35 - { 36 - Document = JToken.Parse(File.ReadAllText(Path.Combine("Core", "Federation", "ActivityStreams", 37 - "Contexts", "toot.json"))) 38 - } 39 - }, 40 - { 41 - "http://schema.org/", new RemoteDocument 42 - { 43 - Document = JToken.Parse(File.ReadAllText(Path.Combine("Core", "Federation", "ActivityStreams", 44 - "Contexts", "schema.json"))) 45 - } 46 - }, 47 - { 48 - "litepub-0.1", new RemoteDocument 49 - { 50 - Document = JToken.Parse(File.ReadAllText(Path.Combine("Core", "Federation", "ActivityStreams", 51 - "Contexts", "litepub.json"))) 52 - } 53 - } 31 + { "https://www.w3.org/ns/activitystreams", GetPreloadedContext("as.json") }, 32 + { "https://w3id.org/security/v1", GetPreloadedContext("security.json") }, 33 + { "http://joinmastodon.org/ns", GetPreloadedContext("toot.json") }, 34 + { "http://schema.org/", GetPreloadedContext("schema.json") }, 35 + { "litepub-0.1", GetPreloadedContext("litepub.json") } 54 36 }; 55 37 56 38 private static readonly ConcurrentDictionary<string, RemoteDocument> ContextCache = new(); 57 39 58 - private static readonly JToken DefaultContext = 59 - JToken.Parse(File.ReadAllText(Path.Combine("Core", "Federation", "ActivityStreams", "Contexts", 60 - "default.json"))); 40 + private static readonly JToken FederationContext = GetPreloadedDocument("iceshrimp.json"); 61 41 62 42 // Nonstandard extensions to the AS context need to be loaded in to fix federation with certain AP implementations 63 - private static readonly JToken ASExtensions = 64 - JToken.Parse(File.ReadAllText(Path.Combine("Core", "Federation", "ActivityStreams", "Contexts", 65 - "as-extensions.json"))); 43 + private static readonly JToken ASExtensions = GetPreloadedDocument("as-extensions.json"); 66 44 67 45 private static readonly JsonLdProcessorOptions Options = new() 68 46 { ··· 148 126 149 127 public static JObject? Compact(JToken? json) 150 128 { 151 - return JsonLdProcessor.Compact(json, DefaultContext, Options); 129 + return JsonLdProcessor.Compact(json, FederationContext, Options); 152 130 } 153 131 154 132 public static JArray? Expand(JToken? json)
+12
Iceshrimp.Backend/Iceshrimp.Backend.csproj
··· 64 64 <ItemGroup> 65 65 <Content Include="configuration.ini" CopyToOutputDirectory="Always"/> 66 66 </ItemGroup> 67 + 68 + <ItemGroup> 69 + <Content Update="Core\Federation\ActivityStreams\Contexts\*.json"> 70 + <CopyToOutputDirectory>Never</CopyToOutputDirectory> 71 + <CopyToPublishDirectory>Never</CopyToPublishDirectory> 72 + </Content> 73 + <ContentWithTargetPath Include="Core\Federation\ActivityStreams\Contexts\*.json"> 74 + <CopyToOutputDirectory>Always</CopyToOutputDirectory> 75 + <CopyToPublishDirectory>Always</CopyToPublishDirectory> 76 + <TargetPath>contexts\%(Filename)%(Extension)</TargetPath> 77 + </ContentWithTargetPath> 78 + </ItemGroup> 67 79 68 80 <ItemGroup> 69 81 <None Remove="Core\Database\prune-designer-cs-files.sh" />