source: TFP-WebServer/WebServer/src/WebAPI/APIs/GameData/Mods.cs@ 472

Last change on this file since 472 was 467, checked in by alloc, 15 months ago

21.1.16.2 WebServer release
Added "id"s to messages in log API / event
Added "baseUrl" to mods API for WebMods

File size: 2.7 KB
RevLine 
[391]1using JetBrains.Annotations;
[402]2using Utf8Json;
[426]3using Webserver.Permissions;
[391]4
[434]5namespace Webserver.WebAPI.APIs.GameData {
[391]6 [UsedImplicitly]
[426]7 public class Mods : AbsRestApi {
[402]8 private readonly byte[] loadedWebMods;
[391]9
[426]10 public Mods (Web _parent) {
[402]11 JsonWriter writer = new JsonWriter ();
12 writer.WriteBeginArray ();
13
[434]14 for (int i = 0; i < _parent.WebMods.Count; i++) {
15 WebMod webMod = _parent.WebMods [i];
[426]16
[408]17 if (i > 0) {
[402]18 writer.WriteValueSeparator ();
19 }
[426]20
21 writeModJson (ref writer, webMod);
[402]22 }
[408]23
[402]24 writer.WriteEndArray ();
[391]25
[402]26 loadedWebMods = writer.ToUtf8ByteArray ();
[391]27 }
28
[467]29 private static void writeModJson (ref JsonWriter _writer, WebMod _webMod) {
30 _writer.WriteBeginObject ();
31
[426]32 _writer.WritePropertyName ("name");
33 _writer.WriteString (_webMod.ParentMod.Name);
34
35 _writer.WriteValueSeparator ();
36 _writer.WritePropertyName ("displayName");
[434]37 _writer.WriteString (_webMod.ParentMod.DisplayName);
[426]38
39 _writer.WriteValueSeparator ();
40 _writer.WritePropertyName ("description");
[434]41 _writer.WriteString (_webMod.ParentMod.Description);
[426]42
43 _writer.WriteValueSeparator ();
44 _writer.WritePropertyName ("author");
[434]45 _writer.WriteString (_webMod.ParentMod.Author);
[426]46
47 _writer.WriteValueSeparator ();
48 _writer.WritePropertyName ("version");
[434]49 _writer.WriteString (_webMod.ParentMod.VersionString);
[426]50
51 _writer.WriteValueSeparator ();
52 _writer.WritePropertyName ("website");
[434]53 _writer.WriteString (_webMod.ParentMod.Website);
[467]54
55 writeWebModJson (ref _writer, _webMod);
56
57 _writer.WriteEndObject ();
[426]58 }
[432]59
[467]60 private static void writeWebModJson (ref JsonWriter _writer, WebMod _webMod) {
61 if (_webMod.ModUrl != null) {
62 _writer.WriteValueSeparator ();
63
64 _writer.WritePropertyName ("web");
65 _writer.WriteBeginObject ();
66
67 _writer.WritePropertyName ("baseUrl");
68 _writer.WriteString (_webMod.ModUrl);
69
70 string webModReactBundle = _webMod.ReactBundle;
71 if (webModReactBundle != null) {
72 _writer.WriteValueSeparator ();
73 _writer.WritePropertyName ("bundle");
74 _writer.WriteString (webModReactBundle);
75 }
76
77 string webModCssFile = _webMod.CssPath;
78 if (webModCssFile != null) {
79 _writer.WriteValueSeparator ();
80 _writer.WritePropertyName ("css");
81 _writer.WriteString (webModCssFile);
82 }
83
84 _writer.WriteEndObject ();
85 }
86 }
87
[432]88 protected override void HandleRestGet (RequestContext _context) {
89 PrepareEnvelopedResult (out JsonWriter writer);
90 writer.WriteRaw (loadedWebMods);
91 SendEnvelopedResult (_context, ref writer);
92 }
93
94 public override int DefaultPermissionLevel () => AdminWebModules.PermissionLevelGuest;
[391]95 }
[426]96}
Note: See TracBrowser for help on using the repository browser.