[391] | 1 | using System.IO;
|
---|
[402] | 2 | using Webserver.FileCache;
|
---|
[391] | 3 | using Webserver.UrlHandlers;
|
---|
| 4 |
|
---|
| 5 | namespace 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;
|
---|
[463] | 12 | /// <summary>
|
---|
| 13 | /// Absolute web path to the mod web root, e.g. "/webmods/myMod/"
|
---|
| 14 | /// </summary>
|
---|
| 15 | public readonly string ModUrl;
|
---|
| 16 | /// <summary>
|
---|
| 17 | /// Absolute web path to the React bundle if the mod has one, e.g. "/webmods/myMod/bundle.js"
|
---|
| 18 | /// </summary>
|
---|
| 19 | public readonly string ReactBundle;
|
---|
| 20 | /// <summary>
|
---|
| 21 | /// Absolute web path to a CSS if the mod has one, e.g. "/webmods/myMod/styling.css"
|
---|
| 22 | /// </summary>
|
---|
| 23 | public readonly string CssPath;
|
---|
[426] | 24 | public readonly bool IsWebMod;
|
---|
[391] | 25 |
|
---|
| 26 | public WebMod (Web _parentWeb, Mod _parentMod, bool _useStaticCache) {
|
---|
[426] | 27 | ParentMod = _parentMod;
|
---|
| 28 |
|
---|
[402] | 29 | string folder = $"{_parentMod.Path}/WebMod";
|
---|
[426] | 30 | IsWebMod = Directory.Exists (folder);
|
---|
[391] | 31 |
|
---|
[434] | 32 | if (!IsWebMod) {
|
---|
| 33 | return;
|
---|
| 34 | }
|
---|
[391] | 35 |
|
---|
[463] | 36 | ModUrl = $"{modsBaseUrl}{_parentMod.Name}/";
|
---|
[391] | 37 |
|
---|
[434] | 38 | ReactBundle = $"{folder}/{reactBundleName}";
|
---|
[463] | 39 | ReactBundle = File.Exists (ReactBundle) ? $"{ModUrl}{reactBundleName}" : null;
|
---|
[391] | 40 |
|
---|
[434] | 41 | CssPath = $"{folder}/{stylingFileName}";
|
---|
[463] | 42 | CssPath = File.Exists (CssPath) ? $"{ModUrl}{stylingFileName}" : null;
|
---|
[434] | 43 |
|
---|
[463] | 44 | _parentWeb.RegisterPathHandler (ModUrl, new StaticHandler (
|
---|
[434] | 45 | folder,
|
---|
| 46 | _useStaticCache ? new SimpleCache () : new DirectAccess (),
|
---|
| 47 | false)
|
---|
| 48 | );
|
---|
[391] | 49 | }
|
---|
| 50 | }
|
---|
| 51 | }
|
---|