Compare commits

..

22 Commits

Author SHA1 Message Date
ee7a714a4c
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 22:29:14 +01:00
068743a794
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 22:13:19 +01:00
9ceafa50f6
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 22:12:11 +01:00
e7c5b83f7a
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 22:11:25 +01:00
bff318f8bf
. 2022-08-17 22:08:41 +01:00
4180cb61f8
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 22:03:41 +01:00
d1080bce5b
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 22:02:23 +01:00
e926a50fb0
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 21:59:18 +01:00
a18502c68e
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 21:58:24 +01:00
f1c50b75e2
Fix main tag.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 21:57:06 +01:00
5f4fe169c8
Fix nav resizing.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 21:55:09 +01:00
efda456bcc
Add to resize event.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 21:44:52 +01:00
606be703fa
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 21:26:20 +01:00
fb018d9f4a
Fix missing .length
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 18:39:08 +01:00
a26a2df198
Try fix nav arrangement.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 18:35:43 +01:00
7c2e829df7
Fix nav arrangement.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 18:31:23 +01:00
c807754bea
Add nav resize utility functions.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 18:27:13 +01:00
685ea662f5
Fix font weighting.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 13:48:36 +01:00
6131f1612c
Provide the ability to get the nav item width of text.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 13:44:18 +01:00
67dd95be76
Remove explicit domain in the index yml.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 13:11:40 +01:00
380abaa4ea
.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 13:08:46 +01:00
5fcfb11c65
Provide a CSS Upgrade to prepare for JS supported nav modification on resize.
All checks were successful
continuous-integration/drone/push Build is passing
2022-08-17 13:04:03 +01:00
16 changed files with 60 additions and 310 deletions

8
.drone.yml Normal file
View File

@ -0,0 +1,8 @@
kind: pipeline
name: default
steps:
- name: build
image: golang
commands:
- make build

View File

@ -1,12 +0,0 @@
platform: linux/amd64
pipeline:
format:
image: golang
commands:
- files=$(gofmt -l .) && echo "$files" && [ -z "$files" ]
build:
image: golang
commands:
- make build

View File

@ -1,13 +1,13 @@
# Captain ALM Cityuni subdomain WebServer
[![Build Status](https://ci.mrmelon54.com/api/badges/alfred/cityuni-webserver/status.svg)](https://ci.mrmelon54.com/alfred/cityuni-webserver)
[![Build Status](https://ci.mrmelon54.xyz/api/badges/alfred/cityuni-webserver/status.svg)](https://ci.mrmelon54.xyz/alfred/cityuni-webserver)
This provides my template and cache supporting web / application server for my city university portfolio subdomain.
[Production Server](https://cityuni.captainalm.com/)
Maintainer:
[Captain ALM](https://code.mrmelon54.com/alfred)
[Captain ALM](https://code.mrmelon54.xyz/alfred)
License:
[BSD 3-Clause](https://code.mrmelon54.com/alfred/cityuni-webserver/src/branch/master/LICENSE)
[BSD 3-Clause](https://code.mrmelon54.xyz/alfred/GOPackageHeaderServer/src/branch/master/LICENSE)

View File

@ -6,7 +6,6 @@ Under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 Internati
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Times New Roman", Times, serif;
}
#st{
position: absolute;
@ -274,7 +273,7 @@ main{
overflow: hidden;
}
.item-table > div > div > div{
padding: 4px;
padding: 2px;
}
.item-table-caption, .so-pane-caption{
display: table-caption !important;

View File

@ -1,19 +0,0 @@
package conf
import "strings"
type PageYaml struct {
PageName string `yaml:"pageName"`
PagePath string `yaml:"pagePath"`
}
func (py PageYaml) GetPagePath() string {
toReturn := py.PagePath
if !strings.HasSuffix(toReturn, ".go") {
toReturn += ".go"
}
if !strings.HasPrefix(toReturn, "/") {
toReturn = "/" + toReturn
}
return toReturn
}

View File

@ -9,13 +9,10 @@ import (
type ServeYaml struct {
DataStorage string `yaml:"dataStorage"`
TemplateStorage string `yaml:"templateStorage"`
Domains []string `yaml:"domains"`
RangeSupported bool `yaml:"rangeSupported"`
EnableGoInfoPage bool `yaml:"enableGoInfoPage"`
CacheSettings CacheSettingsYaml `yaml:"cacheSettings"`
PageSettings []PageYaml `yaml:"pageSettings"`
YmlDataFallback bool `yaml:"ymlDataFallback"`
}
func (sy ServeYaml) GetDomainString() string {
@ -42,20 +39,3 @@ func (sy ServeYaml) GetDataStoragePath() string {
return sy.DataStorage
}
}
func (sy ServeYaml) GetTemplateStoragePath() string {
if sy.TemplateStorage == "" || !filepath.IsAbs(sy.TemplateStorage) {
wd, err := os.Getwd()
if err != nil {
return ""
} else {
if sy.TemplateStorage == "" {
return wd
} else {
return path.Join(wd, sy.TemplateStorage)
}
}
} else {
return sy.TemplateStorage
}
}

View File

@ -4,13 +4,9 @@ listen:
webMethod: "http"
identify: true
serve:
dataStorage: ""
domains: []
rangeSupported: true
enableGoInfoPage: true
cacheSettings:
enableTemplateCaching: false
enableTemplateCachePurge: false
enableContentsCaching: true
enableContentsCachePurge: true
maxAge: 3600

View File

@ -150,10 +150,6 @@
<th>Memory Page Size</th>
<td>{{ .PageSize }}</td>
</tr>
<tr>
<th>System Time</th>
<td>{{ .CurrentTime }}</td>
</tr>
</table>
</p>
<p>

View File

@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="Captain ALM's City University Portfolio">
<meta name="keywords" content="CaptainALM Captain_ALM Captain ALM portfolio Alfred Manville projects programming hacking cracking city uni cityuni cuol City University of London mycityuni">
<meta name="keywords" content="CaptainALM Captain_ALM Captain ALM portfolio Alfred Manville projects programming hacking cracking">
<title>City University Portfolio</title>
<link rel="stylesheet" href="{{ .Data.CSSBaseURL }}"/>
{{ if .Light }}
@ -155,15 +155,10 @@
<div class="item-table-360">
<div id="video-{{ $c }}">
{{ if eq .VideoLocation "" }}
<img src="{{ .GetVideoThumbnail $.Data.NoVideoImageLocation }}" alt="No Video" width="360px">
{{ else }}
{{ if .IsVideoLink }}
<a href="{{ .VideoLocation }}">
<img src="{{ .GetVideoThumbnail $.Data.PlayVideoImageLocation }}" alt="Play Video" title="Play" width="360px">
</a>
<img src="{{ $.Data.NoVideoImageLocation }}" alt="No Video" width="360px">
{{ else }}
<script type="application/javascript">
CreateVideoPlaceholder({{ $c }}, "{{ .GetVideoThumbnail $.Data.PlayVideoImageLocation }}")
CreateVideoPlaceholder({{ $c }})
</script>
<noscript>
<video controls width="360px">
@ -172,7 +167,6 @@
</video>
</noscript>
{{ end }}
{{ end }}
</div>
</div>
</div>

View File

@ -13,29 +13,25 @@ sortImageLocation: "resources/assets/sort.png"
headerLinks:
Main Portfolio: "https://portfolio.captainalm.com/"
Root Site Home: "https://www.captainalm.com/"
LinkedIn: "https://www.linkedin.com/in/alfred-manville/"
Github: "https://github.com/Captain-ALM/"
about:
title: "Alfred Manville (Captain ALM)"
content: >
<p>
Hello, I'm Alfred Manville (#age# Years Old) and a third year student at City, University of London.
Hello, I'm Alfred Manville (#age# Years Old).
I'm a free and open-source developer who enjoys networking my laptops together,
writes network software to communicate between them and then tries to break said software.
I also have a <a href="https://youtube.com/c/CaptainALM">Youtube Channel</a> which is in the process of being resumed from a hiatus.
</p>
<p>
On the programming side, I know Visual Basic .net, C# .net, C, Java, Go, Javascript, C++, Python, Bash,
Haskell, Processing and Microsoft Smallbasic (I have also dabbled in Batch).
On the programming side, I know Visual Basic .net, C# .net, C, Java, Go, Javascript (Circa. 2000 ECMAScript although I am learning the latest version of the language),
Processing and Microsoft Smallbasic (I have also dabbled in C++, Python and Bash/Batch).
I am currently in the progress of writing infrastructure software in Go, in the past, I wrote a <a href="https://github.com/Captain-ALM/CALM-Console">command console</a>
in VB .net for my own pluggable libraries (I created a CMD emulator to get past the school disabling interactive CMD) and some <a href="https://github.com/Captain-ALM/CALMNetLibSamples">
network communication applications</a> (Including a peer-to-peer <a href="https://github.com/Captain-ALM/C-ALM-VOIP">VOIP client</a>
using NAudio as the audio library and my own network wrapper library, however, it is in need of bug-fixing at the moment).
</p>
<p>
My github username is <a href="https://github.com/Captain-ALM">Captain-ALM</a> and has half my public programming projects,
the other half is located at: <a href="https://code.mrmelon54.com/alfred">https://code.mrmelon54.com/alfred</a>
</p>
<p>
On the cracking / hacking side, I've used virtual machines a lot (Mainly infrastructure testing
but I did at one point try creating and breaking into a test windows domain network I had setup).
I've also used VMs to pull perform a PXE boot off a network and analyse the partially deployed image
@ -55,9 +51,6 @@ about:
I used to do Karate (Kyokushin Brown Belt) and I wish I could still fit my bike.
Here is my <a href="https://cdn.captainalm.com/download/keys/alfred@captainalm.com.asc">GPG Key</a> for my email address.
</p>
<p>
My CV is available in the following formats: ( <a href="https://cdn.captainalm.com/download/cvs/AlfredManvilleCV-2024.docx">DOCX</a> | <a href="https://cdn.captainalm.com/download/cvs/AlfredManvilleCV-2024.pdf">PDF</a> )
</p>
thumbnailLocation: "resources/assets/imageofyou_t.jpg"
imageLocation: "resources/assets/imageofyou.jpg"
imageAltText: "Image of me."
@ -89,7 +82,6 @@ entries:
endDate: "31/10/2021"
videoLocation: "resources/stream/vid-bootcamp.mp4"
videoContentType: "video/mp4"
videoThumbnailLocation: "resources/assets/bootcamp-vid.png"
thumbnailLocations:
- "resources/assets/pic1_t.jpg"
- "resources/assets/pic2_t.jpg"
@ -149,7 +141,6 @@ entries:
endDate: "08/05/2022"
videoLocation: "resources/stream/vid-ninjaformer-2022.mp4"
videoContentType: "video/mp4"
videoThumbnailLocation: "resources/assets/ninjaformer-vid.png"
thumbnailLocations:
- "resources/assets/pic4_t.jpg"
- "resources/assets/pic5_t.jpg"
@ -190,7 +181,6 @@ entries:
endDate: "30/01/2022"
videoLocation: "resources/stream/vid-shadowwork.mp4"
videoContentType: "video/mp4"
videoThumbnailLocation: "resources/assets/shadowwork-vid.png"
thumbnailLocations:
- "resources/assets/shadowwork-2_t.jpg"
- "resources/assets/shadowwork-3_t.jpg"
@ -223,148 +213,6 @@ entries:
Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
</p>
<p>
Find the source code here: <a href="https://code.mrmelon54.com/alfred/cityuni-webserver">https://code.mrmelon54.com/alfred/cityuni-webserver</a>
Find the source code here: <a href="https://code.mrmelon54.xyz/alfred/cityuni-webserver">https://code.mrmelon54.xyz/alfred/cityuni-webserver</a>
</p>
startDate: "13/07/2022"
- name: "Python Communicator"
content: >
<p>
After learning python for my portfolio development option, I wanted to showcase what I knew in python.
I usually make a network application in each of the new programming languages that I learn.
For the repo showing me learning python please go to: <a href="https://code.mrmelon54.com/alfred/LearningPy">https://code.mrmelon54.com/alfred/LearningPy</a>
</p>
<p>
This project is a message based network communicator written in python and has a module for networking.
The project allows the sending of text messages and files over a network.
It also comes with a nice twist, in that if you select the pickle protocol, you can inject code into another client by sending a specially crafted message!
</p>
<p>
Find the source code here: <a href="https://github.com/Captain-ALM/CALMPyNetworker">https://github.com/Captain-ALM/CALMPyNetworker</a>
</p>
startDate: "10/12/2022"
endDate: "10/12/2022"
videoLocation: "resources/stream/vid-pycom.mp4"
videoContentType: "video/mp4"
videoThumbnailLocation: "resources/assets/pycom-vid.png"
thumbnailLocations:
- "resources/assets/pycom-1_t.jpg"
- "resources/assets/pycom-2_t.jpg"
- "resources/assets/pycom-3_t.jpg"
- "resources/assets/pycom-4_t.jpg"
imageLocations:
- "resources/assets/pycom-1.jpg"
- "resources/assets/pycom-2.jpg"
- "resources/assets/pycom-3.jpg"
- "resources/assets/pycom-4.jpg"
imageAltTexts:
- "Text Messaging."
- "File Messaging."
- "Exploit Testing."
- "Failed Exploit Testing."
- name: "Group Project - AirVia ATS (AirTicket Sales)"
content: >
<p>
This group project was creating a Ticket Sales system for the fictional company AirVia LTD, for this the group had to both design the implementation and then write the code for it.
Unfortunately, the project was not finished to a state where all the required features were added in and while all of the backend functionality except for the reports existed,
the GUIs to view and control those backends was not available.
Examples of this include: Sales, Transactions, Discounts and Reports where no GUIs were created or finished for any of these components.
The design of the program was followed with a lot of adaptations (Rather than not being followed at all) and it architecturally made sense with the use of facade implementations;
The use of facade allowed for other people to code against an interface while waiting for a controller to be finished which extended the interface.
</p>
<p>
The database system was handled via an abstraction layer I designed and wrote myself which supports 'locking' a record for keeping consistency when multiple instances of the program are running.
This system uses an auxiliary table that has only the primary key column, a record is locked if it does not exist in the auxiliary table (Cannot delete) and is not locked if it does (Cannot insert);
This allows for atomic locking and unlocking of the record.
The implementation requires the record locked for safe access (Loading, Storing).
The abstraction layer makes use of two base classes, one for a single record and one for a table; with tha table one allowing the creation and deletion of the extending table via a schema and name being provided (As seen in the source code).
I also developed a backup system for the database that supports any table with the specifically supported data types used in the tables defined in the schema - removing the need to use third-party programs like SQLDump.
</p>
<p>
In the end, the following features were implemented: Login, Help / Error / Status Bar, Account System + GUI, Blank Types + GUI, Blanks + GUI, Customers + GUI, Discounts, Flexible Discounts, Sales, Transactions, Refunds, Dashboard + Notifications, Database Interfacing + Backup and Rates + GUI.
</p>
<p>
Find the source code here: <a href="https://github.com/karansambee/IN2018-Team-Project/tree/master">https://github.com/karansambee/IN2018-Team-Project/tree/master</a>
</p>
startDate: "01/02/2023"
endDate: "30/04/2023"
videoLocation: "resources/stream/vid-groupproject-2023.mp4"
videoContentType: "video/mp4"
videoThumbnailLocation: "resources/assets/groupproject-vid.png"
thumbnailLocations:
- "resources/assets/groupproject-1_t.jpg"
- "resources/assets/groupproject-2_t.jpg"
- "resources/assets/groupproject-3_t.jpg"
- "resources/assets/groupproject-4_t.jpg"
- "resources/assets/groupproject-5_t.jpg"
- "resources/assets/groupproject-6_t.jpg"
- "resources/assets/groupproject-7_t.jpg"
- "resources/assets/groupproject-8_t.jpg"
- "resources/assets/groupproject-9_t.jpg"
- "resources/assets/groupproject-10_t.jpg"
imageLocations:
- "resources/assets/groupproject-1.png"
- "resources/assets/groupproject-2.png"
- "resources/assets/groupproject-3.png"
- "resources/assets/groupproject-4.png"
- "resources/assets/groupproject-5.png"
- "resources/assets/groupproject-6.png"
- "resources/assets/groupproject-7.png"
- "resources/assets/groupproject-8.png"
- "resources/assets/groupproject-9.png"
- "resources/assets/groupproject-10.png"
imageAltTexts:
- "Logon Interface."
- "Administrator Dashboard Interface."
- "Blank Modifier."
- "Customer Creator."
- "Disabling an Account."
- "Rate Creator."
- "Blank Type Editor."
- "Help on Force Unlocking (Database Manager Interface)."
- "Account Editor on a Manager within The Dashboard Interface."
- "Part of the Main.java source code Screenshot."
- name: "City-University Promotional Video"
content: >
<p>
Here, I star in an interview for City, University of London's Promotional Marketing Campaign. Join <a href="https://www.city.ac.uk/">City</a>!
</p>
<p>
Find the video here: <a href="https://www.youtube.com/watch?v=tOccImgskec">https://www.youtube.com/watch?v=tOccImgskec</a>
</p>
<p>
Find the general School of Science and Technology video here: <a href="https://www.youtube.com/watch?v=pkTCf4CWFSY">https://www.youtube.com/watch?v=pkTCf4CWFSY</a>
</p>
startDate: "05/06/2023"
endDate: "05/06/2023"
videoLocation: "https://www.youtube.com/watch?v=tOccImgskec"
videoContentType: "text/uri-list"
videoThumbnailLocation: "resources/assets/citypromo-vid.png"
- name: "Decide Quiz - GCloud City"
content: >
<p>
This project was <a href="https://cdn.captainalm.com/download/gcloudcity/CloudApplicationSpecification-AlfredManville-MohammadMasood.docx">designed</a> <a href="https://cdn.captainalm.com/download/gcloudcity/CloudPresentation-AlfredManville-MohammadMasood.pptx">to</a> operate as a Kahoot clone although the front-end never got completed by the other member of the pair (This was written in React).
</p>
<p>
This was created in a pair as part of the Cloud Computing module at City, University of London. It was built for use using google cloud and therefore
uses many Google Cloud Platform Technologies which are listed and shown off in the video.
</p>
<p>
The communication protocol uses JSON packets passed either through a WebSocket connection or a REST based protocol that polls the server for data while sending the queued packets.
The REST connection is used as a fallback system where WebSockets do not work; in addition, a REST connection is made to the master server to first work out which app server has
the least load, once found, this is sent back to the client where the client will then attempt a WebSocket connection and, on failure, a REST session is created (A key is returned
which is then used as a parameter in subsequent communications). In the event there is no more capacity, a service unavailable error is sent and a new VM will be spun up, in the case
that any are left. The source code for this library can be found at <a href="https://github.com/Captain-ALM/gc-c-com">https://github.com/Captain-ALM/gc-c-com</a> and the master server source
code can be found at <a href="https://github.com/Captain-ALM/gc-c-master-srv">https://github.com/Captain-ALM/gc-c-master-srv</a>.
</p>
<p>
The main game loop was supposed to allow user generated quizzes once logged in along-side allowing for public quizzes that could be used and copied by other users.
Only logged in users could start games where any user - both logged in or not - could join and answer questions within a set amount of time, with the person answering
the fastest getting more points than people who answer later. The system would also have a leaderboard shown at the end of each question; it was also designed to recover
from crashes and resume from the last question executed. The source code for the app server can be found at <a href="https://github.com/Captain-ALM/gc-c-app-srv">
https://github.com/Captain-ALM/gc-c-app-srv</a> where all this functionality does exist in the backend; the database source code can be found at <a href="https://github.com/Captain-ALM/gc-c-db">https://github.com/Captain-ALM/gc-c-db</a>.
</p>
startDate: "27/11/2023"
endDate: "14/01/2024"
videoLocation: "resources/stream/vid-gc-c-v2.mp4"
videoContentType: "video/mp4"
videoThumbnailLocation: "resources/assets/vid-gc-c-v2.png"

View File

@ -26,9 +26,9 @@ function CreateEntry(id, name, videourl, videotype, start, end, duration) {
duration : parseInt(duration, 10)
};
}
function CreateVideoPlaceholder(id,phImageURL) {
function CreateVideoPlaceholder(id) {
var imgPH = document.createElement("img")
imgPH.src = phImageURL
imgPH.src = PlayImageURL
imgPH.id = "play-"+id
imgPH.alt = "Play Video"
imgPH.title = "Play"
@ -67,7 +67,6 @@ function SetupIndexArray() {
function SetupJSTheme() {
var th = document.getElementById("theme")
th.href = "#"
new Image().src = MoonImageURL //Preload I hope
if (document.addEventListener) {
th.addEventListener("click", ToggleTheme)
} else {
@ -186,10 +185,10 @@ function EntrySort(o, s) {
SortValue = s
}
if (chg || OrderValue !== o) {
if (ts === "asc" || ts === "ascending") {
ts = 1
} else {
if (ts === "desc" || ts === "descending") {
ts = -1
} else {
ts = 1
}
var to = o.toString().toLowerCase()
if (to === "start") {

View File

@ -45,7 +45,6 @@ func (gipg *goInfoPage) GetCacheIDExtension(urlParameters url.Values) string {
type goInfoTemplateMarshal struct {
FullOutput bool
CurrentTime time.Time
RegisteredPages []string
CachedPages []string
ProcessID int
@ -99,7 +98,6 @@ func (gipg *goInfoPage) GetContents(urlParameters url.Values) (contentType strin
theBuffer := &io.BufferedWriter{}
err = theTemplate.ExecuteTemplate(theBuffer, templateName, &goInfoTemplateMarshal{
FullOutput: urlParameters.Has("full"),
CurrentTime: time.Now(),
RegisteredPages: regPages,
CachedPages: cacPages,
ProcessID: os.Getpid(),

View File

@ -43,9 +43,9 @@ func NewPageHandler(config conf.ServeYaml) *PageHandler {
CacheSettings: config.CacheSettings,
}
if config.EnableGoInfoPage {
toReturn.PageProviders = GetProviders(config.CacheSettings.EnableTemplateCaching, config.GetDataStoragePath(), toReturn, config.GetTemplateStoragePath(), config.PageSettings, config.YmlDataFallback)
toReturn.PageProviders = GetProviders(config.CacheSettings.EnableTemplateCaching, config.DataStorage, toReturn)
} else {
toReturn.PageProviders = GetProviders(config.CacheSettings.EnableTemplateCaching, config.GetDataStoragePath(), nil, config.GetTemplateStoragePath(), config.PageSettings, config.YmlDataFallback)
toReturn.PageProviders = GetProviders(config.CacheSettings.EnableTemplateCaching, config.DataStorage, nil)
}
return toReturn
}
@ -286,9 +286,6 @@ func (ph *PageHandler) GetRegisteredPages() []string {
}
func (ph *PageHandler) GetCachedPages() []string {
if ph.pageContentsCacheRWMutex == nil {
return make([]string, 0)
}
ph.pageContentsCacheRWMutex.RLock()
defer ph.pageContentsCacheRWMutex.RUnlock()
pages := make([]string, len(ph.PageContentsCache))
@ -301,9 +298,6 @@ func (ph *PageHandler) GetCachedPages() []string {
}
func (ph *PageHandler) GetNumberOfCachedPages() int {
if ph.pageContentsCacheRWMutex == nil {
return 0
}
ph.pageContentsCacheRWMutex.RLock()
defer ph.pageContentsCacheRWMutex.RUnlock()
return len(ph.PageContentsCache)

View File

@ -1,26 +1,18 @@
package pageHandler
import (
"golang.captainalm.com/cityuni-webserver/conf"
"golang.captainalm.com/cityuni-webserver/pageHandler/pages/index"
"strings"
)
import "golang.captainalm.com/cityuni-webserver/pageHandler/pages/index"
var providers map[string]PageProvider
func GetProviders(cacheTemplates bool, dataStorage string, pageHandler *PageHandler, templateStorage string, pageSettings []conf.PageYaml, ymlDataFallback bool) map[string]PageProvider {
func GetProviders(cacheTemplates bool, dataStorage string, pageHandler *PageHandler) map[string]PageProvider {
if providers == nil {
providers = make(map[string]PageProvider)
if pageHandler != nil {
infoPage := newGoInfoPage(pageHandler, dataStorage, cacheTemplates)
providers[infoPage.GetPath()] = infoPage //Go Information Page
}
for _, cpg := range pageSettings { //Register pages
if strings.EqualFold(cpg.PageName, index.PageName) {
indexPage := index.NewPage(dataStorage, cacheTemplates, templateStorage, cpg.GetPagePath(), ymlDataFallback)
indexPage := index.NewPage(dataStorage, cacheTemplates)
providers[indexPage.GetPath()] = indexPage
}
}
}
return providers
}

View File

@ -5,7 +5,6 @@ import (
"html/template"
"math"
"net/http"
"strings"
"time"
)
@ -21,7 +20,6 @@ type EntryYaml struct {
ThumbnailLocations []template.URL `yaml:"thumbnailLocations"`
ImageLocations []template.URL `yaml:"imageLocations"`
ImageAltTexts []string `yaml:"imageAltTexts"`
VideoThumbnailLocation template.URL `yaml:"videoThumbnailLocation"`
}
type ImageReference struct {
@ -30,18 +28,6 @@ type ImageReference struct {
ImageAltText string
}
func (ey EntryYaml) GetVideoThumbnail(usual template.URL) template.URL {
if ey.VideoThumbnailLocation == "" {
return usual
} else {
return ey.VideoThumbnailLocation
}
}
func (ey EntryYaml) IsVideoLink() bool {
return strings.EqualFold(ey.VideoContentType, "text/uri-list")
}
func (ey EntryYaml) GetStartDate() string {
return ey.StartDate.Format(dateFormat)
}

View File

@ -1,7 +1,6 @@
package index
import (
"errors"
"golang.captainalm.com/cityuni-webserver/utils/io"
"gopkg.in/yaml.v3"
"html/template"
@ -13,10 +12,10 @@ import (
"time"
)
const PageName = "index"
const templateName = "index.go.html"
const yamlName = "index.go.yml"
func NewPage(dataStore string, cacheTemplates bool, templateStore string, pagePath string, ymlDataFallback bool) *Page {
func NewPage(dataStore string, cacheTemplates bool) *Page {
var ptm *sync.Mutex
var sdm *sync.Mutex
if cacheTemplates {
@ -24,10 +23,7 @@ func NewPage(dataStore string, cacheTemplates bool, templateStore string, pagePa
sdm = &sync.Mutex{}
}
pageToReturn := &Page{
YMLDataFallback: ymlDataFallback,
PagePath: pagePath,
DataPath: path.Join(dataStore, pagePath),
TemplatePath: path.Join(templateStore, templateName),
DataStore: dataStore,
StoredDataMutex: sdm,
PageTemplateMutex: ptm,
}
@ -35,10 +31,7 @@ func NewPage(dataStore string, cacheTemplates bool, templateStore string, pagePa
}
type Page struct {
YMLDataFallback bool
PagePath string
DataPath string
TemplatePath string
DataStore string
StoredDataMutex *sync.Mutex
StoredData *DataYaml
LastModifiedData time.Time
@ -48,7 +41,7 @@ type Page struct {
}
func (p *Page) GetPath() string {
return p.PagePath
return "/index.go"
}
func (p *Page) GetLastModified() time.Time {
@ -136,12 +129,16 @@ func (p *Page) getPageTemplate() (*template.Template, error) {
defer p.PageTemplateMutex.Unlock()
}
if p.PageTemplate == nil {
stat, err := os.Stat(p.TemplatePath)
thePath := templateName
if p.DataStore != "" {
thePath = path.Join(p.DataStore, thePath)
}
stat, err := os.Stat(thePath)
if err != nil {
return nil, err
}
p.LastModifiedTemplate = stat.ModTime()
loadedData, err := os.ReadFile(p.TemplatePath)
loadedData, err := os.ReadFile(thePath)
if err != nil {
return nil, err
}
@ -164,19 +161,14 @@ func (p *Page) getPageData() (*DataYaml, error) {
defer p.StoredDataMutex.Unlock()
}
if p.StoredData == nil {
thePath := p.DataPath
thePath := yamlName
if p.DataStore != "" {
thePath = path.Join(p.DataStore, thePath)
}
stat, err := os.Stat(thePath)
if err != nil {
if p.YMLDataFallback && errors.Is(err, os.ErrNotExist) {
thePath += ".yml"
stat, err = os.Stat(thePath)
if err != nil {
return nil, err
}
} else {
return nil, err
}
}
p.LastModifiedData = stat.ModTime()
fileHandle, err := os.Open(thePath)
if err != nil {
@ -197,16 +189,15 @@ func (p *Page) getPageData() (*DataYaml, error) {
p.StoredData = dataYaml
}
return dataYaml, nil
} else {
return p.StoredData, nil
}
}
func getSortValue(toCheckIn string) int8 {
if toCheckIn == "asc" || toCheckIn == "ascending" {
return 1
} else {
if toCheckIn == "desc" || toCheckIn == "descending" {
return -1
} else {
return 1
}
}