forked from fiatjaf/pyramid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.templ
More file actions
1049 lines (1043 loc) · 40.4 KB
/
Copy pathsettings.templ
File metadata and controls
1049 lines (1043 loc) · 40.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package main
import (
"fmt"
"slices"
"strings"
"fiatjaf.com/nostr"
"fiatjaf.com/nostr/eventstore/bleve"
"github.com/fiatjaf/pyramid/global"
"github.com/fiatjaf/pyramid/layout"
"github.com/fiatjaf/pyramid/search"
)
templ settingsPage(loggedUser nostr.PubKey) {
@layout.Layout(loggedUser, "settings") {
<div class="max-w-4xl mx-auto">
<!-- landlubber link -->
<div class="mb-6 flex justify-end">
@layout.LandlubberButton("")
</div>
<!-- relay metadata -->
@layout.RelayMetadata(global.RelayMain,
global.Settings.RelayName, global.Settings.RelayDescription, global.Settings.RelayIcon,
global.Settings.Pinned)
<!-- theme colors -->
<form
method="POST"
action="/settings"
class="space-y-6 mt-8"
x-data={ `{
accentColor: '`+global.Settings.Theme.AccentColor+`',
backgroundColor: '`+global.Settings.Theme.BackgroundColor+`',
textColor: '`+global.Settings.Theme.TextColor+`',
secondaryBgColor: '`+global.Settings.Theme.SecondaryBackgroundColor+`',
extraColor: '`+global.Settings.Theme.ExtraColor+`',
baseColor: '`+global.Settings.Theme.BaseColor+`',
headerTransparency: '`+global.Settings.Theme.HeaderTransparency+`',
primaryFont: '`+global.Settings.Theme.PrimaryFont+`',
secondaryFont: '`+global.Settings.Theme.SecondaryFont+`',
saved: false,
updateTheme() {
document.documentElement.style.setProperty('--accent-color', this.accentColor);
document.documentElement.style.setProperty('--bg-color', this.backgroundColor);
document.documentElement.style.setProperty('--text-color', this.textColor);
document.documentElement.style.setProperty('--secondary-bg-color', this.secondaryBgColor);
document.documentElement.style.setProperty('--extra-color', this.extraColor);
document.documentElement.style.setProperty('--base-color', this.baseColor);
document.documentElement.style.setProperty('--header-transparency', this.headerTransparency + '%');
document.documentElement.style.setProperty('--primary-font', this.primaryFont);
document.documentElement.style.setProperty('--secondary-font', this.secondaryFont);
},
saveSettings(event) {
setTimeout(async () => {
const response = await fetch(this.$refs.form.action, {
method: 'POST',
body: new URLSearchParams(new FormData(this.$refs.form))
});
if (response.ok) {
this.saved = true;
setTimeout(() => this.saved = false, 2000);
}
}, 1)
},
resetTheme() {
this.accentColor = '';
this.backgroundColor = '';
this.textColor = '';
this.secondaryBgColor = '';
this.extraColor = '';
this.baseColor = '';
this.headerTransparency = '60';
this.primaryFont = 'Inter';
this.secondaryFont = 'system-ui';
setTimeout(() => this.$refs.form.submit(), 1)
},
enableCustomTheme() {
function gen (baseLight, baseSat) {
let h = Math.random() * 360
let s = (baseSat + Math.random() * 10) / 100
let l = (baseLight + Math.random() * 10) / 100
const a = s * Math.min(l, 1 - l)
const f = n => {
const k = (n + h / 30) % 12
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1)
return Math.round(255 * color).toString(16).padStart(2, '0')
}
return "#" + f(0) + f(8) + f(4)
}
this.accentColor = gen(60, 80);
this.backgroundColor = gen(90, 50);
this.textColor = gen(30, 60);
this.secondaryBgColor = '#ffffff';
this.extraColor = gen(50, 90);
this.baseColor = '#000000';
this.headerTransparency = '60';
this.primaryFont = 'Inter';
this.secondaryFont = 'sans';
setTimeout(() => this.$refs.form.submit(), 1)
}
}` }
x-init="updateTheme()"
x-ref="form"
>
@layout.SubSectionTitle("theme colors")
<div class="mb-4 themed:hidden">
<button
type="button"
@click.prevent="enableCustomTheme()"
class="cursor-pointer px-6 py-2 rounded-lg font-semibold bg-stone-700 hover:bg-stone-800 dark:bg-stone-600 dark:hover:bg-stone-500 text-white shadow-md hover:shadow-lg"
>
enable custom theme
</button>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 unthemed:hidden">
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300">primary color</label>
<input
type="color"
name="accent_color"
x-model="accentColor"
@input="updateTheme()"
@blur="saveSettings()"
class="w-full h-10 rounded border border-stone-300 cursor-pointer"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300">background color</label>
<input
type="color"
name="background_color"
x-model="backgroundColor"
@input="updateTheme()"
@blur="saveSettings()"
class="w-full h-10 rounded border border-stone-300 cursor-pointer"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300">text color</label>
<input
type="color"
name="text_color"
x-model="textColor"
@input="updateTheme()"
@blur="saveSettings()"
class="w-full h-10 rounded border border-stone-300 cursor-pointer"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300">secondary background color</label>
<input
type="color"
name="secondary_background_color"
x-model="secondaryBgColor"
@input="updateTheme()"
@blur="saveSettings()"
class="w-full h-10 rounded border border-stone-300 cursor-pointer"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300">extra color</label>
<input
type="color"
name="extra_color"
x-model="extraColor"
@input="updateTheme()"
@blur="saveSettings()"
class="w-full h-10 rounded border border-stone-300 cursor-pointer"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300">base color</label>
<input
type="color"
name="base_color"
x-model="baseColor"
@input="updateTheme()"
@blur="saveSettings()"
class="w-full h-10 rounded border border-stone-300 cursor-pointer"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300">header transparency</label>
<input
type="range"
name="header_transparency"
min="0"
max="100"
value="100"
x-model="headerTransparency"
@input="updateTheme()"
@blur="saveSettings()"
class="w-full h-10 rounded border border-stone-300"
/>
</div>
<!-- Font Settings -->
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300">primary font</label>
<select
name="primary_font"
x-model="primaryFont"
@change="updateTheme()"
@blur="saveSettings()"
class="w-full px-3 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
>
@fontOptions()
</select>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300">secondary font</label>
<select
name="secondary_font"
x-model="secondaryFont"
@change="updateTheme()"
@blur="saveSettings()"
class="w-full px-3 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
>
@fontOptions()
</select>
</div>
</div>
<div class="flex justify-between items-center mt-4 unthemed:hidden">
<button
type="button"
@click="resetTheme()"
class="cursor-pointer px-4 py-2 rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-700 dark:hover:bg-stone-600 text-stone-700 dark:text-stone-300 font-medium"
>
reset
</button>
<div
x-show="saved"
x-transition
class="text-sm text-green-600 dark:text-green-400 font-medium"
>
saved!
</div>
</div>
</form>
<!-- General Settings Section -->
<form
method="POST"
action="/settings"
class="space-y-6 mt-8"
x-data={ `{
nip05Enabled: ` + fmt.Sprint(global.Settings.NIP05.Enabled) + `,
maxInvitesPerPerson: ` + global.JSONString(global.Settings.GetMaxInvitesDisplay()) + `,
requireCurrentTimestamp: ` + fmt.Sprint(global.Settings.RequireCurrentTimestamp) + `,
acceptScheduledEvents: ` + fmt.Sprint(global.Settings.AcceptScheduledEvents) + `,
allowEphemeralFromAnyone: ` + fmt.Sprint(global.Settings.AllowEphemeralFromAnyone) + `,
validateSchema: ` + fmt.Sprint(global.Settings.ValidateSchema) + `,
browseUri: ` + global.JSONString(global.Settings.BrowseURI) + `,
linkUrl: ` + global.JSONString(global.Settings.LinkURL) + `,
saved: false,
async saveSettings() {
const response = await fetch(this.$refs.form.action, {
method: 'POST',
body: new URLSearchParams(new FormData(this.$refs.form))
})
if (response.ok) {
this.saved = true;
setTimeout(() => this.saved = false, 2000)
}
}
}` }
x-ref="form"
>
@layout.SubSectionTitle("general")
<div class="space-y-4">
<div class="flex justify-between gap-4 items-center">
<label for="require_current_timestamp" class="text-sm dark:text-stone-300 flex items-center">
<input
type="checkbox"
name="require_current_timestamp"
id="require_current_timestamp"
class="w-4 h-6 rounded border-stone-300 dark:border-stone-600 mr-2"
x-model="requireCurrentTimestamp"
@change="saveSettings()"
/>
require event timestamps to be current (within ±60 seconds)
</label>
<input type="hidden" name="require_current_timestamp" value="off"/>
<label for="accept_scheduled_events" class="text-sm dark:text-stone-300 flex items-center">
<input
type="checkbox"
name="accept_scheduled_events"
id="accept_scheduled_events"
class="w-4 h-6 rounded border-stone-300 dark:border-stone-600 mr-2"
x-model="acceptScheduledEvents"
@change="saveSettings()"
/>
accept scheduled events
</label>
<input type="hidden" name="accept_scheduled_events" value="off"/>
</div>
<div class="flex items-center">
<input
type="checkbox"
name="validate_schema"
id="validate_schema"
class="w-4 h-6 rounded border-stone-300 dark:border-stone-600"
x-model="validateSchema"
@change="saveSettings()"
/>
<label for="validate_schema" class="ml-2 text-sm font-medium dark:text-stone-300">
validate main relay events against schema
</label>
<input type="hidden" name="validate_schema" value="off"/>
</div>
<div class="flex items-center">
<input
type="checkbox"
name="allow_ephemeral_from_anyone"
id="allow_ephemeral_from_anyone"
class="w-4 h-6 rounded border-stone-300 dark:border-stone-600"
x-model="allowEphemeralFromAnyone"
@change="saveSettings()"
/>
<label for="allow_ephemeral_from_anyone" class="ml-2 text-sm font-medium dark:text-stone-300">
allow ephemeral events from non-members
</label>
<input type="hidden" name="allow_ephemeral_from_anyone" value="off"/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="max_invites_per_person">max invites per person</label>
<input
type="text"
name="max_invites_per_person"
id="max_invites_per_person"
placeholder="e.g. 4 or 5/4/3/2/1"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
x-model="maxInvitesPerPerson"
@blur="saveSettings()"
/>
<p class="text-xs text-stone-500 dark:text-stone-400 mt-1">
use a single number or slash-separated values for the number of invites available at each level (e.g. "5/4/3/2")
</p>
</div>
<div class="flex items-center">
<input
type="checkbox"
name="nip05_enabled"
id="nip05_enabled"
class="w-4 h-6 rounded border-stone-300 dark:border-stone-600"
x-model="nip05Enabled"
@change="saveSettings()"
/>
<label for="nip05_enabled" class="ml-2 text-sm font-medium dark:text-stone-300">
enable NIP-05 addresses for members
</label>
<input type="hidden" name="nip05_enabled" value="off"/>
</div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="allowed kinds">allowed kinds</label>
<div class="space-y-2">
<textarea
name="allowed_kinds_spec"
placeholder="examples:
1, 3, 6, 7, 20, 21, 22, 1111
all
+1227, +30818, -7"
class="w-full px-3 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100 h-24 font-mono text-sm"
@blur="saveSettings()"
>{ global.Settings.AllowedKindsSpec }</textarea>
<p class="text-xs text-stone-500 dark:text-stone-400">
comma-separated numbers set the full list, "all" allows all kinds, and "+/-" entries add or remove from the default list
</p>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="browse_uri">URL pattern for the relay "browse" links</label>
<div class="flex flex-wrap gap-2 items-center">
<input
type="text"
name="browse_uri"
id="browse_uri"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100 mb-3"
x-model="browseUri"
@blur="saveSettings()"
/>
<button
type="button"
@mousedown="browseUri = 'https://jumble.social/?r={url}'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
jumble
</button>
<button
type="button"
@mousedown="browseUri = 'https://yakihonne.com/r/content?r={url}'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
yakihonne
</button>
<button
type="button"
@mousedown="browseUri = 'https://fevela.me/?r={url}'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
fevela
</button>
<button
type="button"
@mousedown="browseUri = 'https://wisp.talk/relay/{url}'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
wisp
</button>
<button
type="button"
@mousedown="browseUri = 'https://grimoire.rocks/run?cmd=req%20{url}'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
grimoire
</button>
<button
type="button"
@mousedown="browseUri = 'https://nosotros.app/feed?relay={url}&kind=1&limit=30&type=relayfeed'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
nosotros
</button>
<button
type="button"
@mousedown="browseUri = 'https://coracle.social/relays/{url}'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
coracle
</button>
</div>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="link_url">URL pattern for external links</label>
<div class="flex flex-wrap gap-2 items-center">
<input
type="text"
name="link_url"
id="link_url"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100 mb-3"
x-model="linkUrl"
@blur="saveSettings()"
/>
<button
type="button"
@mousedown="linkUrl = 'nostr:{code}'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
native
</button>
<button
type="button"
@mousedown="linkUrl = 'https://njump.me/{code}'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
njump.me
</button>
<button
type="button"
@mousedown="linkUrl = 'https://grimoire.rocks/run?cmd=open%20{code}'"
@mouseup="saveSettings()"
class="cursor-pointer px-3 py-1 text-sm rounded bg-stone-200 hover:bg-stone-300 dark:bg-stone-600 dark:hover:bg-stone-500"
>
grimoire
</button>
</div>
</div>
</div>
<div
x-show="saved"
x-transition
class="text-sm text-green-600 dark:text-green-400 font-medium"
>
saved!
</div>
</form>
<form
method="POST"
action="/settings"
class="space-y-6 mt-8"
x-data={ `{
maxEventSize: ` + fmt.Sprint(global.Settings.Limits.MaxEventSize) + `,
maxSubscriptionsOpen: ` + fmt.Sprint(global.Settings.Limits.MaxSubscriptionsOpen) + `,
maxTotalCostOpen: ` + fmt.Sprint(global.Settings.Limits.MaxTotalCostOpen) + `,
maxIndexableTags: ` + fmt.Sprint(global.Settings.Limits.MaxIndexableTags) + `,
maxEntriesInFollowList: ` + fmt.Sprint(global.Settings.Limits.MaxEntriesInFollowList) + `,
maxQueryLimit: ` + fmt.Sprint(global.Settings.Limits.MaxQueryLimit) + `,
saved: false,
async saveSettings() {
const response = await fetch(this.$refs.form.action, {
method: 'POST',
body: new URLSearchParams(new FormData(this.$refs.form))
})
if (response.ok) {
this.saved = true;
setTimeout(() => this.saved = false, 2000)
}
}
}` }
x-ref="form"
>
@layout.SubSectionTitle("limits")
<details>
<summary class="cursor-pointer text-sm font-medium dark:text-stone-300">open</summary>
<div class="space-y-4 mt-4">
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="max_event_size">max event size (in bytes)</label>
<input
type="number"
name="max_event_size"
id="max_event_size"
min="1"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
x-model="maxEventSize"
@blur="saveSettings()"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="max_subscriptions_open">max subscriptions open</label>
<input
type="number"
name="max_subscriptions_open"
id="max_subscriptions_open"
min="0"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
x-model="maxSubscriptionsOpen"
@blur="saveSettings()"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="max_total_cost_open">max total cost open</label>
<input
type="number"
name="max_total_cost_open"
id="max_total_cost_open"
min="0"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
x-model="maxTotalCostOpen"
@blur="saveSettings()"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="max_indexable_tags">max indexable tags per event</label>
<input
type="number"
name="max_indexable_tags"
id="max_indexable_tags"
min="0"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
x-model="maxIndexableTags"
@blur="saveSettings()"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="max_entries_in_follow_list">max entries in follow list (kind 3)</label>
<input
type="number"
name="max_entries_in_follow_list"
id="max_entries_in_follow_list"
min="0"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
x-model="maxEntriesInFollowList"
@blur="saveSettings()"
/>
</div>
<div>
<label class="block text-sm font-medium mb-2 dark:text-stone-300" for="max_query_limit">max query limit</label>
<input
type="number"
name="max_query_limit"
id="max_query_limit"
min="0"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
x-model="maxQueryLimit"
@blur="saveSettings()"
/>
</div>
</div>
</details>
<div
x-show="saved"
x-transition
class="text-sm text-green-600 dark:text-green-400 font-medium"
>
saved!
</div>
</form>
<!-- NIP-50 Search Section -->
<div
x-data={ `{
saved: false,
enableSearch: ` + fmt.Sprint(global.Settings.Search.Enable) + `,
searchLanguages: ` + global.JSONString(global.Settings.Search.Languages) + `,
prevLanguages: ` + global.JSONString(global.Settings.Search.Languages) + `,
async saveSettings() {
const response = await fetch(this.$refs.form.action, {
method: 'POST',
body: new URLSearchParams(new FormData(this.$refs.form))
})
if (response.ok) {
this.saved = true;
setTimeout(() => this.saved = false, 2000)
}
},
}` }
>
<form
method="POST"
action="/settings"
class="space-y-6 mt-8"
x-ref="form"
>
@layout.SubSectionTitle("full-text search")
<div class="flex gap-8 items-start">
<div class="flex items-center">
<div>
<input
type="checkbox"
name="enable_search"
id="enable_search"
class="w-4 h-6 rounded border-stone-300 dark:border-stone-600"
x-model="enableSearch"
@change="saveSettings()"
/>
<label for="enable_search" class="ml-2 text-sm dark:text-stone-300">
enable NIP-50 full-text search
</label>
<input type="hidden" name="enable_search" value="off"/>
<!-- Search Statistics -->
<div class="mt-4 rounded-lg" x-show="enableSearch">
{{ searchStats, _ := search.GetStats() }}
<div class="text-sm space-y-1">
<div>
<span class="font-medium text-stone-700 dark:text-stone-300">indexed documents:</span>
<span class="text-stone-600 dark:text-stone-400">{ searchStats.DocumentCount }</span>
</div>
<div>
<span class="font-medium text-stone-700 dark:text-stone-300">search last enabled:</span>
<span class="text-stone-600 dark:text-stone-400">
if searchStats.LastSearchOn.IsZero() {
never
} else {
{ searchStats.LastSearchOn.Format("2006-01-02 15:04:05") }
}
</span>
</div>
<div>
<span class="font-medium text-stone-700 dark:text-stone-300">last reindex:</span>
<span class="text-stone-600 dark:text-stone-400">
if searchStats.LastReindex.IsZero() {
never
} else {
{ searchStats.LastReindex.Format("2006-01-02 15:04:05") }
}
</span>
</div>
<div>
<span class="font-medium text-stone-700 dark:text-stone-300">languages last changed:</span>
<span class="text-stone-600 dark:text-stone-400">
if searchStats.LastLanguagesChange.IsZero() {
never
} else {
{ searchStats.LastLanguagesChange.Format("2006-01-02 15:04:05") }
}
</span>
</div>
</div>
</div>
</div>
</div>
<div x-show="enableSearch" x-transition class="flex-1 max-w-md">
{{ selectedLanguages := global.Settings.Search.Languages }}
<label class="block text-sm font-medium mb-2 dark:text-stone-300">languages (current: { strings.Join(selectedLanguages, ", ") })</label>
<select
name="search_languages"
multiple
size="6"
class="w-full h-24 px-3 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
x-ref="languageSelect"
@blur="saveSettings()"
>
for _, lang := range bleve.SupportedLanguages {
{{ code := strings.ToLower(lang.IsoCode639_1().String()) }}
{{ name := lang.String() }}
<option value={ code } selected?={ slices.Contains(selectedLanguages, code) }>{ name }</option>
}
</select>
<p class="text-xs text-stone-500 dark:text-stone-400">
notes will be judged to be of one of these languages and indexed properly, ctrl+click to select multiple.
</p>
</div>
</div>
<div
x-show="saved"
x-transition
class="text-sm text-green-600 dark:text-green-400 font-medium"
>
saved!
</div>
</form>
<div class="mt-4" x-show={ "enableSearch && " + global.JSONString(search.ShouldShowReindexButton()) }>
<form method="POST" action="/search/reindex" onsubmit="return confirm('this will delete the current search index and rebuild it from scratch. this may take a while for large databases. continue?');">
<button
type="submit"
class="cursor-pointer px-6 py-2 rounded-lg font-semibold bg-stone-700 hover:bg-stone-800 dark:bg-stone-600 dark:hover:bg-stone-500 text-white shadow-md hover:shadow-lg"
>
reindex everything
</button>
</form>
</div>
</div>
<!-- Add Root Member Section -->
<form
method="POST"
action="/settings"
class="space-y-4 mt-8"
onsubmit="return confirm('this will invite a new root member with full administrative privileges. continue?');"
>
@layout.SubSectionTitle("add new root member")
<p class="text-sm text-stone-600 dark:text-stone-400">
root users have as much power as you. proceed with maximum caution.
</p>
<div class="flex flex-wrap gap-3 items-center">
<input
type="text"
name="root_member_pubkey"
placeholder="npub1... or hex pubkey"
required
class="flex-1 min-w-[220px] px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100 font-mono text-sm"
/>
<button
type="submit"
class="cursor-pointer px-4 py-2 rounded bg-stone-700 hover:bg-stone-800 dark:bg-stone-600 dark:hover:bg-stone-500 text-white font-medium"
>
invite root member
</button>
</div>
</form>
<!-- FTP Server Settings Section -->
<form
method="POST"
action="/settings"
class="space-y-6 mt-8"
x-data={ `{
ftpEnabled: ` + fmt.Sprint(global.Settings.FTP.Enabled) + `,
ftpPassword: '` + global.Settings.FTP.Password + `',
saved: false,
async saveSettings() {
const response = await fetch(this.$refs.form.action, {
method: 'POST',
body: new URLSearchParams(new FormData(this.$refs.form))
})
if (response.ok) {
this.saved = true;
setTimeout(() => this.saved = false, 2000)
}
}
}` }
x-ref="form"
>
@layout.SubSectionTitle("ftp server")
<div class="space-y-4">
<div class="flex items-center">
<input
type="checkbox"
name="ftp_enabled"
id="ftp_enabled"
class="w-4 h-6 rounded border-stone-300 dark:border-stone-600"
x-model="ftpEnabled"
@change="saveSettings()"
/>
<label for="ftp_enabled" class="ml-2 text-sm font-medium dark:text-stone-300">
enable FTP (SFTP) server for full read/write access to all events and blobs
</label>
<input type="hidden" name="ftp_enabled" value="off"/>
</div>
<div class="mt-4" x-show="ftpEnabled">
<label class="block text-sm font-medium mb-2 dark:text-stone-300" id="ftp_password">password</label>
<input
name="ftp_password"
id="ftp_password"
placeholder="password for FTP server, please pick something big and unguessable"
class="w-full px-4 py-2 rounded border border-stone-300 dark:border-stone-600 bg-white dark:bg-stone-700 dark:text-stone-100"
x-model="ftpPassword"
@blur="saveSettings()"
/>
</div>
<div x-show="ftpEnabled && ftpPassword" x-transition>
<div class="mt-4 p-4 bg-stone-50 dark:bg-stone-800 rounded-lg">
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 text-sm">
<div>
<label class="block font-medium mb-2 dark:text-stone-300">connection info</label>
<div class="text-stone-600 dark:text-stone-400">
<div>port: <span class="font-mono">{ global.S.SFTPPort }</span></div>
<div>username: <span class="font-mono">admin</span></div>
<div>password: <span class="font-mono" x-text="ftpPassword"></span></div>
</div>
</div>
<div>
<label class="block font-medium mb-2 dark:text-stone-300">ssh public key fingerprint</label>
<div class="text-stone-600 dark:text-stone-400 font-mono text-xs break-all">
{ getSSHPublicKey() }
</div>
</div>
</div>
</div>
</div>
</div>
<div
x-show="saved"
x-transition
class="text-sm text-green-600 dark:text-green-400 font-medium"
>
saved!
</div>
</form>
{{ systemStats := getSystemStats() }}
{{ relayClients, relayListeners := relay.Stats() }}
<!-- System Section -->
<div
class="mt-8"
x-data={ `{
restarting: false,
restartResult: '',
async restartServer() {
this.restarting = true;
this.restartResult = '';
try {
const response = await fetch('/restart', { method: 'POST' });
if (response.ok) {
this.restartResult = 'restart triggered. the page will refresh in 5 seconds.';
setTimeout(() => location.reload(), 5000);
return;
}
const result = await response.text();
this.restartResult = 'restart failed: ' + result;
} catch (error) {
if (error.message === 'Failed to fetch') {
this.restartResult = 'restart triggered. the page will refresh in 5 seconds.';
setTimeout(() => location.reload(), 5000);
return;
}
this.restartResult = 'restart failed: ' + error.message;
} finally {
this.restarting = false;
}
}
}` }
>
@layout.SubSectionTitle("system")
{{ cpuCount := len(systemStats.CPUUsages) }}
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-white dark:bg-stone-800 rounded-lg border border-stone-200 dark:border-stone-700 p-4">
<div class="text-sm font-medium text-stone-700 dark:text-stone-300">cpu usage</div>
if cpuCount <= 1 {
<div class="mt-1 text-lg text-stone-900 dark:text-stone-100">total: { systemStats.CPUUsage }</div>
<div class="text-xs text-stone-500 dark:text-stone-400">pyramid: { systemStats.CPUProcess }</div>
} else {
<div class="mt-1 text-sm text-stone-600 dark:text-stone-400">total: { systemStats.CPUUsage }</div>
<div class="text-xs text-stone-500 dark:text-stone-400">pyramid: { systemStats.CPUProcess }</div>
<div class="mt-3 overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-stone-500 dark:text-stone-400">
<th class="py-1">cpu</th>
<th class="py-1 text-right">usage</th>
</tr>
</thead>
<tbody>
for i, usage := range systemStats.CPUUsages {
<tr class="border-t border-stone-100 dark:border-stone-700">
<td class="py-1 text-stone-600 dark:text-stone-300">cpu { i }</td>
<td class="py-1 text-right text-stone-900 dark:text-stone-100">{ fmt.Sprintf("%.1f%%", usage) }</td>
</tr>
}
</tbody>
</table>
</div>
}
</div>
<div class="bg-white dark:bg-stone-800 rounded-lg border border-stone-200 dark:border-stone-700 p-4">
<div class="text-sm font-medium text-stone-700 dark:text-stone-300">memory usage</div>
<div class="mt-1 text-lg text-stone-900 dark:text-stone-100">total: { systemStats.Memory }</div>
<div class="text-xs text-stone-500 dark:text-stone-400">pyramid: { systemStats.MemoryProcess }</div>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4">
<div class="bg-white dark:bg-stone-800 rounded-lg border border-stone-200 dark:border-stone-700 p-4">
<div class="text-sm font-medium text-stone-700 dark:text-stone-300">server</div>
<div class="mt-1 text-stone-900 dark:text-stone-400">domain: { global.Settings.Domain }</div>
<div class="mt-1 text-stone-900 dark:text-stone-100">host: <span class="font-mono">{ global.S.Host }</span></div>
<div class="mt-1 text-stone-900 dark:text-stone-100">port: <span class="font-mono">{ global.S.Port }</span></div>
if global.S.Port == "443" {
<div class="text-sm text-stone-600 dark:text-stone-400">managing TLS certificates</div>
}
</div>
<div class="bg-white dark:bg-stone-800 rounded-lg border border-stone-200 dark:border-stone-700 p-4">
<div class="text-sm font-medium text-stone-700 dark:text-stone-300">relay</div>
<div class="mt-1 text-lg text-stone-900 dark:text-stone-100">clients: { relayClients }</div>
<div class="text-xs text-stone-500 dark:text-stone-400">subscriptions: { relayListeners }</div>
<div class="text-right text-sm text-stone-700 dark:text-stone-200 mt-4">
<a href="/clients" target="_blank" class="cursor-pointer hover:underline hover:text-stone-400">/clients</a>
<a href="/log" target="_blank" class="ml-4 cursor-pointer hover:underline hover:text-stone-400">/log</a>
</div>
</div>
<div class="bg-white dark:bg-stone-800 rounded-lg border border-stone-200 dark:border-stone-700 p-4">
<div class="text-sm font-medium text-stone-700 dark:text-stone-300">data usage</div>
<div class="mt-1 text-lg text-stone-900 dark:text-stone-100">disk used: { systemStats.DiskUsed } / { systemStats.DiskTotal } ({ systemStats.DiskUsedPct })</div>
<div class="text-sm text-stone-600 dark:text-stone-400">pyramid: { systemStats.DataSize } ({ global.S.DataPath })</div>
</div>
</div>
<div class="mt-4">
<button
type="button"
@click="confirm('this will restart the pyramid server. continue?') ? restartServer() : null"
:disabled="restarting"
class="cursor-pointer inline-block px-4 py-2 rounded bg-stone-700 hover:bg-stone-800 disabled:bg-stone-400 text-white font-medium"
>
<span x-show="!restarting">restart pyramid</span>
<span x-show="restarting">restarting...</span>
</button>
<div
x-show="restartResult"
x-transition
class="mt-2 text-sm"
:class="restartResult.includes('failed') ? 'text-red-600 dark:text-red-400' : 'text-emerald-700 dark:text-emerald-300'"
x-text="restartResult"
></div>
</div>
</div>
if !global.S.NoAutoUpdates {
<!-- update Section -->
<div
class="mt-8"
x-data={ `{
customUpdateSource: ` + global.JSONString(customUpdateSource) + `,
updating: false,
updateResult: '',
setCustomUpdateSource() {
const nextSource = prompt('paste a github repo, github release, or direct url', this.customUpdateSource || '')
if (nextSource === null) return
this.customUpdateSource = nextSource.trim()
setTimeout(() => this.$refs.customUpdateForm.submit(), 500)
},
async performUpdate() {
this.updating = true;
this.updateResult = '';
try {
const response = await fetch('/update', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
});
if (response.status === 502) {
// treat 502 as success (server restarting during update)
this.updateResult = 'update successful (probably, if you have a reverse-proxy). the page will refresh in 10 seconds.'
setTimeout(() => location.reload(), 10000)
return
}
const result = await response.text();
this.updateResult = 'update failed: ' + result;
} catch (error) {
if (error.message === 'Failed to fetch') {
// this means we have probably succeeded
this.updateResult = 'update successful (probably). the page will refresh in 10 seconds.'
setTimeout(() => location.reload(), 10000)
return
}
this.updateResult = 'fetch call failed: ' + error.message;
} finally {
this.updating = false;
}
},
versionToNumber (versionName) {
if (versionName.startsWith('v')) versionName = versionName.slice(1)
return versionName.split('.').map((n, i) => parseInt(n) * 10**(10-i*3)).reduce((acc, n) => acc + n, 0)
}
}` }
>
@layout.SubSectionTitle("update")
<form method="POST" action="/settings" x-ref="customUpdateForm">
<input type="hidden" name="custom_update_source" x-model="customUpdateSource"/>
</form>
<p class="text-sm text-stone-600 dark:text-stone-400 mb-4">
<div>current version: <span class="text-stone-600 dark:text-stone-400" x-ref="currentVersion">{ currentVersion }</span></div>
<div>
if customUpdateSource != "" {
custom version: <span class="text-stone-600 dark:text-stone-400" x-ref="latestVersion"><a class="hover:font-medium underline underline-offset-4" href={ templ.SafeURL(customUpdateSource) } target="_blank">{ latestVersion.name }</a></span>
} else {
latest version: <span class="text-stone-600 dark:text-stone-400" x-ref="latestVersion"><a class="hover:font-medium underline underline-offset-4" href={ templ.SafeURL("https://github.com/fiatjaf/pyramid/releases/tag/" + latestVersion.name) } target="_blank">{ latestVersion.name }</a></span>
}
<button