Swap swagger for waffle

This commit is contained in:
Melon 2022-10-30 14:14:33 +00:00
parent cb37844281
commit b5bb66634b
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
27 changed files with 143 additions and 216 deletions

View File

@ -2,5 +2,5 @@ package assets
import "embed" import "embed"
//go:embed swagger //go:embed waffle
var SwaggerAssets embed.FS var WaffleAssets embed.FS

Binary file not shown.

Before

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 628 B

View File

@ -1,16 +0,0 @@
html {
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
background: #fafafa;
}

View File

@ -1,19 +0,0 @@
<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="index.css" />
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="./swagger-initializer.js" charset="UTF-8"> </script>
</body>
</html>

View File

@ -1,79 +0,0 @@
<!doctype html>
<html lang="en-US">
<head>
<title>Swagger UI: OAuth2 Redirect</title>
</head>
<body>
<script>
'use strict';
function run () {
var oauth2 = window.opener.swaggerUIRedirectOauth2;
var sentState = oauth2.state;
var redirectUrl = oauth2.redirectUrl;
var isValid, qp, arr;
if (/code|token|error/.test(window.location.hash)) {
qp = window.location.hash.substring(1).replace('?', '&');
} else {
qp = location.search.substring(1);
}
arr = qp.split("&");
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
qp = qp ? JSON.parse('{' + arr.join() + '}',
function (key, value) {
return key === "" ? value : decodeURIComponent(value);
}
) : {};
isValid = qp.state === sentState;
if ((
oauth2.auth.schema.get("flow") === "accessCode" ||
oauth2.auth.schema.get("flow") === "authorizationCode" ||
oauth2.auth.schema.get("flow") === "authorization_code"
) && !oauth2.auth.code) {
if (!isValid) {
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "warning",
message: "Authorization may be unsafe, passed state was changed in server. The passed state wasn't returned from auth server."
});
}
if (qp.code) {
delete oauth2.state;
oauth2.auth.code = qp.code;
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
} else {
let oauthErrorMsg;
if (qp.error) {
oauthErrorMsg = "["+qp.error+"]: " +
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
(qp.error_uri ? "More info: "+qp.error_uri : "");
}
oauth2.errCb({
authId: oauth2.auth.name,
source: "auth",
level: "error",
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server."
});
}
} else {
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
}
window.close();
}
if (document.readyState !== 'loading') {
run();
} else {
document.addEventListener('DOMContentLoaded', function () {
run();
});
}
</script>
</body>
</html>

View File

@ -1,21 +0,0 @@
window.onload = function() {
//<editor-fold desc="Changeable Configuration Block">
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
urls: window.loadUrls,
"urls.primaryName": window.loadMain, // default document (if other than the first)
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
//</editor-fold>
};

View File

@ -1,26 +0,0 @@
window.onload = function() {
//<editor-fold desc="Changeable Configuration Block">
// the following lines will be replaced by docker/configurator, when it runs in a docker-container
window.ui = SwaggerUIBundle({
urls: [
{url: "spec/mailbox.yml", name: "Mailbox"},
{url: "spec/mailmaster.yml", name: "Mail Master"},
{url: "spec/mailconfig.yml", name: "Mail Config"},
{url: "spec/nginxconfig.yml", name: "NGINX Config"},
],
"urls.primaryName": "NGINX Config", // default document (if other than the first)
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
//</editor-fold>
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<title>Waffle</title>
<script type="module" crossorigin src="/assets/index.339c397e.js"></script>
<link rel="stylesheet" href="/assets/index.7a759c70.css">
</head>
<body>
<div id="app"></div>
</body>
</html>

View File

@ -25,8 +25,8 @@ import (
var ( var (
//go:embed pages/index.go.html //go:embed pages/index.go.html
indexTemplate string indexTemplate string
//go:embed pages/swagger.go.html //go:embed pages/waffle.go.html
swaggerTemplate string waffleTemplate string
returnCookie = "melon-tools-return-gitea" returnCookie = "melon-tools-return-gitea"
) )
@ -69,9 +69,9 @@ func (m *Module) SetupModule(router *mux.Router, f func(cb func(http.ResponseWri
router.HandleFunc("/login", m.sessionWrapper(m.loginPage)) router.HandleFunc("/login", m.sessionWrapper(m.loginPage))
router.PathPrefix("/spec/{org}/{repo}/{sha}/{spec:.+}").HandlerFunc(m.getClient(m.specPage)) router.PathPrefix("/spec/{org}/{repo}/{sha}/{spec:.+}").HandlerFunc(m.getClient(m.specPage))
router.PathPrefix("/spec-raw/{org}/{repo}/{sha}/{spec:.+}").HandlerFunc(m.getClient(m.specRawPage)) router.PathPrefix("/spec-raw/{org}/{repo}/{sha}/{spec:.+}").HandlerFunc(m.getClient(m.specRawPage))
router.PathPrefix("/swagger").HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { router.PathPrefix("/waffle").HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
p := filepath.Join("swagger", filepath.Base(req.URL.Path)) p := filepath.Join("waffle", "assets", filepath.Base(req.URL.Path))
open, err := assets.SwaggerAssets.Open(p) open, err := assets.WaffleAssets.Open(p)
if err != nil { if err != nil {
http.NotFound(rw, req) http.NotFound(rw, req)
return return
@ -356,7 +356,7 @@ func (m *Module) specPage(rw http.ResponseWriter, req *http.Request, state *util
return return
} }
tmp, err := template.New("swagger").Parse(swaggerTemplate) tmp, err := template.New("waffle").Parse(waffleTemplate)
if err != nil { if err != nil {
fmt.Println("Template parse error:", err) fmt.Println("Template parse error:", err)
return return

View File

@ -1,22 +0,0 @@
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Swagger | Gitea | Melon Tools</title>
<link rel="stylesheet" type="text/css" href="/gitea/swagger/swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="/gitea/swagger/index.css" />
<link rel="icon" type="image/png" href="/gitea/swagger/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/gitea/swagger/favicon-16x16.png" sizes="16x16" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="/gitea/swagger/swagger-ui-bundle.js" charset="UTF-8"></script>
<script src="/gitea/swagger/swagger-ui-standalone-preset.js" charset="UTF-8"></script>
<script src="/gitea/swagger/swagger-initializer-custom.js" charset="UTF-8"></script>
<script>
window.loadUrls = {{.LoadUrls}};
window.loadMain = {{.LoadMain}};
</script>
</body>
</html>

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
<title>{{.LoadMain}} | Waffle | Gitea | Melon Tools</title>
<script>
const config = {
primary: "{{.LoadMain}}",
specs: {{.LoadUrls}},
};
window.CONFIG_URL = "data:application/javascript;base64," + btoa(JSON.stringify(config));
</script>
<script type="module" crossorigin src="/gitea/waffle/index.339c397e.js"></script>
<link rel="stylesheet" href="/gitea/waffle/index.7a759c70.css">
</head>
<body>
<div id="app"></div>
</body>
</html>