Public Access
ease blog article upload
This commit is contained in:
+13
-11
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/bin/sh
|
||||
|
||||
cookie_path=./cookies.txt
|
||||
|
||||
@@ -14,10 +14,10 @@ print_help() {
|
||||
echo "> $0 logout"
|
||||
echo ""
|
||||
echo "create a new blog article:"
|
||||
echo "> $0 upload ./article.tar"
|
||||
echo "> $0 upload ./article-dir"
|
||||
echo ""
|
||||
echo "update an existing blog article:"
|
||||
echo "> $0 patch 123 ./article.tar"
|
||||
echo "> $0 patch 123 ./article-dir"
|
||||
echo ""
|
||||
echo "publish an existing blog article:"
|
||||
echo "> $0 publish 123"
|
||||
@@ -56,15 +56,16 @@ logout() {
|
||||
|
||||
upload() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "error: article file is not passed" >&2
|
||||
echo "error: article directory is not passed" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! [ -f "$1" ]; then
|
||||
echo "error: article file not found" >&2
|
||||
if ! [ -d "$1" ]; then
|
||||
echo "error: article directory not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
out=$(curl -v -f -X PUT -F "file=@$1" "$URL/api/blog" -b "$cookie_path" 2>&1)
|
||||
tar -C "$1" -cf /tmp/article.tar $(ls "$1")
|
||||
out=$(curl -v -f -X PUT -F "file=@/tmp/article.tar" "$URL/api/blog" -b "$cookie_path" 2>&1)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$out" >&2
|
||||
exit 1
|
||||
@@ -79,15 +80,16 @@ patch() {
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$2" ]; then
|
||||
echo "error: article file is not passed" >&2
|
||||
echo "error: article directory is not passed" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! [ -f "$2" ]; then
|
||||
echo "error: article file not found" >&2
|
||||
if ! [ -d "$2" ]; then
|
||||
echo "error: article directory not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
out=$(curl -v -f -X PATCH -F "file=@$2" "$URL/api/blog/$1" -b "$cookie_path" 2>&1)
|
||||
tar -C "$2" -cf /tmp/article.tar $(ls "$2")
|
||||
out=$(curl -v -f -X PATCH -F "file=@/tmp/article.tar" "$URL/api/blog/$1" -b "$cookie_path" 2>&1)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "$out" >&2
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user