Fix extra space and call migrate on boot

master v0.0
bel 2019-12-07 14:34:42 -07:00
parent 72169206f8
commit 2bb3bee83c
5 changed files with 22 additions and 7 deletions

View File

@ -2,8 +2,7 @@ FROM frolvlad/alpine-glibc:alpine-3.9_glibc-2.29
RUN apk update \
&& apk add --no-cache \
ca-certificates \
git \
bash \
bash jq curl \
php php-sqlite3 php-pdo php-pdo_mysql php-json php-pdo_sqlite
RUN mkdir -p /var/log

View File

@ -6,4 +6,12 @@
kill -9 1
) &
(
until curl localhost:39909; do
sleep 1
done
pushd /main/testdata
bash ./migrate.sh 192.168.0.86:44112 localhost:39909
) &
exec /main/exec-todo-server "$@"

View File

@ -30,7 +30,7 @@ type Task struct {
type StrList []string
func (sl StrList) MarshalJSON() ([]byte, error) {
s := strings.Join(sl, ", ")
s := strings.Join(sl, ",")
return json.Marshal(s)
}
@ -102,7 +102,7 @@ func (t *Task) MarshalJSON() ([]byte, error) {
"note": strings.Join(t.Note, "\n"),
"noteText": strings.Join(t.Note, "\n"),
"ow": 0,
"tags": strings.Join([]string(t.Tags), ", "),
"tags": strings.Join([]string(t.Tags), ","),
"tags_ids": strings.Join([]string(tagsIds), ","),
"duedate": t.Due.Format(fullFormat),
"dueClass": "",

View File

@ -65,7 +65,7 @@ func TestJSONMarshal(t *testing.T) {
json.Unmarshal(b, &m)
if v, ok := m["tags"]; !ok {
t.Error(ok, m)
} else if v != "a, b" {
} else if v != "a,b" {
t.Error(v, m)
}
}

12
testdata/migrate.sh vendored
View File

@ -30,7 +30,7 @@ function migrate_tasks() {
local to_addr="$2"
local from_list="$3"
local to_list=$(lookup_list "$from_addr" "$from_list" "$to_addr")
local has_tasks="$(list_tasks "$to_addr" "$to_list" | base64 --decode | jq .title)"
local has_tasks="$(list_tasks "$to_addr" "$to_list" | b64decode | jq .title)"
for task in $(list_tasks "$from_addr" "$from_list"); do
add_task "$to_addr" "$to_list" "$task" "$has_tasks"
done
@ -70,7 +70,7 @@ function list_tasks() {
function add_task() {
local addr="$1"
local list="$2"
local task="$(echo -n "$3" | base64 --decode | jq "del(.id, .listId)")"
local task="$(echo -n "$3" | b64decode | jq "del(.id, .listId)")"
local has_tasks="$4"
local title="$(echo "$task" | jq -r .title)"
local tags="$(echo "$task" | jq -r .tags)"
@ -105,6 +105,14 @@ function add_task() {
fi
}
function b64decode() {
if printf "" | base64 --decode 2> /dev/null; then
base64 --decode
else
base64 -d
fi
}
if [ "$0" == "$BASH_SOURCE" ]; then
echo bash migrate.sh 192.168.0.86:44112 localhost:39909
time main "$@"