[391] | 1 | using JetBrains.Annotations;
|
---|
[402] | 2 | using Utf8Json;
|
---|
[391] | 3 |
|
---|
[402] | 4 | namespace Webserver.WebAPI.APIs {
|
---|
[391] | 5 | [UsedImplicitly]
|
---|
[402] | 6 | public class WebMods : AbsRestApi {
|
---|
| 7 | private readonly byte[] loadedWebMods;
|
---|
[391] | 8 |
|
---|
[402] | 9 | public WebMods (Web _parent) {
|
---|
| 10 | JsonWriter writer = new JsonWriter ();
|
---|
| 11 | writer.WriteBeginArray ();
|
---|
| 12 |
|
---|
| 13 | bool first = true;
|
---|
[391] | 14 | foreach (WebMod webMod in _parent.webMods) {
|
---|
[402] | 15 | if (!first) {
|
---|
| 16 | writer.WriteValueSeparator ();
|
---|
| 17 | }
|
---|
| 18 | first = false;
|
---|
| 19 |
|
---|
| 20 | writer.WriteBeginObject ();
|
---|
| 21 |
|
---|
| 22 | writer.WriteString ("name");
|
---|
| 23 | writer.WriteNameSeparator ();
|
---|
| 24 | writer.WriteString (webMod.ParentMod.Name);
|
---|
[391] | 25 |
|
---|
| 26 | string webModReactBundle = webMod.ReactBundle;
|
---|
| 27 | if (webModReactBundle != null) {
|
---|
[402] | 28 | writer.WriteValueSeparator ();
|
---|
| 29 | writer.WriteString ("bundle");
|
---|
| 30 | writer.WriteNameSeparator ();
|
---|
| 31 | writer.WriteString (webModReactBundle);
|
---|
[391] | 32 | }
|
---|
[402] | 33 |
|
---|
[391] | 34 | string webModCssFile = webMod.CssPath;
|
---|
| 35 | if (webModCssFile != null) {
|
---|
[402] | 36 | writer.WriteValueSeparator ();
|
---|
| 37 | writer.WriteString ("css");
|
---|
| 38 | writer.WriteNameSeparator ();
|
---|
| 39 | writer.WriteString (webModCssFile);
|
---|
[391] | 40 | }
|
---|
[402] | 41 |
|
---|
| 42 | writer.WriteEndObject ();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | writer.WriteEndArray ();
|
---|
[391] | 46 |
|
---|
[402] | 47 | loadedWebMods = writer.ToUtf8ByteArray ();
|
---|
[391] | 48 | }
|
---|
| 49 |
|
---|
[402] | 50 | protected override void HandleRestGet (RequestContext _context) {
|
---|
| 51 | PrepareEnvelopedResult (out JsonWriter writer);
|
---|
| 52 | writer.WriteRaw (loadedWebMods);
|
---|
| 53 | SendEnvelopedResult (_context, ref writer);
|
---|
[391] | 54 | }
|
---|
| 55 |
|
---|
| 56 | public override int DefaultPermissionLevel () {
|
---|
| 57 | return 2000;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | }
|
---|