This commit is contained in:
polwex 2024-06-29 02:14:46 +07:00
parent 9a55f89650
commit 51c078429a
10 changed files with 163 additions and 32 deletions

View File

@ -27,7 +27,9 @@
:_ this init-cards:hd
++ on-load |= old=vase
:_ this(state !<(versioned-state old)) ~
:_ this(state !<(versioned-state old))
:: :- cache-root:cache cache-static:cache
~
++ on-watch
|= =(pole knot)
?+ pole !!
@ -49,8 +51,33 @@
?: ?=(%seed a) teds:seed
?: ?=(%seed2 a) coms:seed
?: ?=(%seed3 a) reps:seed
:: admin
?: ?=([%hr @p ?] a) (handle-hr +.a)
?: ?=([%ban @p ?] a) (handle-ban +.a)
?: ?=([%del-ted @t] a) (handle-del .y +.a)
?: ?=([%del-com @t] a) (handle-del .n +.a)
~& wtf=a
`this
++ handle-del |= [is-ted=? uidt=@t]
=/ uid (slaw:sr %uw uidt) ?~ uid !!
=/ cued (cue u.uid)
=/ pid %- (soft pid:tp) cued
?~ pid !!
=^ cards state
%+ handle-del:cache is-ted u.pid
[cards this]
++ handle-hr |= [=ship w=?]
?> .=(src.bowl our.bowl)
=. admins ?: w
(~(put in admins) ship)
(~(del in admins) ship)
`this
++ handle-ban |= [=ship w=?]
?> (~(has in admins) src.bowl)
=. blacklist ?: w
(~(put in blacklist) ship)
(~(del in blacklist) ship)
`this
++ handle-cache |= a=* :_ this
=/ which ($?(%root %ted %sta %all) a)
?- which
@ -75,6 +102,7 @@
=/ rng ~(. og eny.bowl)
|%
++ teds
=. admins admins:const
=/ titles titles:seeds
=. state
|- ?~ titles state
@ -170,7 +198,6 @@
::
++ serve
^- (quip card _this)
~& eyre-poke=now.bowl
=/ order !<(order:router vase)
=/ address address.req.order
:: ?: (~(has in banned.admin) address) `this

View File

@ -11,6 +11,7 @@
|= noun=* ^- [(list card) _state]
=/ poke (pokes:sur noun)
~& ui-poke=poke
=. src ship.poke
=/ eyre-id eyre-id.poke
|^
?- -.p.poke
@ -18,15 +19,17 @@
%submit-comment (handle-comment +.p.poke)
%submit-reply (handle-reply +.p.poke)
%vote (handle-vote +.p.poke)
%del (handle-del +.p.poke)
==
++ handle-thread |= [title=@t url=@t text=@t]
=/ =content:sur ?. .=('' url) [%link url] [%text (build-content:lib text)]
=/ ted (build-thread:lib title src now content)
=. state (save-ted ted)
:_ state :+
cache-root
(cache-ted ted)
(redirect-ted ted)
(cache-ted pid.ted)
(redirect-ted pid.ted)
++ handle-comment |= [ted=thread:sur text=@t]
@ -35,8 +38,8 @@
=. state (save-com com ted)
:_ state :+
cache-root
(cache-ted ted)
(redirect-ted ted)
(cache-ted pid.ted)
(redirect-ted pid.ted)
@ -49,7 +52,7 @@
=. state (save-rep com par)
:_ state :*
cache-root
(cache-ted u.ted)
(cache-ted pid.u.ted)
(cache-com com)
(cache-com par)
(redirect-com par)
@ -74,9 +77,9 @@
=. state (save-karma ship.pid.ted vote)
:_ state :~
cache-root
(cache-ted ted)
(cache-ted pid.ted)
(cache-user ship.pid.ted)
:: (redirect-ted ted)
:: (redirect-ted pid.ted)
==
++ handle-com-vote |= [=pid:tp vote=?]
=/ votesi=@si (new:si vote 1)
@ -102,8 +105,8 @@
:: redirectors
++ redirect-root (redirect:router eyre-id "")
++ redirect-ted |= ted=thread:sur
=/ link (scow:sr %uw (jam pid.ted))
++ redirect-ted |= =pid:tp
=/ link (scow:sr %uw (jam pid))
=/ url "/ted/{link}"
(redirect:router eyre-id url)
++ redirect-com |= com=comment:tp
@ -113,8 +116,8 @@
--
:: cache builders
++ cache-root (cache-card "")
++ cache-ted |= ted=thread:sur
=/ link (scow:sr %uw (jam pid.ted))
++ cache-ted |= =pid:tp
=/ link (scow:sr %uw (jam pid))
=/ url "/ted/{link}"
(cache-card url)
++ cache-com |= com=comment:tp
@ -127,7 +130,7 @@
=/ teds (tap:torm:sur threads)
=. l |- ?~ teds l
=/ ted=thread:sur +.i.teds
=/ car (cache-ted ted)
=/ car (cache-ted pid.ted)
$(teds t.teds, l [car l])
:- cache-root l
++ cache-user |= who=@p
@ -148,7 +151,7 @@
=/ teds (tap:torm:sur threads)
=. l |- ?~ teds l
=/ ted=thread:sur +.i.teds
=/ car (cache-ted ted)
=/ car (cache-ted pid.ted)
$(teds t.teds, l [car l])
=/ coms (tap:gorm:tp comments)
=. l |- ?~ coms l
@ -179,6 +182,22 @@
=. par par(children nc)
=. comments (put:gorm:tp comments ppid par)
state
++ wipe-coms
|= [ted=pid:tp]
=/ coms (tap:gorm:tp comments)
|- ?~ coms comments
=/ com=comment:tp +.i.coms
?. .=(ted thread.com) $(coms t.coms)
=. comments +:(del:gorm:tp comments [author.com id.com])
$(coms t.coms)
++ wipe-reps
|= [par=pid:tp]
=/ coms (tap:gorm:tp comments)
|- ?~ coms comments
=/ com=comment:tp +.i.coms
?. .=(par parent.com) $(coms t.coms)
=. comments +:(del:gorm:tp comments [author.com id.com])
$(coms t.coms)
++ save-karma |= [who=@p vote=?]
=/ curr (~(get by karma) who)
=/ cur ?~ curr `@sd`0 u.curr
@ -193,4 +212,42 @@
=/ pl=simple-payload:http (render:rout router-path)
=/ entry=cache-entry:eyre [.n %payload pl]
[%pass /root %arvo %e %set-response pathc `entry]
++ handle-del |= [is-ted=? =pid:tp]
?: is-ted
=/ ted (get-thread:lib pid state)
?~ ted `state
=. threads +:(del:torm:sur threads pid)
=. comments (wipe-coms pid)
:_ state :+
cache-root
(cache-ted pid)
~
:: redirect-root
::
=| l=(list card)
=/ ucom (get-comment:lib pid state)
?~ ucom `state =/ com u.ucom
=. comments (wipe-reps pid)
=. l [(cache-com com) l]
=/ upar (get-comment:lib parent.com state)
:: delete from child of parent
=. comments ?~ upar comments
=/ par u.upar
=/ nc (~(del in children.par) pid)
=. par par(children nc)
=. l [(cache-com par) l]
(put:gorm:tp comments [author.par id.par] par)
:: delete from reply of thread
=/ uted (get-thread:lib thread.com state)
=. threads ?~ uted threads
=/ ted u.uted
=/ nr %+ skip replies.ted |= rp=pid:tp .=(rp pid)
=. ted ted(replies nr)
=. l [(cache-ted pid.ted) l]
(put:torm:sur threads pid.ted ted)
:_ state :-
cache-root
l
--

View File

@ -36,7 +36,7 @@
'South Korean telecom company attacks torrent users with malware '
'Show HN: R2R V2 A open source RAG engine with prod features '
'From RSS to My Kindle '
'How the STL Uses Explicit (quuxplusone.github.io)'
'How the STL Uses Explicit'
'The brain makes a lot of waste. Now scientists think they know where it goes'
'The plan-execute pattern '
'1Living Computers Museum to permanently close, auction vintage items '

View File

@ -1,11 +1,12 @@
/- tp=post
|%
+$ pokes [%ui eyre-id=@ta p=ui-pokes]
+$ pokes [%ui ship=@p eyre-id=@ta p=ui-pokes]
+$ ui-pokes
$% [%submit-comment ted=thread text=@t]
[%submit-reply =comment:tp text=@t]
[%submit-thread title=@t url=@t text=@t]
[%vote ted=? =pid:tp vote=?]
[%del ted=? =pid:tp]
==
+$ state
$% state-0
@ -19,6 +20,7 @@ $: %0
::
mods=(set @p)
admins=(set @p)
blacklist=(set @p)
==
+$ threads ((mop pid:tp thread) ggth:tp)
++ torm ((on pid:tp thread) ggth:tp)

View File

@ -39,14 +39,12 @@
;< res=client-response:iris bind:m take-client-response:strandio
?. ?=(%finished -.res) (strand-fail:strand %no-body ~)
=/ headers headers.response-header.res
~& > header=headers
=/ redirect (get-header:http 'location' headers)
~& >> red=redirect
?^ redirect (pure:m [%| u.redirect])
::
?~ full-file.res (strand-fail:strand %no-body ~)
~& mime=-.u.full-file.res
=/ htmls=@t q.data.u.full-file.res
=/ json [%s htmls]
(pure:m [%& json])

View File

@ -33,9 +33,20 @@
=pid post-link
;+ (votes v)
;div:"{author}"
;a/"/forum/com/{post-link}":"{ago} ago"
;a/"/forum/ted/{post-link}":"{ago} ago"
;* comments
==
:: ++ delete-button
:: |= [is-admin=? is-ted=? post-link=tape]
:: ?. is-admin ~
:: =/ action ?: is-ted
:: "/del-ted/{post-link}"
:: "/del-com/{post-link}"
:: ;+
:: ;form(action action, method "post")
:: ;input(type "submit"):"Delete"
:: ==
++ post-metadata
|= [=pid:tp now=@da v=votes:tp reply-count=@ud is-ted=?]
=/ teds ?: is-ted "yeah" "nope"

View File

@ -1,5 +1,6 @@
/- sur=forum
/+ sig=sigil-sigil
|_ =bowl:gall
|_ [=state:sur =bowl:gall]
++ login ^- manx
?- (clan:title src.bowl)
%czar sigil
@ -10,22 +11,27 @@
==
++ login-prompt ^- manx
;a/"/forum/log":"Log In"
++ new-post-link ^- marl
:: TODO reverse this
:: ?: (~(has in admins.state) src.bowl) ~
;+ ;a/"/forum/add":"new post"
++ sigil
:: ;+ (sig(size 48) src.bowl)
=/ p (scow %p src.bowl)
;div.f.g2
;a/"/forum/add":"new post"
;* new-post-link
;a/"/forum/usr/{p}":"{p}"
==
++ $
;nav#topnav.fs.g2
;div.f.g2
;div#nav-main.fs
;a/"/":"~ Technical Journal"
;a/"https://urbitsystems.tech/":"~ Technical Journal"
;div#nav-dropdown:"↓"
==
;div#nav-links
;a/"/information":"Information"
;a/"https://urbitsystems.tech/information":"Information"
;a.active/"/forum":"Forum"
==
==

View File

@ -20,11 +20,13 @@
==
++ script ^~ %- trip
'''
function autoSave(){
function listeners(){
const form = document.getElementById("form");
const draftID = "new-thread";
const linkDiv = document.getElementById("thread-url");
const area = document.getElementById("textarea");
// autosave
window.addEventListener("load", () => {
const savedContent = localStorage.getItem(draftID);
console.log(savedContent, "saved")
@ -37,7 +39,12 @@
console.log("saving", area.value)
localStorage.setItem(draftID, area.value);
})
// toggler
linkDiv.addEventListener("input", () => {
if (linkDiv.value) textarea.disabled = true;
else textarea.disabled = false;
});
}
autoSave();
listeners();
'''
--

View File

@ -17,5 +17,9 @@
;input(type "hidden", name "redirect", value redirect-str);
;button(name "eauth", type "submit"):"Login"
==
;div.tc.nudge
;p:"If you don't have an Urbit ID, click on this link to get one for free."
;a.button/"https://redhorizon.com/join/2d55b768-a5f4-45cf-a4e5-a4302e05a1f9":"Get Urbit ID"
==
==
--

View File

@ -102,13 +102,13 @@
==
++ add-layout |= m=manx
%- layout :~
(navbar bowl)
(navbar state bowl)
m
==
++ serve-fragment |= =(pole knot) ^- manx
?+ pole !!
[%sigil ~]
=/ navb ~(. navbar bowl)
=/ navb ~(. navbar [state bowl])
=/ userdiv login:navb
userdiv
==
@ -121,6 +121,7 @@
++ serve-index |= t=@t ^- manx
=/ pag (slaw %ud t) ?~ pag manx-bail
=/ threads (get-thread-page:lib u.pag state)
(index [u.pag threads] state bowl)
++ serve-comment |= uidt=@t ^- manx
=/ uid (slaw:sr %uw uidt) ?~ uid manx-bail
@ -165,14 +166,32 @@
[%new-thread ~] handle-thread
[%vote %ted uid=@t vote=@t ~] (handle-vote .y uid.p vote.p)
[%vote %com uid=@t vote=@t ~] (handle-vote .n uid.p vote.p)
:: admin
[%del-ted uid=@t ~] (del .y uid.p)
[%del-com uid=@t ~] (del .n uid.p)
==
++ del
|= [is-ted=? uidt=@t]
=/ uid (slaw:sr %uw uidt) ?~ uid ~
=/ cued (cue u.uid)
=/ pid %- (soft pid:tp) cued
?~ pid ~
?: is-ted
=/ ted (get-thread:lib u.pid state)
?~ ted ~
(self-poke [%ui src.bowl eyre-id %del is-ted u.ted])
::
=/ com (get-comment:lib u.pid state)
?~ com ~
(self-poke [%ui src.bowl eyre-id %del is-ted u.com])
++ handle-vote |= [is-ted=? uidt=@t vote=@t]
=/ vot=? .=(vote 'gud')
=/ uid (slaw:sr %uw uidt) ?~ uid ~
=/ cued (cue u.uid)
=/ pid %- (soft pid:tp) cued
?~ pid ~
(self-poke [%ui eyre-id %vote is-ted u.pid vot])
(self-poke [%ui src.bowl eyre-id %vote is-ted u.pid vot])
++ handle-thread
?~ body ~
@ -184,7 +203,7 @@
?~ title ~
=/ url (~(get by bod) 'url')
?~ url ~
(self-poke [%ui eyre-id %submit-thread u.title u.url u.md])
(self-poke [%ui src.bowl eyre-id %submit-thread u.title u.url u.md])
++ handle-reply |= top=?
?~ body ~
@ -201,11 +220,11 @@
?: top
=/ ted (get-thread:lib u.pid state)
?~ ted ~
(self-poke [%ui eyre-id %submit-comment u.ted u.md])
(self-poke [%ui src.bowl eyre-id %submit-comment u.ted u.md])
::
=/ com (get-comment:lib u.pid state)
?~ com ~
(self-poke [%ui eyre-id %submit-reply u.com u.md])
(self-poke [%ui src.bowl eyre-id %submit-reply u.com u.md])
--
::
++ self-poke |= noun=*