interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / social / 55pages.om

784 lines · 11527 bytes Raw Blame History
1note social/55pages.om: soroute, the social pages, POST actions, and the contract fragments.
2note ---- router
3fn soroute to long
4if sopis tsplogin
5ret sologin
6end
7if sopis tsplogo
8ret sologout
9end
10if sopis tspset
11ret sosettings
12end
13if sopis tspsetn
14ret sosetname
15end
16if sopis tspstars
17ret sostarsp
18end
19if sopis tspfol
20ret sofollow true
21end
22if sopis tspunf
23ret sofollow false
24end
25if ne get fridx 0 9999
26ret sorepor
27end
28ret souserp
29end
30note ---- form and link pieces
31fn socsrfout to void
32for i ulong get fcsrfl 0 bound 64
33fescc get fcsrf i
34end
35end
36fn sopathout to void
37for i ulong get fpathl 0 bound 4096
38fescc get fpath i
39end
40end
41note softail: close the action attribute, add csrf + back, the button, close the form
42fn softail lbl view uchar * to void
43fput tshf2
44socsrfout
45fput tshf3
46sopathout
47fput tshf4
48fput lbl
49fput tshf5
50end
51fn sorform act view uchar * lbl view uchar * to void
52fput tshf1
53fputb
54fputrepo
55fput act
56softail lbl
57end
58fn sorcnt sp view uchar * n ulong w view uchar * to void
59fput tsha1
60fputb
61fputrepo
62fput sp
63fput tsha2
64fnum n
65fput w
66fput tsha3
67end
68note sorkeyt: the string id of allow-list repo i into sokb: "rad:<RID>" for a project with an old
69note Radicle id (every target already in the log), "git:<id>" for a store project without one
70note (fhasal, server/radsrc.om or store/repos.om). An index past the list gives "rad:" alone, as the
71note empty frid did before.
72fn sorkeyt i ulong to void
73sokclr
74if ge i get fan 0
75sokt tsradp
76ret
77end
78if fhasal i
79sokt tsradp
80else
81sokt tsgitp
82end
83n = fridlen i
84for k ulong n bound 128
85sokc fridbyte i k
86end
87end
88note sorepoid: string id of allow-list index i (sorkeyt; 0 when nobody touched it)
89fn sorepoid i ulong to ulong
90sorkeyt i
91ret sofind
92end
93note soownid: account DID id for the user name in fown (0 when none)
94fn soownid to ulong
95n = get fownl 0
96if or eq n 0 gt n 39
97ret 0
98end
99sokclr
100for i ulong n bound 64
101sokc get fown i
102end
103ret get gsnmo sofind
104end
105note sonmout: the account's URL segment: its display name, else the z... key of its DID
106fn sonmout d ulong to void
107n = get gsnm d
108if ne n 0
109sooutid n 0
110ret
111end
112sooutid d len tsdidp
113end
114note sorsvk: gskb holds a display name or the z... key of a DID; the account id or 0
115fn sorsvk to ulong
116if sonameok
117ret get gsnmo sofind
118end
119n = get gskbl 0
120if or lt n 40 gt n 60
121ret 0
122end
123z = new uchar 64 0
124for i ulong n bound 64
125put z i get gskb i
126end
127sokclr
128sokt tsdidp
129sokt part z 0 n
130s = sofind
131if eq get gsacc s 0
132ret 0
133end
134ret s
135end
136note ---- contract fragments and counts
137fn sostarn i ulong to ulong
138ret get gscst sorepoid i
139end
140fn sofavn i ulong to ulong
141ret get gscfv sorepoid i
142end
143fn sofolln to ulong
144ret get gscfl soownid
145end
146fn sofollg to ulong
147ret get gscfg soownid
148end
149note sobar: star / watch / favorite forms and counts for repo fridx
150fn sobar to void
151i = get fridx 0
152if or eq i 9999 eq get gsok 0 0
153ret
154end
155t = sorepoid i
156u = get gscur 0
157fput tshbar1
158if eq u 0
159sosignin tssinst
160end
161if ne u 0
162if soron 1 u t
163sorform tsrunst tsbunst
164else
165sorform tsrstar tsbstar
166end
167end
168sorcnt tsrsg get gscst t tswstar
169if ne u 0
170if soron 3 u t
171sorform tsrunwt tsbunwt
172else
173sorform tsrwat tsbwat
174end
175end
176sorcnt tsrwr get gscwt t tswwat
177if ne u 0
178if soron 2 u t
179sorform tsrunfv tsbunfv
180else
181sorform tsrfav tsbfav
182end
183end
184fput tshbar2
185end
186fn sosignin lbl view uchar * to void
187fput tsha1
188flink tsplog2
189fput tsha2
190fput lbl
191fput tsha3
192end
193fn sofolbar to void
194soflbar soownid
195end
196note soflbar: follower/following counts and the follow form for account d
197fn soflbar d ulong to void
198if or eq d 0 eq get gsok 0 0
199ret
200end
201fput tshbar1
202souln d tsqfls get gscfl d tswfls
203souln d tsqflg get gscfg d tswflg
204u = get gscur 0
205if eq u 0
206sosignin tssinfl
207end
208if and ne u 0 ne u d
209fput tshf1
210fputb
211if soron 4 u d
212fput tspunf2
213sofolf d tsbunfl
214else
215fput tspfol2
216sofolf d tsbfol
217end
218end
219fput tshbar2
220end
221fn sofolf d ulong lbl view uchar * to void
222fput tshfu
223sonmout d
224softail lbl
225end
226fn souln d ulong q view uchar * n ulong w view uchar * to void
227fput tsha1
228fputb
229sonmout d
230fput tsqtabe
231fput q
232fput tsha2
233fnum n
234fput w
235fput tsha3
236end
237fn sostarsof to void
238d = soownid
239if eq d 0
240fput tsnone
241ret
242end
243sorepol 1 d
244end
245note sorepol: allow-listed repos with relation kind by actor a (private repos never appear)
246fn sorepol kind ulong a ulong to void
247c = ulong 0
248n = get fan 0
249fput tsul1
250for i ulong n bound 4096
251t = sorepoid i
252if and ne t 0 soron kind a t
253c = add c 1
254sorepoli i t
255end
256end
257fput tsul2
258if eq c 0
259fput tsnone
260end
261end
262fn sorepoli i ulong t ulong to void
263fput tsli1
264fput tsrepo1
265fputb
266fput tfowner
267fput tsslash
268fputrn i
269fput tsha2
270fput tfowner
271fput tsslash
272fputrn i
273fput tsha3
274fput tsmut1
275fnum get gscst t
276fput tswstar
277fput tsmut2
278fput tsli2
279end
280note sousers: side 1 lists actors a of (kind, a, x); side 0 lists targets b of (kind, x, b)
281fn sousers kind ulong x ulong side ulong to void
282fput tsul1
283c = ulong 0
284for s ulong 262144
285k = get gsrk s
286if and ne k 0 ne get gsrv s 0
287if eq shr k 48 kind
288a = and shr k 24 16777215
289b = and k 16777215
290if and eq side 1 eq b x
291c = add c 1
292soli a
293end
294if and eq side 0 eq a x
295c = add c 1
296soli b
297end
298end
299end
300end
301fput tsul2
302if eq c 0
303fput tsnone
304end
305end
306fn soli d ulong to void
307fput tsli1
308souser d
309fput tsli2
310end
311note ---- query tabs
312fn sotab to ulong
313n = fqget tsqtab
314if lt n 1
315ret 0
316end
317m = ulong n
318if sofvis tsqfav m
319ret 1
320end
321if sofvis tsqwat m
322ret 3
323end
324if sofvis tsqfls m
325ret 4
326end
327if sofvis tsqflg m
328ret 5
329end
330if sofvis tsqstar m
331ret 6
332end
333ret 9
334end
335fn sofvis t view uchar * n ulong to bool
336if ne n len t
337ret false
338end
339for i ulong n bound 64
340if ne get fval i get t i
341ret false
342end
343end
344ret true
345end
346note ---- repo actions and lists
347fn sorepor to long
348a = soracode
349if eq a 0
350ret 0
351end
352if ge a 20
353if gt get fmeth 0 2
354ret 405
355end
356ret sorlist a
357end
358if ne get fmeth 0 3
359ret 405
360end
361r = sowpre
362if ne r 0
363ret r
364end
365ret soract2 a
366end
367fn soracode to ulong
368if sorestis tsrstar
369ret 1
370end
371if sorestis tsrunst
372ret 2
373end
374if sorestis tsrfav
375ret 3
376end
377if sorestis tsrunfv
378ret 4
379end
380if sorestis tsrwat
381ret 5
382end
383if sorestis tsrunwt
384ret 6
385end
386if sorestis tsrsg
387ret 20
388end
389if sorestis tsrwr
390ret 21
391end
392ret 0
393end
394note soract2: idempotent; an event is logged only when the state changes
395fn soract2 a ulong to long
396u = get gscur 0
397sorkeyt get fridx 0
398t = sofind
399on = eq rem a 2 1
400kind = add div sub a 1 2 1
401cur = false
402if ne t 0
403cur = soron kind u t
404end
405if ne cur on
406if not soemit a u
407ret soerr 500 tsmwrite
408end
409end
410d = new uchar 256 0
411k = ulong 0
412for i ulong get fownl 0 bound 64
413put d k get fown i
414k = add k 1
415end
416put d k 47
417k = add k 1
418for i ulong get frepol 0 bound 128
419put d k get frepo i
420k = add k 1
421end
422ret sobackto part d 0 k
423end
424fn sorlist a ulong to long
425t = sorepoid get fridx 0
426if fjwant
427if eq a 20
428ret sojlist 1 t
429end
430ret sojlist 3 t
431end
432fyalt
433kind = ulong 1
434if eq a 20
435fsetti tstsg
436else
437fsetti tstwr
438kind = ulong 3
439end
440frepohd 99
441fput tsh2a
442if eq kind 1
443fput tstsg
444else
445fput tstwr
446end
447fput tsh2b
448if eq t 0
449fput tsnone
450ret 200
451end
452sousers kind t 1
453ret 200
454end
455note sobackto: 303 to base + back (validated body field) or else base + def
456fn sobackto def view uchar * to long
457put fkind 0 2
458flocb
459b = new uchar 512 0
460n = sobval tsbk b
461if gt n 0
462if sobackok part b 0 ulong n
463for i ulong sub ulong n 1 bound 512
464flocc get b add i 1
465end
466ret 303
467end
468end
469floct def
470ret 303
471end
472note sobackok: "/" then [A-Za-z0-9._~/-] with no "//" and no "/." (no traversal, no other host)
473fn sobackok s view uchar * to bool
474if ne get s 0 47
475ret false
476end
477for i ulong len s bound 512
478c = get s i
479if not sourlc c
480ret false
481end
482if gt i 0
483p = get s sub i 1
484if and eq p 47 or eq c 47 eq c 46
485ret false
486end
487end
488end
489ret true
490end
491fn sourlc c uchar to bool
492if and ge c 65 le c 90
493ret true
494end
495if and ge c 97 le c 122
496ret true
497end
498if and ge c 48 le c 57
499ret true
500end
501ret or or eq c 45 eq c 46 or or eq c 95 eq c 126 eq c 47
502end
503note ---- follow
504fn sofollow on bool to long
505if ne get fmeth 0 3
506ret 405
507end
508r = sowpre
509if ne r 0
510ret r
511end
512raw = new uchar 64 0
513n = sobval tsfuser raw
514if lt n 1
515ret soerr 400 tsmnous
516end
517sokclr
518for i ulong ulong n
519sokc get raw i
520end
521d = sorsvk
522if eq d 0
523ret soerr 404 tsmnous
524end
525u = get gscur 0
526if eq d u
527ret soerr 400 tsmself
528end
529if ne soron 4 u d on
530sokclr
531sokid d
532a = ulong 8
533if on
534a = ulong 7
535end
536if not soemit a u
537ret soerr 500 tsmwrite
538end
539end
540ret sobackto part raw 0 ulong n
541end
542note ---- pages
543fn sopgin to long
544fput tsin1
545for i ulong get fuserl 0 bound 64
546fescc get fuser i
547end
548fput tsin2
549fput tsrepo1
550flink tspset2
551fput tsha2
552fput tsin3
553fput tsha3
554sologf
555ret 200
556end
557fn sologf to void
558fput tshf1
559flink tsplo2
560softail tsbout
561end
562fn sopglog nh view uchar * ts ulong mac view uchar * to long
563fput tslg1
564c = new uchar 96 0
565l = sochal nh ts c
566fesc part c 0 l
567fput tslg2
568flink tsplog2
569fput tslg3
570fput mac
571fput tslg4
572fput nh
573fput tslg5
574d = new uchar 20 0
575k = sodec ts d
576fput part d 0 k
577fput tslg6
578ret 200
579end
580fn sosettings to long
581if gt get fmeth 0 2
582ret 405
583end
584u = get gscur 0
585if eq u 0
586ret soback tsplog2
587end
588fsetti tstset
589fput tsst1
590sooutid u 0
591n = get gsnm u
592if eq n 0
593fput tsst2n
594else
595fput tsst2
596sooutid n 0
597fput tsst3
598end
599fput tsst4
600if ne u get gsown 0
601fput tsst5
602flink tspsn2
603fput tsst6
604socsrfout
605fput tsst7
606end
607fput tsst8
608sologf
609ret 200
610end
611fn sostarsp to long
612if gt get fmeth 0 2
613ret 405
614end
615u = get gscur 0
616if eq u 0
617ret soback tsplog2
618end
619fsetti tststar
620tab = sotab
621kind = ulong 1
622if eq tab 1
623kind = ulong 2
624end
625if eq tab 3
626kind = ulong 3
627end
628if fjwant
629ret sojstarp u kind
630end
631fyalt
632fput tsh1a
633fput tststar
634fput tsh1b
635fput tstab1
636sostabl 1 kind tslstar tsqstar
637sostabl 2 kind tslfav tsqfav
638sostabl 3 kind tslwat tsqwat
639fput tstab2
640if eq kind 2
641fput tsfavp
642end
643sorepol kind u
644ret 200
645end
646fn sostabl code ulong cur ulong lbl view uchar * q view uchar * to void
647if eq code cur
648fput tstabon
649else
650fput tsrepo1
651end
652fputb
653fput tspstr2
654if ne code 1
655fput tsqtabe
656fput q
657end
658fput tsha2
659fput lbl
660fput tsha3
661end
662note souserp: /<user>, /<user>/followers, /<user>/following for accounts; <user> is the display
663note name or the z... key. The owner's plain profile stays the server's.
664fn souserp to long
665n = get fpathl 0
666if or lt n 2 gt n 80
667ret 0
668end
669j = ulong 1
670for it ulong 80
671if or ge j n eq get fpath j 47
672break
673end
674j = add j 1
675end
676tab = sotab
677if lt j n
678tab = sosegtab j
679if eq tab 0
680ret 0
681end
682end
683sokclr
684for i ulong sub j 1 bound 80
685sokc get fpath add i 1
686end
687d = sorsvk
688if eq d 0
689ret 0
690end
691if and eq d get gsown 0 and ne tab 4 ne tab 5
692ret 0
693end
694if gt get fmeth 0 2
695ret 405
696end
697tn = new uchar 80 0
698l = sub j 1
699for i ulong l bound 80
700put tn i get fpath add i 1
701end
702fsetti part tn 0 l
703if fjwant
704ret sojprof d tab
705end
706fyalt
707ret soprof d tab
708end
709note sosegtab: the rest of fpath from j is "/followers" (4) or "/following" (5); else 0
710fn sosegtab j ulong to ulong
711if sopsub j tspfls
712ret 4
713end
714if sopsub j tspflg
715ret 5
716end
717ret 0
718end
719fn sopsub j ulong t view uchar * to bool
720if ne sub get fpathl 0 j len t
721ret false
722end
723for i ulong len t bound 64
724if ne get fpath add j i get t i
725ret false
726end
727end
728ret true
729end
730fn soprof d ulong tab ulong to long
731fput tsh1a
732sonmout d
733fput tsh1b
734fput tsdid1
735sooutid d 0
736fput tsdid2
737soflbar d
738fput tstab1
739k = tab
740if or eq tab 0 eq tab 9
741k = ulong 6
742end
743sotabl d 6 k
744sotabl d 4 k
745sotabl d 5 k
746fput tstab2
747if eq k 4
748sousers 4 d 1
749ret 200
750end
751if eq k 5
752sousers 4 d 0
753ret 200
754end
755sorepol 1 d
756ret 200
757end
758note sotabl: profile tab code (6 stars, 4 followers, 5 following) for account d; cur is marked
759fn sotabl d ulong code ulong cur ulong to void
760if eq code cur
761fput tstabon
762else
763fput tsrepo1
764end
765fputb
766sonmout d
767fput tsqtabe
768if eq code 6
769fput tsqstar
770fput tsha2
771fput tslstar
772end
773if eq code 4
774fput tsqfls
775fput tsha2
776fput tslfls
777end
778if eq code 5
779fput tsqflg
780fput tsha2
781fput tslflg
782end
783fput tsha3
784end