2024-05-17 16:12:35 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# thx: https://stackoverflow.com/a/27601038
|
|
|
|
waitport() {
|
|
|
|
ATTEMPTS=50
|
|
|
|
while [ $((ATTEMPTS-=1)) -gt 0 ] && ! nc -z localhost $1; do
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
|
|
|
|
[ "$ATTEMPTS" != 0 ] || exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
test_api() {
|
|
|
|
waitport 3000
|
2024-08-03 15:51:46 +00:00
|
|
|
curl -m 3 http://localhost:3000/
|
2024-09-12 08:40:37 +00:00
|
|
|
API_RESPONSE=$(curl -m 10 http://localhost:3000/ \
|
2024-05-17 16:12:35 +00:00
|
|
|
-X POST \
|
|
|
|
-H "Accept: application/json" \
|
|
|
|
-H "Content-Type: application/json" \
|
2024-08-03 09:29:29 +00:00
|
|
|
-d '{"url":"https://www.tiktok.com/@fatfatmillycat/video/7195741644585454894"}')
|
2024-05-17 16:12:35 +00:00
|
|
|
|
2024-08-03 09:29:29 +00:00
|
|
|
echo "API_RESPONSE=$API_RESPONSE"
|
2024-05-17 16:12:35 +00:00
|
|
|
STATUS=$(echo "$API_RESPONSE" | jq -r .status)
|
|
|
|
STREAM_URL=$(echo "$API_RESPONSE" | jq -r .url)
|
2024-09-04 18:26:48 +00:00
|
|
|
[ "$STATUS" = tunnel ] || exit 1;
|
2024-09-12 08:40:37 +00:00
|
|
|
S=$(curl -I -m 10 "$STREAM_URL")
|
2024-05-17 16:12:35 +00:00
|
|
|
|
2024-08-03 09:29:29 +00:00
|
|
|
CONTENT_LENGTH=$(echo "$S" \
|
2024-05-17 16:12:35 +00:00
|
|
|
| grep -i content-length \
|
|
|
|
| cut -d' ' -f2 \
|
|
|
|
| tr -d '\r')
|
|
|
|
|
|
|
|
echo "$CONTENT_LENGTH"
|
|
|
|
[ "$CONTENT_LENGTH" = 0 ] && exit 1
|
|
|
|
if [ "$CONTENT_LENGTH" -lt 512 ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_api() {
|
|
|
|
export API_PORT=3000
|
|
|
|
export API_URL=http://localhost:3000
|
2024-08-03 09:29:29 +00:00
|
|
|
timeout 10 pnpm run --prefix api start &
|
|
|
|
API_PID=$!
|
2024-05-17 16:12:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup_web() {
|
2024-10-30 11:13:36 +00:00
|
|
|
pnpm run --prefix web check
|
2024-08-03 09:29:29 +00:00
|
|
|
pnpm run --prefix web build
|
2024-05-17 16:12:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cd "$(git rev-parse --show-toplevel)"
|
2024-08-03 09:29:29 +00:00
|
|
|
pnpm install --frozen-lockfile
|
2024-05-17 16:12:35 +00:00
|
|
|
|
|
|
|
if [ "$1" = "api" ]; then
|
2024-08-03 09:29:29 +00:00
|
|
|
setup_api
|
2024-05-17 16:12:35 +00:00
|
|
|
test_api
|
2024-08-03 09:29:29 +00:00
|
|
|
[ "$API_PID" != "" ] \
|
|
|
|
&& kill "$API_PID"
|
2024-05-17 16:12:35 +00:00
|
|
|
elif [ "$1" = "web" ]; then
|
2024-08-03 09:29:29 +00:00
|
|
|
setup_web
|
2024-05-17 16:12:35 +00:00
|
|
|
else
|
|
|
|
echo "usage: $0 <api/web>" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-09-12 08:40:37 +00:00
|
|
|
wait || exit $?
|