Update integrations and use Hugo-like data files

This commit is contained in:
Taras Kushnir
2025-07-28 15:52:45 +03:00
parent e351ed6fb1
commit a804f76012
16 changed files with 118 additions and 32 deletions
+6
View File
@@ -174,6 +174,11 @@ func run(ctx context.Context, cfg common.ConfigStore, stderr io.Writer, listener
return err
}
dataCtx, err := web.LoadData()
if err != nil {
return err
}
apiURLConfig := config.AsURL(ctx, cfg.Get(common.APIBaseURLKey))
sessionStore := db.NewSessionStore(pool, memory.New(), 1*time.Minute, session.KeyPersistent)
portalServer := &portal.Server{
@@ -194,6 +199,7 @@ func run(ctx context.Context, cfg common.ConfigStore, stderr io.Writer, listener
Metrics: metrics,
Mailer: portalMailer,
RateLimiter: ipRateLimiter,
DataCtx: dataCtx,
}
templatesBuilder := portal.NewTemplatesBuilder()
+2
View File
@@ -110,11 +110,13 @@ func (s *Server) RenderResponse(ctx context.Context, name string, data interface
Const interface{}
Ctx interface{}
Platform interface{}
Data interface{}
}{
Params: data,
Const: s.RenderConstants,
Ctx: reqCtx,
Platform: s.PlatformCtx,
Data: s.DataCtx,
}
var out bytes.Buffer
+1
View File
@@ -111,6 +111,7 @@ type Server struct {
RenderConstants interface{}
Jobs Jobs
PlatformCtx interface{}
DataCtx interface{}
}
func (s *Server) createSettingsTabs() []*SettingsTab {
+7
View File
@@ -54,6 +54,11 @@ func TestMain(m *testing.M) {
planService := billing.NewPlanService(nil)
testPlan = planService.GetInternalTrialPlan()
dataCtx, err := web.LoadData()
if err != nil {
panic(err)
}
if testing.Short() {
server = &Server{
Stage: common.StageTest,
@@ -65,6 +70,7 @@ func TestMain(m *testing.M) {
},
PuzzleEngine: &fakePuzzleEngine{result: &puzzle.VerifyResult{Error: puzzle.VerifyNoError}},
PlanService: planService,
DataCtx: dataCtx,
}
ctx := context.TODO()
@@ -116,6 +122,7 @@ func TestMain(m *testing.M) {
PuzzleEngine: &fakePuzzleEngine{result: &puzzle.VerifyResult{Error: puzzle.VerifyNoError}},
Metrics: monitoring.NewStub(),
PlanService: planService,
DataCtx: dataCtx,
}
ctx := context.TODO()
+37
View File
@@ -2,9 +2,11 @@ package web
import (
"embed"
"encoding/json"
"io/fs"
"log/slog"
"net/http"
"strings"
"github.com/PrivateCaptcha/PrivateCaptcha/pkg/common"
)
@@ -34,3 +36,38 @@ var templateFiles embed.FS
func Templates() *embed.FS {
return &templateFiles
}
//go:embed data/*.json
var dataFiles embed.FS
type DataContext map[string]interface{}
func LoadData() (DataContext, error) {
data := make(DataContext)
entries, err := dataFiles.ReadDir("data")
if err != nil {
return nil, err
}
for _, entry := range entries {
if !entry.Type().IsRegular() {
continue
}
content, err := dataFiles.ReadFile("data/" + entry.Name())
if err != nil {
return nil, err
}
var parsed interface{}
if err := json.Unmarshal(content, &parsed); err != nil {
return nil, err
}
key := strings.TrimSuffix(entry.Name(), ".json")
data[key] = parsed
}
return data, nil
}
+38
View File
@@ -0,0 +1,38 @@
[
{
"name": "Wordpress",
"icon": "img/integrations/wordpress.svg",
"link": "",
"ready": false
},
{
"name": "React",
"icon": "img/integrations/reactjs.svg",
"link": "https://docs.privatecaptcha.com/docs/integrations/react/",
"ready": true
},
{
"name": "Go",
"icon": "img/integrations/golang.svg",
"link": "https://docs.privatecaptcha.com/docs/integrations/go/",
"ready": true
},
{
"name": "Python",
"icon": "img/integrations/python.svg",
"link": "https://docs.privatecaptcha.com/docs/integrations/python/",
"ready": true
},
{
"name": "Javacript",
"icon": "img/integrations/javascript.svg",
"link": "https://docs.privatecaptcha.com/docs/integrations/javascript/",
"ready": true
},
{
"name": ".NET",
"icon": "img/integrations/dotnet.svg",
"link": "",
"ready": false
}
]
+11 -23
View File
@@ -77,38 +77,26 @@
<div class="mt-10">
<div class="mx-auto max-w-2xl lg:mx-0 lg:max-w-none">
<div class="flex items-center justify-between">
<h2 class="text-base font-semibold leading-7 text-gray-900">Other integrations</h2>
<div class="-mt-2 -ml-2 flex flex-wrap items-baseline">
<h3 class="mt-2 ml-2 text-base font-semibold text-gray-900">Other integrations</h3>
<p class="mt-1 ml-2 truncate text-sm text-gray-500">use sitekey <code class="rounded-md bg-gray-200 text-gray-800 px-1.5 py-1">{{ .Params.Sitekey }}</code></p>
</div>
<ul class="mt-6 grid grid-cols-1 gap-x-6 gap-y-8 lg:grid-cols-3 xl:gap-x-8">
{{ range $item := $.Data.integrations }}
<li class="overflow-hidden rounded-xl border border-gray-200">
<div class="flex items-center gap-x-4 border-b border-gray-900/5 bg-gray-50 p-6">
<img src="{{$.Ctx.CDN}}/portal/img/wordpress.png" alt="WordPress" class="h-10 w-10 p-1 flex-none rounded-lg bg-white object-contain ring-1 ring-gray-900/10">
<div class="text-sm font-medium leading-6 text-gray-900">WordPress</div>
<img src="{{$.Ctx.CDN}}/portal/{{$item.icon}}" alt="{{$item.name}} icon" class="h-10 w-10 p-1 flex-none rounded-lg bg-white object-contain ring-1 ring-gray-900/10">
<div class="text-sm font-medium leading-6 text-gray-900">{{$item.name}}</div>
<div class="ml-auto">
{{ if $item.ready }}
<a class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" href="{{$item.link}}" target="_blank">Setup</a>
{{ else }}
<span class="inline-flex items-center rounded-md bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-800 ring-1 ring-inset ring-yellow-600/20">Coming soon</span>
{{ end }}
</div>
</div>
<dl class="-my-3 x-6 py-4 text-sm leading-6">
<div class="flex justify-between gap-x-4 py-3 px-6">
<button type="button" class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" disabled>Setup</button>
</div>
</dl>
</li>
<li class="overflow-hidden rounded-xl border border-gray-200">
<div class="flex items-center gap-x-4 border-b border-gray-900/5 bg-gray-50 p-6">
<img src="{{$.Ctx.CDN}}/portal/img/React.svg" alt="WordPress" class="h-10 w-10 p-1 flex-none rounded-lg bg-white object-contain ring-1 ring-gray-900/10">
<div class="text-sm font-medium leading-6 text-gray-900">React</div>
<div class="ml-auto">
<span class="inline-flex items-center rounded-md bg-yellow-50 px-2 py-1 text-xs font-medium text-yellow-800 ring-1 ring-inset ring-yellow-600/20">Coming soon</span>
</div>
</div>
<dl class="-my-3 x-6 py-4 text-sm leading-6">
<div class="flex justify-between gap-x-4 py-3 px-6">
<button type="button" class="inline-flex items-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50" disabled>Setup</button>
</div>
</dl>
</li>
{{ end }}
</ul>
</div>
</div>
-9
View File
@@ -1,9 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-11.5 -10.23174 23 20.46348">
<title>React Logo</title>
<circle cx="0" cy="0" r="2.05" fill="#61dafb"/>
<g stroke="#61dafb" stroke-width="1" fill="none">
<ellipse rx="11" ry="4.2"/>
<ellipse rx="11" ry="4.2" transform="rotate(60)"/>
<ellipse rx="11" ry="4.2" transform="rotate(120)"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 366 B

+1
View File
@@ -0,0 +1 @@
<svg width="51" height="52" viewBox="0 0 51 52" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M25.442 51.108c14.01 0 25.367-11.357 25.367-25.367S39.452.374 25.442.374.075 11.73.075 25.74s11.357 25.367 25.367 25.367" fill="#5C2D91"/><g fill="#fff"><path opacity=".1" d="M7.86 7.508a25.367 25.367 0 1 0 35.815 35.816z"/><path d="M5.94 33.073a1.07 1.07 0 0 1-.792-.333 1.1 1.1 0 0 1-.325-.792 1.1 1.1 0 0 1 .325-.793 1.06 1.06 0 0 1 .793-.34 1.1 1.1 0 0 1 .792.34 1.1 1.1 0 0 1 .333.793 1.1 1.1 0 0 1-.333.792 1.1 1.1 0 0 1-.792.333m15.752-.198h-2.077L12.187 21.35a4.8 4.8 0 0 1-.46-.904h-.063q.105.988.08 1.982v10.448h-1.689V18.424h2.196l7.23 11.32q.45.705.586.967h.04a15 15 0 0 1-.103-2.124V18.424h1.688zm11.431 0h-7.681V18.424h7.325v1.53H27.17v4.804h5.216v1.522H27.17v5.01h5.961zm11.344-12.921h-4.201v12.921h-1.689V19.954h-4.154v-1.53h10.044z"/></g></svg>

After

Width:  |  Height:  |  Size: 865 B

+1
View File
@@ -0,0 +1 @@
<svg width="60" height="23" viewBox="0 0 60 23" fill="none" xmlns="http://www.w3.org/2000/svg"><g fill="#00ACD7"><path d="M5.767 7.54c-.08 0-.159-.08-.08-.16l.556-.792c.079-.08.158-.158.317-.158h9.988c.08 0 .159.079.08.158l-.476.714c-.08.079-.159.158-.318.158zm-4.202 2.536c-.079 0-.158-.08-.079-.158l.555-.793c.08-.08.159-.159.317-.159h12.763c.08 0 .159.08.159.159l-.238.793c0 .079-.159.158-.238.158zm6.739 2.616c-.08 0-.159-.08-.08-.159l.397-.713c.079-.08.158-.159.317-.159h5.549c.08 0 .158.08.158.16l-.079.633a.17.17 0 0 1-.158.159zm29.013-5.708-4.677 1.19c-.396.079-.475.158-.792-.318-.397-.475-.714-.792-1.348-1.03-1.744-.872-3.488-.634-5.073.396-1.903 1.19-2.854 3.013-2.854 5.312 0 2.22 1.585 4.042 3.805 4.36 1.902.237 3.488-.397 4.756-1.824.238-.317.476-.634.793-1.03h-5.39c-.556 0-.714-.397-.556-.872.397-.872 1.031-2.3 1.427-3.013.08-.158.317-.475.714-.475h10.147c-.08.793-.08 1.506-.159 2.299-.317 1.982-1.03 3.884-2.299 5.47-1.982 2.615-4.598 4.28-7.927 4.756-2.775.396-5.311-.159-7.53-1.823q-3.093-2.379-3.568-6.184c-.397-3.012.555-5.787 2.378-8.165 1.982-2.616 4.598-4.28 7.848-4.835 2.616-.476 5.153-.159 7.372 1.347 1.507.951 2.537 2.3 3.25 3.964.08.317 0 .396-.317.475"/><path d="M46.513 22.443c-2.537-.08-4.836-.793-6.817-2.458-1.665-1.427-2.696-3.25-3.013-5.39-.475-3.171.397-5.946 2.3-8.403 2.06-2.695 4.518-4.043 7.847-4.677 2.854-.476 5.55-.238 7.927 1.427 2.22 1.506 3.568 3.567 3.964 6.262.476 3.805-.634 6.818-3.17 9.434-1.824 1.902-4.123 3.012-6.66 3.567-.872.159-1.664.159-2.378.238m6.659-11.257c0-.396 0-.634-.08-.951-.475-2.775-3.012-4.36-5.707-3.726-2.616.555-4.28 2.22-4.915 4.836-.475 2.14.555 4.36 2.537 5.31 1.506.635 3.092.556 4.518-.158 2.3-1.11 3.488-2.933 3.647-5.311"/></g></svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

@@ -0,0 +1 @@
<svg width="53" height="52" viewBox="0 0 53 52" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M4.048 3.751h45.086v44.393H4.048z" fill="#F5DE19"/><path d="M30.342 30.196a4.57 4.57 0 0 0 1.721 1.863 4.67 4.67 0 0 0 2.465.673c1.755 0 2.878-.864 2.878-2.06 0-1.428-1.153-1.938-3.085-2.77l-1.06-.448c-3.06-1.282-5.088-2.888-5.088-6.284 0-3.129 2.415-5.511 6.204-5.511a6.34 6.34 0 0 1 3.523.777 6.2 6.2 0 0 1 2.502 2.563l-3.312 2.085a2.85 2.85 0 0 0-1.077-1.311 2.9 2.9 0 0 0-1.643-.477 1.87 1.87 0 0 0-1.413.454 1.82 1.82 0 0 0-.614 1.334c0 1.25.788 1.758 2.605 2.537l1.06.447c3.6 1.52 5.636 3.07 5.636 6.552 0 3.756-2.997 5.814-7.02 5.814a8.24 8.24 0 0 1-4.502-1.009 8.07 8.07 0 0 1-3.22-3.257zm-14.967.361c.665 1.162 1.27 2.145 2.726 2.145 1.39 0 2.27-.536 2.27-2.62V15.895h4.237v14.241c0 4.319-2.577 6.285-6.327 6.285a6.66 6.66 0 0 1-3.776-.933 6.5 6.5 0 0 1-2.58-2.872z" fill="#000"/></svg>

After

Width:  |  Height:  |  Size: 899 B

+1
View File
@@ -0,0 +1 @@
<svg version="1.0" width="111.161" height="111.161" xmlns="http://www.w3.org/2000/svg"><path style="fill:#306998;fill-opacity:1" d="M54.919 0c-4.584.022-8.961.413-12.813 1.095C30.76 3.099 28.7 7.295 28.7 15.032v10.219h26.813v3.406H18.638c-7.793 0-14.616 4.684-16.75 13.594-2.462 10.213-2.571 16.586 0 27.25 1.905 7.938 6.457 13.594 14.25 13.594h9.218v-12.25c0-8.85 7.657-16.657 16.75-16.657h26.782c7.454 0 13.406-6.138 13.406-13.625v-25.53c0-7.267-6.13-12.726-13.406-13.938C64.282.328 59.502-.02 54.918 0m-14.5 8.22c2.77 0 5.031 2.298 5.031 5.125 0 2.816-2.262 5.093-5.031 5.093-2.78 0-5.031-2.277-5.031-5.093 0-2.827 2.251-5.125 5.03-5.125"/><path style="fill:#ffd43b;fill-opacity:1" d="M85.638 28.657v11.906c0 9.231-7.826 17-16.75 17H42.106c-7.336 0-13.406 6.279-13.406 13.625V96.72c0 7.266 6.319 11.54 13.406 13.625 8.488 2.495 16.627 2.946 26.782 0 6.75-1.955 13.406-5.888 13.406-13.625V86.5H55.513v-3.405H95.7c7.793 0 10.696-5.436 13.406-13.594 2.8-8.399 2.68-16.476 0-27.25-1.925-7.758-5.604-13.594-13.406-13.594zM70.575 93.313c2.78 0 5.031 2.278 5.031 5.094 0 2.827-2.251 5.125-5.031 5.125-2.77 0-5.031-2.298-5.031-5.125 0-2.816 2.261-5.094 5.031-5.094"/></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

+1
View File
@@ -0,0 +1 @@
<svg width="57" height="52" viewBox="0 0 57 52" fill="none" xmlns="http://www.w3.org/2000/svg"><g fill="#00D8FF"><path d="M28.533 29.663c2.394 0 4.335-1.774 4.335-3.963s-1.941-3.964-4.335-3.964-4.335 1.774-4.335 3.964 1.94 3.963 4.335 3.963"/><path d="M28.533 34.787a53.6 53.6 0 0 1-15.399-1.902 20.3 20.3 0 0 1-6.342-3.104 5.8 5.8 0 0 1-1.757-1.787 5.3 5.3 0 0 1-.78-2.294c0-2.621 3.15-5.19 8.425-6.87a54.2 54.2 0 0 1 15.853-2.137 54 54 0 0 1 15.645 2.099 20.4 20.4 0 0 1 6.135 2.958 5.6 5.6 0 0 1 1.73 1.72c.43.683.693 1.444.767 2.23 0 2.723-3.52 5.484-9.19 7.2a54.3 54.3 0 0 1-15.087 1.887m0-16.198A52.7 52.7 0 0 0 13.36 20.62c-4.855 1.55-7.032 3.668-7.032 5.074 0 1.471 2.34 3.784 7.476 5.39a51.3 51.3 0 0 0 14.728 1.806c4.884.08 9.752-.524 14.436-1.791 5.332-1.616 7.76-3.932 7.76-5.4a3.5 3.5 0 0 0-.59-1.415 3.9 3.9 0 0 0-1.161-1.08 18.3 18.3 0 0 0-5.482-2.622 51.8 51.8 0 0 0-14.963-1.994"/><path d="M18.683 45.468a4.9 4.9 0 0 1-2.317-.52c-2.483-1.31-3.343-5.086-2.3-10.104 1.148-4.802 3.14-9.403 5.895-13.623 2.585-4.235 5.895-8.064 9.803-11.343a20.1 20.1 0 0 1 5.868-3.382 6.35 6.35 0 0 1 2.496-.508c.862 0 1.714.174 2.495.508 2.582 1.36 3.437 5.527 2.232 10.875a43.6 43.6 0 0 1-5.75 12.895c-2.495 4.184-5.7 7.98-9.496 11.245a20 20 0 0 1-6.11 3.47 9.3 9.3 0 0 1-2.816.487m3.075-23.306a42.2 42.2 0 0 0-5.653 13.031c-.96 4.622-.039 7.401 1.3 8.108 1.387.734 4.755.038 8.844-3.228 3.624-3.128 6.683-6.761 9.064-10.765a41.7 41.7 0 0 0 5.516-12.329c1.134-5.033.154-8.116-1.236-8.848a4.38 4.38 0 0 0-3.24.141 18 18 0 0 0-5.22 3.041c-3.733 3.14-6.894 6.806-9.363 10.859z"/><path d="M38.377 45.49c-2.35 0-5.334-1.3-8.441-3.744-3.977-3.308-7.343-7.183-9.966-11.474-2.721-4.163-4.697-8.697-5.851-13.43-.5-2.083-.593-4.23-.274-6.342a5.06 5.06 0 0 1 .764-2.224 5.6 5.6 0 0 1 1.723-1.72c2.578-1.364 6.953.039 11.419 3.663 3.712 3.206 6.864 6.914 9.346 10.994a43 43 0 0 1 5.914 13.138 16.4 16.4 0 0 1 .237 6.574 5.3 5.3 0 0 1-.81 2.284 5.85 5.85 0 0 1-1.78 1.767 4.8 4.8 0 0 1-2.28.513M21.765 29.317c2.517 4.1 5.731 7.809 9.523 10.985 3.9 3.068 6.994 3.728 8.324 3.013 1.387-.738 2.41-3.747 1.356-8.616a41.2 41.2 0 0 0-5.672-12.542c-2.37-3.905-5.378-7.455-8.922-10.528-4.204-3.412-7.613-4.174-9.002-3.439a3.8 3.8 0 0 0-1.043 1.176c-.256.453-.405.95-.44 1.46a14.8 14.8 0 0 0 .266 5.652 41.5 41.5 0 0 0 5.611 12.842z"/></g></svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.0 KiB

+10
View File
@@ -0,0 +1,10 @@
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="wordpress" clip-path="url(#clip0_1_429)">
<path id="Vector" d="M4.1659 24.3442C4.1659 32.2853 8.78062 39.1472 15.4723 42.3995L5.90277 16.1798C4.7556 18.7486 4.16373 21.5308 4.1659 24.3442ZM37.7702 23.3318C37.7702 25.0492 37.1102 27.0422 36.2426 29.817L34.2419 36.5037L26.9921 14.9384C28.1992 14.875 29.2882 14.7471 29.2882 14.7471C30.3689 14.6192 30.2418 13.0309 29.1596 13.0946C29.1596 13.0946 25.9111 13.3492 23.8131 13.3492C21.8418 13.3492 18.5288 13.0946 18.5288 13.0946C17.4478 13.0309 17.321 14.6838 18.4021 14.7471C18.4021 14.7471 19.4255 14.875 20.5058 14.9384L23.6318 23.5017L19.2411 36.6687L11.9356 14.9388C13.1449 14.8754 14.2321 14.7475 14.2321 14.7475C15.312 14.6196 15.1845 13.0313 14.1031 13.095C14.1031 13.095 10.8549 13.3496 8.75657 13.3496C8.38019 13.3496 7.93624 13.3401 7.46557 13.326C11.0527 7.87945 17.2187 4.28356 24.2273 4.28356C29.4501 4.28356 34.2053 6.28 37.7748 9.54989C37.6878 9.54493 37.6034 9.53386 37.5145 9.53386C35.5444 9.53386 34.1461 11.2505 34.1461 13.0946C34.1461 14.7471 35.0989 16.1465 36.1158 17.799C36.8797 19.1355 37.7702 20.8525 37.7702 23.3318ZM24.5792 26.099L30.7464 42.9931C30.7855 43.0894 30.8333 43.1819 30.8892 43.2695C28.8038 44.0024 26.5634 44.4067 24.2273 44.4067C22.3088 44.4067 20.4003 44.1313 18.5601 43.589L24.5792 26.099ZM41.8303 14.7193C43.4478 17.6691 44.2932 20.98 44.2879 24.3442C44.2879 31.7455 40.2763 38.207 34.3122 41.6849L40.44 23.9678C41.5852 21.1063 41.9654 18.8179 41.9654 16.7821C41.9654 16.0446 41.9166 15.3583 41.8303 14.7193ZM24.2273 0.959473C37.1213 0.959473 47.6135 11.4498 47.6139 24.3442C47.6139 37.2405 37.1213 47.7304 24.2273 47.7304C11.3325 47.7304 0.841812 37.2401 0.841812 24.3442C0.841812 11.4498 11.3329 0.959473 24.2273 0.959473ZM24.2273 46.6581C36.5296 46.6581 46.5393 36.648 46.5393 24.3442C46.5393 12.0414 36.53 2.03213 24.2273 2.03213C11.9238 2.03213 1.91409 12.0414 1.91409 24.3442C1.91409 36.648 11.9242 46.6581 24.2273 46.6581Z" fill="#00749A"/>
</g>
<defs>
<clipPath id="clip0_1_429">
<rect width="46.7709" height="46.7709" fill="white" transform="translate(0.841812 0.959473)"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB