Skip to content

Commit

Permalink
404 page added.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwarzlichtbezirk committed Feb 14, 2024
1 parent cc57952 commit 4982a81
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 11 deletions.
61 changes: 61 additions & 0 deletions frontend/build/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<title>hms - 404</title>
<link rel="shortcut icon" href="/asst/hms.256.ico" type="image/vnd.microsoft.icon" />
<link rel="apple-touch-icon" href="/asst/hms.256.png" type="image/png" />
</head>

<body>
<!-- normalize -->
<link rel="stylesheet" type="text/css" href="/plug/normalize.min.css?8.0.1">
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="/plug/bootstrap.min.css?5.3.2">
<!-- Google fonts -->
<link rel="stylesheet" type="text/css" href="/asst/iconfont/material-icons.css">

<!-- Project CSS -->
<link rel="stylesheet" type="text/css" href="/devm/stat.css?0.9.3">
<link rel="stylesheet" type="text/css" href="" id="skinmodel">

<div class="main">
<div class="d-flex flex-column justify-content-center align-items-center w-100 vh-100">
<div class="card hms-card" style="min-width: 18rem; width: 40%;">
<div class="card-body card-body">
<h4 class="card-title">404 page not found</h4>
<p class="card-text">Pointed URL does not refers to any resource.</p>
<a href="/" class="card-link">open main page</a>
<a href="/dev/id1/ctgr/shares/" class="card-link">open shares</a>
</div>
</div>
</div>
</div>

<!-- Popper.js, then Bootstrap JS -->
<script src="/plug/popper.min.js?2.11.8"></script>
<script src="/plug/bootstrap.min.js?5.3.2"></script>

<script>
(async () => {
// load resources model at first
const response = await fetch("/fs/assets/resmodel.json");
if (!response.ok) {
throw new HttpError(response.status, { what: "can not load resources model file", when: Date.now(), code: 0 });
}
const resmodel = await response.json();

// set skin
const id = JSON.parse(sessionStorage.getItem('skinid')) ?? resmodel.defskinid;
for (const v of resmodel.skinlist) {
if (v.id === id) {
document.getElementById('skinmodel')?.setAttribute('href', v.link);
}
}
})();
</script>
</body>
</html>
61 changes: 61 additions & 0 deletions frontend/devmode/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<title>hms - 404</title>
<link rel="shortcut icon" href="/asst/hms.256.ico" type="image/vnd.microsoft.icon" />
<link rel="apple-touch-icon" href="/asst/hms.256.png" type="image/png" />
</head>

<body>
<!-- normalize -->
<link rel="stylesheet" type="text/css" href="/plug/normalize.min.css?8.0.1">
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="/plug/bootstrap.min.css?5.3.2">
<!-- Google fonts -->
<link rel="stylesheet" type="text/css" href="/asst/iconfont/material-icons.css">

<!-- Project CSS -->
<link rel="stylesheet" type="text/css" href="/devm/stat.css?0.9.3">
<link rel="stylesheet" type="text/css" href="" id="skinmodel">

<div class="main">
<div class="d-flex flex-column justify-content-center align-items-center w-100 vh-100">
<div class="card hms-card" style="min-width: 18rem; width: 40%;">
<div class="card-body card-body">
<h4 class="card-title">404 page not found</h4>
<p class="card-text">Pointed URL does not refers to any resource.</p>
<a href="/" class="card-link">open main page</a>
<a href="/dev/id1/ctgr/shares/" class="card-link">open shares</a>
</div>
</div>
</div>
</div>

<!-- Popper.js, then Bootstrap JS -->
<script src="/plug/popper.min.js?2.11.8"></script>
<script src="/plug/bootstrap.min.js?5.3.2"></script>

<script>
(async () => {
// load resources model at first
const response = await fetch("/fs/assets/resmodel.json");
if (!response.ok) {
throw new HttpError(response.status, { what: "can not load resources model file", when: Date.now(), code: 0 });
}
const resmodel = await response.json();

// set skin
const id = JSON.parse(sessionStorage.getItem('skinid')) ?? resmodel.defskinid;
for (const v of resmodel.skinlist) {
if (v.id === id) {
document.getElementById('skinmodel')?.setAttribute('href', v.link);
}
}
})();
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion frontend/devmode/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const fetchjsonauth = async (method, url, body) => {
});
if (resp0.status === 401 && auth.refrsh) { // Unauthorized
const resp1 = await fetch("/api/auth/refresh", { // get new token
method: "POST",
method: "GET",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
Expand Down
4 changes: 4 additions & 0 deletions frontend/skin/dark/card.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
color: #fff;
}

.hms-card .card-body {
color: rgba(255, 255, 255, 0.66);
}

.hms-card .dropdown-menu {
background: #333333;
}
Expand Down
4 changes: 4 additions & 0 deletions frontend/skin/matrix/card.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
color: PaleGreen;
}

.hms-card .card-body {
color: rgba(128, 255, 128, 0.66);
}

.hms-card .dropdown-menu {
background: #003c00;
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ require (
require (
github.com/bytedance/sonic v1.10.2 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.17.0 // indirect
github.com/go-playground/validator/v10 v10.18.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
Expand Down
7 changes: 4 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo=
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/chenzhuoyu/iasm v0.9.1 h1:tUHQJXo3NhBqw6s33wkGn9SP3bvrWLdlVIJ3hQBL7P0=
github.com/chenzhuoyu/iasm v0.9.1/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -54,8 +55,8 @@ github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74=
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtPsPm2S9NAZ5nl9U=
github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
Expand Down
2 changes: 1 addition & 1 deletion server/api-content.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/gin-gonic/gin"
)

// APIHANDLER
// Distributes static pages.
func SpiPage(pref, fname string) gin.HandlerFunc {
return func(c *gin.Context) {
var content, ok = pagecache[pref+"/"+fname]
Expand Down
9 changes: 8 additions & 1 deletion server/auth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hms

import (
"bytes"
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
Expand Down Expand Up @@ -224,7 +225,13 @@ func GetBearerAuth(tokenstr string) (prf *Profile, code int, err error) {
}

func Handle404(c *gin.Context) {
Ret404(c, SEC_nourl, Err404)
if strings.HasPrefix(c.Request.RequestURI, "/api/") {
Ret404(c, SEC_nourl, Err404)
return
}
var content = pagecache[devmsuff+"/404.html"]
c.Header("Content-Type", "text/html; charset=utf-8")
http.ServeContent(c.Writer, c.Request, "404.html", starttime, bytes.NewReader(content))
}

type AuthResp struct {
Expand Down
3 changes: 3 additions & 0 deletions server/routes-gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var pagecache = map[string][]byte{}
var pagealias = map[string]string{
"/": "main.html",
"/stat": "stat.html",
"/404": "404.html",
}

// Routes aliases.
Expand Down Expand Up @@ -216,6 +217,8 @@ func Router(r *gin.Engine) {
rdev.GET(fpath, SpiPage(devmsuff, fname)) // development mode
r.GET(fpath, SpiPage(relmsuff, fname)) // release mode
}
dacc.GET("/ctgr/:cat", SpiPage(devmsuff, pagealias["/"]))
gacc.GET("/ctgr/:cat", SpiPage(relmsuff, pagealias["/"]))
dacc.GET("/path/*path", SpiPage(devmsuff, pagealias["/"]))
gacc.GET("/path/*path", SpiPage(relmsuff, pagealias["/"]))

Expand Down
2 changes: 1 addition & 1 deletion task/cc-base.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if not exist %cc% (
https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/%cv%/closure-compiler-%cv%.jar
)

java -jar %cc%^
"%JAVA_HOME%\bin\java.exe" -jar %cc%^
--js %wd%\plugin\leaflet.js^
--js %wd%\plugin\leaflet.markercluster.js^
--js %wd%\plugin\sha256.min.js^
Expand Down
2 changes: 1 addition & 1 deletion task/cc-page.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if not exist %cc% (
https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/%cv%/closure-compiler-%cv%.jar
)

java -jar %cc%^
"%JAVA_HOME%\bin\java.exe" -jar %cc%^
--js %wd%\devmode\relmode.js^
--js %wd%\devmode\common.js^
--js %wd%\devmode\request.js^
Expand Down
2 changes: 1 addition & 1 deletion task/cs-skin.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set retval=%~f1
exit /b

:compileskin
java -jar %cs%^
"%JAVA_HOME%\bin\java.exe" -jar %cs%^
%wd%\%~1\page.css^
%wd%\%~1\card.css^
%wd%\%~1\icon.css^
Expand Down

0 comments on commit 4982a81

Please sign in to comment.