From ca5baf50e3e9766c0446be060ef1a1000b41dd35 Mon Sep 17 00:00:00 2001 From: Dominique Liberda Date: Wed, 18 Jan 2023 06:35:55 +0100 Subject: [PATCH] - got rid of all legacy render_unsafe calls --- templates/header.shs | 2 +- templates/themes/default/elements/item.html | 4 ++++ templates/themes/default/fav.html | 14 +++++++++++++- templates/themes/default/feed.html | 14 +++++++++++++- templates/themes/default/playlist.html | 7 ++++++- templates/themes/default/subscribe.html | 12 ++++++++++-- templates/themes/default/watch.html | 2 +- templates/themes/retro/feed.html | 14 +++++++++++++- webroot/fav.shs | 16 +++++++++++----- webroot/feed.shs | 18 +++++++++++++----- webroot/playlist.shs | 13 ++++++++----- webroot/subscribe.shs | 14 +++++++++++--- webroot/watch.shs | 4 ++-- 13 files changed, 106 insertions(+), 28 deletions(-) create mode 100644 templates/themes/default/elements/item.html diff --git a/templates/header.shs b/templates/header.shs index 70d79d4..9e4bede 100644 --- a/templates/header.shs +++ b/templates/header.shs @@ -20,4 +20,4 @@ else strings_[query_nice]='' fi -render strings_ "${cfg[namespace]}/templates/themes/${cfg[template]}/elements/top.t" +render strings_ "${cfg[namespace]}/templates/themes/default/elements/top.html" diff --git a/templates/themes/default/elements/item.html b/templates/themes/default/elements/item.html new file mode 100644 index 0000000..618a7d6 --- /dev/null +++ b/templates/themes/default/elements/item.html @@ -0,0 +1,4 @@ + +
${.title} +
| ${.runtime} seconds | ${.views} views
+Uploaded by ${.channel}
diff --git a/templates/themes/default/fav.html b/templates/themes/default/fav.html index 4246b56..101b723 100644 --- a/templates/themes/default/fav.html +++ b/templates/themes/default/fav.html @@ -1,2 +1,14 @@ -<--- back to main

Your favourites

+

Your favourites

{{.fav}} +{{start ?fav}} + {{start _fav}} +
+ +
+ {{.name}} +

+
+ {{end _fav}} +{{else ?fav}} + Meow? no faves? +{{end ?fav}} diff --git a/templates/themes/default/feed.html b/templates/themes/default/feed.html index 47cf858..b61767b 100644 --- a/templates/themes/default/feed.html +++ b/templates/themes/default/feed.html @@ -1 +1,13 @@ -{{.feed}} +{{start ?feed}} + {{start _feed}} +
+ +
+ {{.title}} +
+ {{.date}} +
+ {{end _feed}} +{{else ?feed}} + Eh. something went wrong. Check if you're logged in and if you subscribe to anyone :p +{{end ?feed}} diff --git a/templates/themes/default/playlist.html b/templates/themes/default/playlist.html index b379393..99dd566 100644 --- a/templates/themes/default/playlist.html +++ b/templates/themes/default/playlist.html @@ -1 +1,6 @@ -{{.playlist}} +{{start _playlist}} + +
+ {{.title}} +

+{{end _playlist}} diff --git a/templates/themes/default/subscribe.html b/templates/themes/default/subscribe.html index 66f36e7..f3da6d4 100644 --- a/templates/themes/default/subscribe.html +++ b/templates/themes/default/subscribe.html @@ -1,2 +1,10 @@ -<--- back to main

Channels you subscribe to

-{{.subscribe}} +

Channels you subscribe to

+{{start ?sub}} + {{start _sub}} +
+ {{.name}}
+
+ {{end _sub}} +{{else ?sub}} + Meow? no subs 🥺? +{{end ?sub}} diff --git a/templates/themes/default/watch.html b/templates/themes/default/watch.html index 5137efa..8ce0997 100644 --- a/templates/themes/default/watch.html +++ b/templates/themes/default/watch.html @@ -10,7 +10,7 @@ {{.like_count}} likes
{{start ?fav}}Add to favourites
{{end ?fav}} - {{start ?unfav}}Remove from favourites
{{end ?unfav}} + {{start ?unfav}}Remove from favourites
{{else ?unfav}}{{end ?unfav}} {{start ?sub}}Subscribe to {{.uploader}}!
{{end ?sub}} {{start ?unsub}}Unsubscribe from {{.uploader}}!
{{end ?unsub}} {{start ?login}}Log in to add this video to your favourites and/or subscribe to this channel!
{{end ?login}} diff --git a/templates/themes/retro/feed.html b/templates/themes/retro/feed.html index 47cf858..35c5f9b 100644 --- a/templates/themes/retro/feed.html +++ b/templates/themes/retro/feed.html @@ -1 +1,13 @@ -{{.feed}} +{{start ?feed}} + {{start _feed}} +
+ +
+ ${video_title[$i]} +
+ $(date -d "@${video_date[$i]}" "+%H:%M, %d %h %Y") +
+ {{end _feed}} +{{else ?feed}} + Eh. something went wrong, maybe you're not logged in? +{{end ?feed}} diff --git a/webroot/fav.shs b/webroot/fav.shs index 5fcc0ea..96fcbd9 100644 --- a/webroot/fav.shs +++ b/webroot/fav.shs @@ -13,6 +13,9 @@ if [[ ${cfg[template]} == 'default' ]]; then source templates/head.sh fi +nested_declare fav +declare -A fav_ + IFS=$'\n' for i in $(tac storage/faves | grep -P "^$(session_get_username ${cookies[sh_session]}):"); do IFS=':' @@ -20,12 +23,15 @@ for i in $(tac storage/faves | grep -P "^$(session_get_username ${cookies[sh_ses if [[ ${array[1]} == '' ]]; then break fi - strings[fav]+="

${array[@]:2:999}

"; + + fav_[id]="${array[1]}" + fav_[name]="${array[@]:2:9999}" + nested_add fav fav_ done -if [[ ! ${strings[fav]} ]]; then - strings[fav]="You are not logged in or you do not have any favorites" -fi +[[ ${fav_[id]} != '' ]] && strings[?sub]=true +strings[_fav]="fav" + source "${cfg[namespace]}/templates/header.shs" -render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/fav.html" +render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/fav.html" diff --git a/webroot/feed.shs b/webroot/feed.shs index 5d8dcce..bd21b9c 100644 --- a/webroot/feed.shs +++ b/webroot/feed.shs @@ -19,14 +19,22 @@ if session_verify "${cookies[sh_session]}"; then video_uploader+=($(grep -Poh "name>.*?//;s/<\///' | head -n 1)) done <<< "$(cat storage/subscribed | grep -P "^$(session_get_username ${cookies[sh_session]}):")" + [[ ${#video_id[@]} -gt 0 ]] && strings[?feed]=true + queue=$(for (( i=0; i<${#video_id[@]}; i++ )); do echo "$i ${video_date[i]}"; done | sort -k2r | awk '{print $1}') - + + nested_declare feed + declare -A feed_ while read i; do - strings[feed]+="
${video_title[$i]}
$(date -d "@${video_date[$i]}" "+%H:%M, %d %h %Y")
" + feed_[id]="${video_id[$i]}" + feed_[title]="${video_title[$i]}" + feed_[date]="$(date -d "@${video_date[$i]}" "+%H:%M, %d %h %Y")" + feed_[uploader]="${video_uploader[$i]}" + #strings[feed]+="
" + nested_add feed feed_ done <<< "$queue" -else - strings[feed]="You're not logged in!" + strings[_feed]="feed" fi source "${cfg[namespace]}/templates/header.shs" -render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/feed.html" +render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/feed.html" diff --git a/webroot/playlist.shs b/webroot/playlist.shs index 9362b2e..4c02b4a 100644 --- a/webroot/playlist.shs +++ b/webroot/playlist.shs @@ -18,13 +18,16 @@ IFS=$'\n' video_title=($(jq -r '.title' <<< $data)) video_id=($(jq -r '.id' <<< $data)) +nested_declare list +declare -A item for (( i=0; i<${#video_id[@]}; i++ )); do - strings[playlist]+="
${video_title[$i]}

" + item[id]="${video_id[$i]}" + item[playlist]="${get_data[list]}" + item[title]="${video_title[$i]}" + nested_add list item done -if [[ ! ${strings[playlist]} ]]; then - strings[playlist]="Invalid playlist or playlist does not have videos" -fi +strings[_playlist]="list" source "${cfg[namespace]}/templates/header.shs" -render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/playlist.html" +render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/playlist.html" diff --git a/webroot/subscribe.shs b/webroot/subscribe.shs index 0edb154..4f59d39 100644 --- a/webroot/subscribe.shs +++ b/webroot/subscribe.shs @@ -13,6 +13,9 @@ if [[ ${cfg[template]} == 'default' ]]; then source templates/head.sh fi +nested_declare channels +declare -A channels_ + IFS=$'\n' for i in $(tac storage/subscribed | grep -P "^$(session_get_username ${cookies[sh_session]}):"); do IFS=':' @@ -21,10 +24,15 @@ for i in $(tac storage/subscribed | grep -P "^$(session_get_username ${cookies[s if [[ ${array[1]} == '' ]]; then break fi - - strings[subscribe]+="
${array[@]:2:9999}
"; + + channels_[id]="${array[1]}" + channels_[name]="${array[@]:2:9999}" + nested_add channels channels_ done +[[ ${channels_[id]} != '' ]] && strings[?sub]=true +strings[_sub]="channels" + unset IFS if [[ ! ${strings[subscribe]} ]]; then @@ -32,4 +40,4 @@ if [[ ! ${strings[subscribe]} ]]; then fi source "${cfg[namespace]}/templates/header.shs" -render_unsafe strings "${cfg[namespace]}/templates/themes/${cfg[template]}/subscribe.html" +render strings "${cfg[namespace]}/templates/themes/${cfg[template]}/subscribe.html" diff --git a/webroot/watch.shs b/webroot/watch.shs index 5a9e390..6c9804d 100755 --- a/webroot/watch.shs +++ b/webroot/watch.shs @@ -138,7 +138,7 @@ if [[ "${get_data[v]}" ]]; then strings[id]="${get_data[v]}" # - if [[ ${cookies[sh_session]} ]]; then + if [[ "${cookies[sh_session]}" != '' ]]; then if [[ $(grep $(session_get_username "${cookies[sh_session]}") storage/faves | grep "${get_data[v]}") == '' ]]; then strings[?fav]=true else @@ -166,7 +166,7 @@ if [[ "${get_data[v]}" ]]; then vid="$(cat "temp/${written_id}_https_-_"*"watch"*".dump")" vid_json="$(tr -d '\n' <<< "$vid" | grep -Poh "ytInitialData.*?" | sed 's/ytInitialData = //;s/<\/script>//')" - strings[recommended]=$() + #strings[recommended]=$() _jq_to_array '.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results[] | .compactAutoplayRenderer.contents[0].compactVideoRenderer, .compactVideoRenderer | if .videoId != null then