mirror of
https://github.com/aljazceru/cyphernode.git
synced 2026-01-04 05:25:37 +01:00
Added inserted_id in stamp response and content-type on get OTS file
This commit is contained in:
@@ -16,14 +16,23 @@ serve_ots_stamp()
|
||||
local result
|
||||
local returncode
|
||||
local errorstring
|
||||
local id_inserted
|
||||
local requested
|
||||
local row
|
||||
|
||||
# Already requested?
|
||||
local requested
|
||||
requested=$(sql "SELECT requested FROM stamp WHERE hash='${hash}'")
|
||||
if [ -n "${requested}" ]; then
|
||||
row=$(sql "SELECT id, requested FROM stamp WHERE hash='${hash}'")
|
||||
trace "[serve_ots_stamp] row=${row}"
|
||||
|
||||
if [ -n "${row}" ]; then
|
||||
# Hash exists in DB...
|
||||
trace "[serve_ots_stamp] Hash already exists in DB."
|
||||
|
||||
requested=$(echo "${row}" | cut -d '|' -f2)
|
||||
trace "[serve_ots_stamp] requested=${requested}"
|
||||
id_inserted=$(echo "${row}" | cut -d '|' -f1)
|
||||
trace "[serve_ots_stamp] id_inserted=${id_inserted}"
|
||||
|
||||
if [ "${requested}" -eq "1" ]; then
|
||||
# Stamp already requested
|
||||
trace "[serve_ots_stamp] Stamp already requested"
|
||||
@@ -38,6 +47,8 @@ serve_ots_stamp()
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
if [ "${returncode}" -eq "0" ]; then
|
||||
id_inserted=$(sql "SELECT id FROM stamp WHERE hash='${hash}'")
|
||||
trace_rc $?
|
||||
errorstring=$(request_ots_stamp "${hash}")
|
||||
returncode=$?
|
||||
trace_rc ${returncode}
|
||||
@@ -48,10 +59,12 @@ serve_ots_stamp()
|
||||
fi
|
||||
fi
|
||||
|
||||
result="{\"method\":\"ots_stamp\",\"hash\":\"${hash}\",\"id\":\"${id_inserted}\",\"result\":\""
|
||||
|
||||
if [ "${returncode}" -eq "0" ]; then
|
||||
result="{\"method\":\"ots_stamp\",\"hash\":\"${hash}\",\"result\":\"success\""
|
||||
result="${result}success\"}"
|
||||
else
|
||||
result="{\"method\":\"ots_stamp\",\"hash\":\"${hash}\",\"result\":\"error\",\"error\":\"${errorstring}\""
|
||||
result="${result}error\",\"error\":\"${errorstring}\"}"
|
||||
fi
|
||||
|
||||
trace "[serve_ots_stamp] result=${result}"
|
||||
|
||||
@@ -27,14 +27,20 @@ file_response_to_client()
|
||||
local pathfile="${path}${filename}"
|
||||
local returncode
|
||||
|
||||
trace "[file_response_to_client] path=${path}"
|
||||
trace "[file_response_to_client] filename=${filename}"
|
||||
trace "[file_response_to_client] pathfile=${pathfile}"
|
||||
local file_length=$(stat -c'%s' ${pathfile})
|
||||
trace "[file_response_to_client] file_length=${file_length}"
|
||||
|
||||
[ -r "${pathfile}" ] \
|
||||
&& echo -ne "HTTP/1.1 200 OK\r\nContent-Disposition: inline; filename=\"${filename}\"\r\nContent-Length: $(stat -c'%s' ${pathfile})\r\n\r\n" \
|
||||
&& echo -ne "HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nContent-Disposition: inline; filename=\"${filename}\"\r\nContent-Length: ${file_length}\r\n\r\n" \
|
||||
&& cat ${pathfile}
|
||||
|
||||
[ ! -r "${pathfile}" ] && echo -ne "HTTP/1.1 404 Not Found\r\n"
|
||||
|
||||
# Small delay needed for the data to be processed correctly by peer
|
||||
sleep 0.2s
|
||||
sleep 0.5s
|
||||
}
|
||||
|
||||
case "${0}" in *responsetoclient.sh) response_to_client $@;; esac
|
||||
|
||||
Reference in New Issue
Block a user