source: TFP-WebServer/WebServer/src/WebMod.cs@ 449

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

Added permission management APIs

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 return;
24 }
25
26 string urlWebModBase = $"{modsBaseUrl}{_parentMod.FolderName}/";
27
28 ReactBundle = $"{folder}/{reactBundleName}";
29 ReactBundle = File.Exists (ReactBundle) ? $"{urlWebModBase}{reactBundleName}" : null;
30
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 );
39 }
40 }
41}
Note: See TracBrowser for help on using the repository browser.