X-Git-Url: https://git.plutz.net//?a=blobdiff_plain;f=index.cgi;h=0078a2f8f1837201ae7fc7a19324cd0fe01d4818;hb=092bfad64ae6b2022991f6193f042d6d53bf10c2;hp=d4f4cec6f8ed573ce27032ccdf9b0467798d0fee;hpb=98fe1cdcebd49e0a6de909a50f5488d473f6e11c;p=rigidfind diff --git a/index.cgi b/index.cgi index d4f4cec..0078a2f 100755 --- a/index.cgi +++ b/index.cgi @@ -6,10 +6,10 @@ [ "$_DATE" ] || _DATE="$(date +%s)" -debug "$REQUEST_METHOD $REQUEST_URI $SERVER_PROTOCOL" +debug "$REQUEST_METHOD $REQUEST_URI $SERVER_PROTOCOL $_DATE" ingest() { - local J="$1" + local J="$1" ztmp="${TMP:-/tmp}/zipfile_$$.zip" # json_get "$J" title # json_get "$J" parts.comments @@ -39,24 +39,28 @@ ingest() { | sed 's;<[^>]*>;;g' ;; *.docx) - printf %s "$content" |base64 -d \ - | unzip -qc /dev/stdin word/document.xml \ + printf %s "$content" |base64 -d >"$ztmp" + unzip -qc "$ztmp" word/document.xml \ | head -c 128M | sed 's;<[^>]*>;;g' + rm -- "$ztmp" ;; *.xlsx) - printf %s "$content" |base64 -d \ - | unzip -qc /dev/stdin xl/sharedStrings.xml \ + printf %s "$content" |base64 -d >"$ztmp" + unzip -qc "$ztmp" xl/sharedStrings.xml \ | head -c 128M | sed 's;<[^>]*>; ;g' + rm -- "$ztmp" ;; *.odt) - printf %s "$content" |base64 -d \ - | unzip -qc /dev/stdin content.xml \ + printf %s "$content" |base64 -d >"$ztmp" + unzip -qc "$ztmp" content.xml \ | head -c 128M | sed 's;<[^>]*>;;g' + rm -- "$ztmp" ;; *.ods|*.odp) - printf %s "$content" |base64 -d \ - | unzip -qc /dev/stdin content.xml \ + printf %s "$content" |base64 -d >"$ztmp" + unzip -qc "$ztmp" content.xml \ | head -c 128M | sed 's;<[^>]*>; ;g' + rm -- "$ztmp" ;; *):;; esac @@ -122,15 +126,23 @@ if [ "$REQUEST_METHOD" = "PUT" ]; then s;,[ \t\r\n]*"content"[ \t\r\n]*:[ \t\r\n]*"[^"]*";; ')" J="$(json_load "${J}")" - - ingest "$J" "$content"\ - | "${_EXEC}/concordance.sh" \ - "$_DATA/$_INDEX/" "$(STRING "$_doc") $_DATE" + + debug "Content: ${#content} bytes" + debug "$(json_dump "$J")" + + if [ "${#content}" -gt 0 ]; then + ingest "$J" "$content"\ + | "${_EXEC}/concordance.sh" \ + "$_DATA/$_INDEX/" "$(STRING "$_doc") $_DATE" + fi J="${J#obj:}" J="$(DB2 "$J" set _indexdate num:"$_DATE")" - if DBM "$_records" insert "$_doc" "$J"; then + if [ "${#content}" -eq 0 ]; then + printf '%s: %s\r\n' "Status" "200 OK" + result="updated" + elif DBM "$_records" insert "$_doc" "$J"; then printf '%s: %s\r\n' "Status" "201 Created" "Location" "/${_INDEX}/_doc/$(URL "$_doc")" \ result="created" elif DBM "$_records" update "$_doc" "$J"; then @@ -141,10 +153,10 @@ if [ "$REQUEST_METHOD" = "PUT" ]; then exit 0 fi - sed 's;$;\r;' <<-EOF - X-elastic-product: Elasticsearch - content-type: application/vnd.elasticsearch+json;compatible-with=8 - + cat <<-EOF + X-elastic-product: Elasticsearch + content-type: application/vnd.elasticsearch+json;compatible-with=8 + { "_index": $(json_dump str:"${_INDEX}"), "_id": $(json_dump str:"$_doc"), "result": "$result", @@ -169,10 +181,10 @@ elif [ "$REQUEST_METHOD" = "DELETE" ]; then result="not_found" fi - sed 's;$;\r;' <<-EOF - X-elastic-product: Elasticsearch - content-type: application/vnd.elasticsearch+json;compatible-with=8 - + cat <<-EOF + X-elastic-product: Elasticsearch + content-type: application/vnd.elasticsearch+json;compatible-with=8 + { "_index": $(json_dump str:"${_INDEX}"), "_id": $(json_dump str:"$_doc"), "result": "$result", @@ -203,11 +215,11 @@ elif [ "$REQUEST_METHOD" = "POST" ]; then )" results="${results% }" - sed 's;$;\r;' <<-EOF - Status: 200 OK - X-elastic-product: Elasticsearch - Content-Type: application/vnd.elasticsearch+json;compatible-with=8 - + cat <<-EOF + Status: 200 OK + X-elastic-product: Elasticsearch + Content-Type: application/vnd.elasticsearch+json;compatible-with=8 + { "took":0, "timed_out":false, "_shards":{"total":1,"successful":1,"skipped":0,"failed":0}, @@ -224,11 +236,11 @@ elif [ "$REQUEST_METHOD" = "HEAD" ]; then [ ! "${accept#*"vnd.elasticsearch+json"*}" ] \ && ctype="${accept}" || ctype="application/json" - sed 's;$;\r;' <<-EOF - HTTP/1.1 200 OK - X-elastic-product: Elasticsearch - content-type: ${ctype} - + cat <<-EOF + HTTP/1.1 200 OK + X-elastic-product: Elasticsearch + content-type: ${ctype} + EOF exit 0 @@ -237,15 +249,15 @@ elif [ "$REQUEST_METHOD" = "GET" ]; then [ ! "${accept#*"vnd.elasticsearch+json"*}" ] \ && ctype="${accept}" || ctype="application/json" - sed 's;$;\r;' <<-EOF - HTTP/1.1 200 OK - X-elastic-product: Elasticsearch - content-type: ${ctype} - + cat <<-EOF + HTTP/1.1 200 OK + X-elastic-product: Elasticsearch + content-type: ${ctype} + EOF if [ "$PATH_INFO" = "/${_INDEX}/" ]; then - sed 's;$;\r;' <<-EOF + cat <<-EOF { $(json_dump str:"${_INDEX}"): { "aliases":{}, "mappings": { @@ -276,7 +288,7 @@ elif [ "$REQUEST_METHOD" = "GET" ]; then } EOF else - sed 's;$;\r;' <<-EOF + cat <<-EOF { "name" : "head", "cluster_name" : "elasticsearch", "version" : {