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

Last change on this file since 436 was 434, checked in by alloc, 18 months ago

Added permission management APIs

File size: 1.3 KB
RevLine 
[391]1using System.IO;
[402]2using Webserver.FileCache;
[391]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";
[426]14 public readonly bool IsWebMod;
[391]15
16 public WebMod (Web _parentWeb, Mod _parentMod, bool _useStaticCache) {
[426]17 ParentMod = _parentMod;
18
[402]19 string folder = $"{_parentMod.Path}/WebMod";
[426]20 IsWebMod = Directory.Exists (folder);
[391]21
[434]22 if (!IsWebMod) {
23 return;
24 }
[391]25
[434]26 string urlWebModBase = $"{modsBaseUrl}{_parentMod.FolderName}/";
[391]27
[434]28 ReactBundle = $"{folder}/{reactBundleName}";
29 ReactBundle = File.Exists (ReactBundle) ? $"{urlWebModBase}{reactBundleName}" : null;
[391]30
[434]31 CssPath = $"{folder}/{stylingFileName}";
32 CssPath = File.Exists (CssPath) ? $"{urlWebModBase}{stylingFileName}" : null;
33
34 _parentWeb.RegisterPathHandler (urlWebModBase, new StaticHandler (
35 folder,
36 _useStaticCache ? new SimpleCache () : new DirectAccess (),
37 false)
38 );
[391]39 }
40 }
41}
Note: See TracBrowser for help on using the repository browser.