]> git.plutz.net Git - serve0/blob - actions/meta.sh
tagging engine
[serve0] / actions / meta.sh
1 #!/bin/zsh
2
3 info="$_GET[\"i\"]"
4 file="{$DATA}/meta/$info.meta"
5
6 if [ -n "${CONTENT_LENGTH}" -a "${CONTENT_LENGTH}" -gt 0 ]; then
7 (head -c "${CONTENT_LENGTH}"; echo)|sed 's/&/\n/g' |while read line; do
8   if (egrep -xq 'length=[0-9]{1,5}' <<<"${line}"); then
9     length="$(cut -d= -f2 <<<"${line}")"
10   elif (egrep -xq 'width=[0-9]{1,5}' <<<"${line}"); then
11     width="$(cut -d= -f2 <<<"${line}")"
12   elif (egrep -xq 'height=[0-9]{1,5}' <<<"${line}"); then
13     height="$(cut -d= -f2 <<<"${line}")"
14   elif (egrep -xq 'tag=.+' <<<"${line}"); then
15     tag="$(sed -r 's:^tag=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
16     tag="$(echo -e "${tag}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
17     tagacc="$tag|$tagacc"
18   elif (egrep -xq 'tags=.+' <<<"${line}"); then
19     tags="$(sed -r 's:^tags=(.*)$:\1:;s:\+:_:g;s:%:\\x:g' <<<"$line")"
20     tags="$(echo -e "${tags}" |sed -r 's:\t| :_:g;s:^!|\r|\$|\^::g;s:\\:\\\\:g;s/</\&lt\;/g;s/>/\&gt\;/g')"
21   elif (egrep -xq 'description=.+' <<<"${line}"); then
22     description="$(cut -d= -f2- <<<"${line}" |sed 's/+/ /g;s/%/\\x/g')"
23     description="$(echo -e "${description}" |sed 's/\r//g;s/\\/\\\\/g;s/</\&lt\;/g;s/>/\&gt\;/g')"
24   elif (egrep -xq 'trash=.+' <<<"${line}"); then
25     trash="true"
26   elif (egrep -xq 'cancel=.+' <<<"${line}"); then
27     cancel="true"
28   elif (egrep -xq 'f=.+' <<<"${line}"); then
29     filter="$(cut -d= -f2- <<<"${line}")"
30   elif (egrep -xq 's=.+' <<<"${line}"); then
31     search="$(cut -d= -f2- <<<"${line}")"
32   elif (egrep -xq 'p=.+' <<<"${line}"); then
33     page="$(cut -d= -f2- <<<"${line}")"
34   elif (egrep -xq 'o=.+' <<<"${line}"); then
35     order="$(cut -d= -f2- <<<"${line}")"
36   fi
37 done
38 fi
39
40 [ -z "$cancel" ] && if [ "$trash" = "true" ]; then
41   rm "${_DATA}/thumbs/$info.jpg" 2>/dev/null
42   mv "${_DATA}/videos/$info" "${_DATA}/meta/$info.meta" "${_DATA}/trash/" 2>/dev/null
43   rm "${_DATA}/cache/$info.cache" 2>/dev/null
44   rm ${_DATA}/cache/\?* 2>/dev/null
45 else
46   echo -e "$length\t$width\t$height\t$info" > "$file"
47   echo -e "${tagacc}${tags}" |tr '\n' '|' >> "$file"
48   echo >>"$file"
49   echo -e "${description}" >> "$file"
50   rm "${_DATA}/cache/$info.cache" 2>/dev/null
51   rm ${_DATA}/cache/\?* 2>/dev/null
52 fi
53
54 echo -n "Location: index.cgi?i=&p=${page}&s=${search}&f=${filter}&o=${order}#$info\n\n"