Skip to content

Commit

Permalink
fix: link clicks empty array validation
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdonado committed Jul 12, 2024
1 parent cebbd48 commit 8f33375
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM alpine:edge as base

WORKDIR /usr/src/app

RUN apk update && apk add --no-cache \
Expand All @@ -19,8 +20,8 @@ RUN shards build --progress
FROM base AS release
RUN mkdir -p /usr/src/app/sqlite
COPY --from=build /usr/src/app/db db
COPY --from=build /usr/src/app/data data
COPY --from=build /usr/src/app/bin /usr/local/bin
COPY --from=build /usr/src/app/data /usr/local/data

EXPOSE 4000/tcp
CMD ["bit"]
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# bit

> Lightning fast, lightweight and minimal self-hosted url shortener
`latest` tag is unstable (Under development!)

## Benchmark

Expand Down
2 changes: 1 addition & 1 deletion app/routes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module App
before_all do |env|
env.response.headers["Access-Control-Allow-Origin"] = "*"
env.response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, DELETE, OPTIONS"
env.response.headers["Access-Control-Allow-Headers"] = "Content-Type, Accept, X-Api-Key"
env.response.headers["Access-Control-Allow-Headers"] = "Content-Type, Accept, Origin, X-Api-Key"
end

after_all do |env|
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/link.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module App::Serializers
builder.field("id", @link.id)
builder.field("refer", @refer)
builder.field("origin", @link.url)
builder.field("clicks", @link.clicks.map { |click| App::Serializers::Click.new(click) })
builder.field("clicks", @link.clicks.try(&.map { |click| App::Serializers::Click.new(click) }) || [] of App::Serializers::Click)
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ function measure {
--header "X-Api-Key: $api_key" \
--header "Content-Type: application/json" \
--data "{ \"url\": \"https://kagi.com\" }")

refer=$(echo $response | awk -F'"' '/"refer":/{print $(NF-1)}')

if [[ -n $refer ]]; then
refer_links+=("$refer")
if (( i % 100 == 0 )); then
echo "Created short link $i/$num_links"
fi
else
echo "Failed to create short link $i"
echo $response
exit 1
fi
done

Expand Down

0 comments on commit 8f33375

Please sign in to comment.