-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrs_uploadfile
executable file
·55 lines (47 loc) · 1.75 KB
/
rs_uploadfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
SCRIPTDIR="$(dirname "$0")"
CONF_FILE="${SCRIPTDIR}/pbpro.conf"
. "${CONF_FILE}" || { echo "Missing ${CONF_FILE}. Exiting." ; exit 1 ; }
unset mediaid
OPTIND=1
while getopts ":m:" OPT ; do
case "${OPT}" in
m) mediaid="${OPTARG}" ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
*) echo "bad option -${OPTARG}" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
_convert_to_full_path(){
echo $(cd $(dirname "${1}"); pwd)/$(basename "${1}")
}
_createresource(){
query="user=${user}&function=create_resource¶m1=3¶m2=0"
sign=$(printf '%s' "${private_key}${query}" | sha256deep)
curl -# "${api_url}/?$query&sign=${sign}"
}
_uploadfile(){
resourceid=$(_createresource)
if [[ ! -n "${mediaid}" ]] ; then
mediaid=$(basename "${1%.*}")
fi
query="user=${user}&function=update_field¶m1=${resourceid}¶m2=8¶m3=${mediaid}"
sign=$(printf '%s' "${private_key}${query}" | sha256deep)
curl -# "${api_url}/?$query&sign=${sign}"
query="user=${user}&function=upload_file¶m1=${resourceid}¶m2=true¶m3=false¶m4=false¶m5=${1}"
sign=$(printf '%s' "${private_key}${query}" | sha256deep)
curl -# "${api_url}/?$query&sign=${sign}"
}
while [ "${*}" != "" ] ; do
# get context about the input
INPUT="${1}"
shift
RS_ID=$("${SCRIPTDIR}/rs_search" $(basename "${INPUT%.*}"))
if [[ -z "${RS_ID}" ]] ; then
_uploadfile $(_convert_to_full_path "${INPUT}")
RS_ID=$("${SCRIPTDIR}/rs_search" $(basename "${INPUT%.*}"))
echo "$(basename "${INPUT%.*}") is now available at pages/view.php?ref=${RS_ID}"
else
echo "$(basename "${INPUT%.*}") is already represented at pages/view.php?ref=${RS_ID}"
fi
done