source: binary-improvements2/WebServer/src/WebMod.cs@ 426

Last change on this file since 426 was 426, checked in by alloc, 19 months ago

*Updated web permissions system
*Fixed webpermissions command
*Moved API "webmods" to "mods", also lists non-webmod mods

File size: 1.3 KB
Line 
1using System.IO;
2using Webserver.FileCache;
3using Webserver.UrlHandlers;
4
5namespace Webserver {
6 public class WebMod {
7 private const string modsBaseUrl = "/webmods/";
8 private const string reactBundleName = "bundle.js";
9 private const string stylingFileName = "styling.css";
10
11 public readonly Mod ParentMod;
12 public readonly string ReactBundle; // Absolute web path to the React bundle if the mod has one, e.g. "/webmods/myMod/bundle.js"
13 public readonly string CssPath; // Absolute web path to a CSS if the mod has one, e.g. "/webmods/myMod/styling.css";
14 public readonly bool IsWebMod;
15
16 public WebMod (Web _parentWeb, Mod _parentMod, bool _useStaticCache) {
17 ParentMod = _parentMod;
18
19 string folder = $"{_parentMod.Path}/WebMod";
20 IsWebMod = Directory.Exists (folder);
21
22 if (IsWebMod) {
23 string urlWebModBase = $"{modsBaseUrl}{_parentMod.FolderName}/";
24
25 ReactBundle = $"{folder}/{reactBundleName}";
26 ReactBundle = File.Exists (ReactBundle) ? $"{urlWebModBase}{reactBundleName}" : null;
27
28 CssPath = $"{folder}/{stylingFileName}";
29 CssPath = File.Exists (CssPath) ? $"{urlWebModBase}{stylingFileName}" : null;
30
31 _parentWeb.RegisterPathHandler (urlWebModBase, new StaticHandler (
32 folder,
33 _useStaticCache ? new SimpleCache () : new DirectAccess (),
34 false)
35 );
36 }
37 }
38 }
39}
Note: See TracBrowser for help on using the repository browser.