on master help sign in
validation: fixing validation in various places, fixing published bug, adding invalid purge
commit579504318d447893b66505e080f26e900a593437 authorHunter Miller <hunter@hmiller.dev> dateSat 6 Aug 2022, 21:31 (4 years ago) parentfcfd17e
5 files changed+54−24
desk/app/sphinx.hoon+17−6 desk/desk.docket-0+2−2 desk/gen/state.hoon+8 desk/lib/sphinx.hoon+25−14 ui/src/state/posts.ts+2−2
desk/app/sphinx.hoon+17−6
@@ -59,10 +59,11 @@
5959 ::
6060 ++ get-state-2
6161 |= =directory:s
62+ =/ purged (purge-invalid directory)
6263 :* %2
6364 (reindex directory)
64− directory
65− (purge directory)
65+ purged
66+ (purge-foreign purged)
6667 ==
6768 ++ reindex
6869 |= =directory:s
@@ -70,7 +71,15 @@
7071 ~(tap by directory)
7172 |= [[=hash:s l=listing:s] i=index:s]
7273 (~(catalog delver i) hash l)
73− ++ purge
74+ ++ purge-invalid
75+ |= =directory:s
76+ ^- directory:s
77+ %- malt
78+ %+ skim
79+ ~(tap by directory)
80+ |= [=hash:s =listing:s]
81+ (listing-valid listing)
82+ ++ purge-foreign
7483 |= =directory:s
7584 ^- directory:s
7685 %- malt
@@ -151,6 +160,7 @@
151160 ?: (~(has by directory) hash.listing)
152161 ~& 'Listing already exists.'
153162 cor
163+ ?. (listing-valid listing) cor
154164 di-abet:(di-publish:(di-abed:di-core:core hash.listing) listing)
155165 --
156166::
@@ -177,8 +187,9 @@
177187 =+ !<(=listing:s vase)
178188 ?> =(hash.listing (digest post.listing))
179189 ?: (~(has by directory) hash.listing)
180− ~& 'Listing already exists.'
181− cor
190+ ~& 'Listing already exists.'
191+ cor
192+ ?. (listing-valid listing) cor
182193 di-abet:(di-receive:(di-abed:di-core hash.listing) listing)
183194 ::
184195 %directory
@@ -315,7 +326,7 @@
315326 =. index (~(catalog delver index) hash l)
316327 =. published
317328 ?. =(source.listing our:bowl) published
318− (~(put by directory) hash.listing listing)
329+ (~(put by published) hash.listing listing)
319330 =. cor (emit (invent:gossip %directory-listing !>(listing)))
320331 di-core
321332 ++ di-receive
desk/desk.docket-0+2−2
@@ -2,9 +2,9 @@
22 info+'A search engine powered by you and your pals for finding answers to your riddles'
33 color+0xb2.5068
44 image+'https://nyc3.digitaloceanspaces.com/hmillerdev/nocsyx-lassul/2022.7.16..04.35.22-sphinx-web-shifted.svg'
5− glob-http+['https://nyc3.digitaloceanspaces.com/hmillerdev/sphinx/glob-0v7.58bpe.gauar.d272t.l9jhq.uqhkn.glob' 0v7.58bpe.gauar.d272t.l9jhq.uqhkn]
5+ glob-http+['https://nyc3.digitaloceanspaces.com/hmillerdev/sphinx/glob-0v4.rk6nd.h0t14.4j4tv.q4bia.9m66a.glob' 0v4.rk6nd.h0t14.4j4tv.q4bia.9m66a]
66 base+'sphinx'
7− version+[0 4 2]
7+ version+[0 4 3]
88 website+'https://github.com'
99 license+'MIT'
1010==
desk/gen/state.hoonnew file+8
@@ -0,0 +1,8 @@
1+/- s=sphinx
2+:- %say
3+|= $: [now=@da eny=@uv =beak]
4+ [~ ~]
5+ ==
6+=/ our (scot %p p.beak)
7+=/ wen (scot %da now)
8+noun+.^(state:s /gx/[our]/sphinx/[wen]/state/noun)
desk/lib/sphinx.hoon+25−14
@@ -47,6 +47,30 @@
4747 %+ turn
4848 entries
4949 |=(=entry hash.entry)
50+++ lengths-valid
51+ |= l=listing
52+ ?& (lte (lent (trip title.post.l)) 77)
53+ (lte (lent (trip description.post.l)) 256)
54+ (lte (lent tags.post.l) 8)
55+ (lte (lent (trip link.post.l)) 1.024)
56+ (lte (lent (trip image.post.l)) 1.024)
57+ ==
58+++ urls-valid
59+ |= l=listing
60+ =/ image
61+ ?: =(image.post.l '') 'X'
62+ (validate image.post.l)
63+ =/ link (validate link.post.l)
64+ &(!=(image ~) !=(link ~))
65+++ listing-valid
66+ |= l=listing
67+ =/ lengths (lengths-valid l)
68+ =/ urls (urls-valid l)
69+ :: ~& title.post.l
70+ :: ~& hash.l
71+ :: ~& ['urls' ?:(urls 'valid' 'invalid')]
72+ :: ~& ['lengths' ?:(lengths 'valid' 'invalid')]
73+ &(lengths urls)
5074++ delver
5175 |_ [=lookup =trigrams =phonetics =trail]
5276 ++ get
@@ -54,20 +78,7 @@
5478 [lookup trigrams phonetics trail]
5579 ++ catalog
5680 |= [=hash l=listing]
57− ?.
58− ?& (lte (lent (trip title.post.l)) 77)
59− (lte (lent (trip description.post.l)) 256)
60− (lte (lent tags.post.l) 8)
61− (lte (lent (trip link.post.l)) 1.024)
62− (lte (lent (trip image.post.l)) 1.024)
63− ==
64− get
65− =/ image
66− ?: =(image.post.l '') 'X'
67− (validate image.post.l)
68− =/ link (validate link.post.l)
69− ?: |(=(image ~) =(link ~))
70− get
81+ ?. (listing-valid l) get
7182 =/ entries=^lookup
7283 %- malt
7384 ^- (list [@t (list entry)])
ui/src/state/posts.ts+2−2
@@ -136,11 +136,11 @@ export function getSnippet(body: Content[]): { image: string, content: string }
136136 }, '');
137137 const image = body.filter((c: Content): c is UrlContent => 'url' in c && IMAGE_REGEX.test(c.url)).map(c => c.url)[0] || '';
138138 const content = removeMd(firstContent.replace(/!\[.*\]\((.*)\)\s*/g, ''));
139− const end = content.length > 256 ? 255 : content.length;
139+ const end = content.length > 256 ? 253 : content.length;
140140 const start = content.substring(0, end);
141141
142142 return {
143− content: start === firstContent ? start : `${start}...`,
143+ content: start === content ? start : `${start}...`,
144144 image: getImage(firstContent) || image
145145 }
146146}