source: binary-improvements2/WebServer/src/WebAPI/APIs/WebMods.cs@ 409

Last change on this file since 409 was 408, checked in by alloc, 21 months ago

Few pieces of code cleanup

File size: 1.5 KB
Line 
1using JetBrains.Annotations;
2using Utf8Json;
3
4namespace Webserver.WebAPI.APIs {
5 [UsedImplicitly]
6 public class WebMods : AbsRestApi {
7 private readonly byte[] loadedWebMods;
8
9 public WebMods (Web _parent) {
10 JsonWriter writer = new JsonWriter ();
11 writer.WriteBeginArray ();
12
13 for (int i = 0; i < _parent.webMods.Count; i++) {
14 WebMod webMod = _parent.webMods [i];
15
16 if (i > 0) {
17 writer.WriteValueSeparator ();
18 }
19
20 writer.WriteBeginObject ();
21
22 writer.WriteString ("name");
23 writer.WriteNameSeparator ();
24 writer.WriteString (webMod.ParentMod.Name);
25
26 string webModReactBundle = webMod.ReactBundle;
27 if (webModReactBundle != null) {
28 writer.WriteValueSeparator ();
29 writer.WriteString ("bundle");
30 writer.WriteNameSeparator ();
31 writer.WriteString (webModReactBundle);
32 }
33
34 string webModCssFile = webMod.CssPath;
35 if (webModCssFile != null) {
36 writer.WriteValueSeparator ();
37 writer.WriteString ("css");
38 writer.WriteNameSeparator ();
39 writer.WriteString (webModCssFile);
40 }
41
42 writer.WriteEndObject ();
43 }
44
45 writer.WriteEndArray ();
46
47 loadedWebMods = writer.ToUtf8ByteArray ();
48 }
49
50 protected override void HandleRestGet (RequestContext _context) {
51 PrepareEnvelopedResult (out JsonWriter writer);
52 writer.WriteRaw (loadedWebMods);
53 SendEnvelopedResult (_context, ref writer);
54 }
55
56 public override int DefaultPermissionLevel () => 2000;
57 }
58}
Note: See TracBrowser for help on using the repository browser.