Startup fix, cookie improvements, #build

Changed
- lock creating superuser at startup by @dshoreman
- auto validate cookie
- API: return cookie validation state for browser extension
- Finetuning CSS mobile layout
This commit is contained in:
simon 2022-06-27 10:14:59 +07:00
commit e8e240c89b
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
6 changed files with 58 additions and 19 deletions

View File

@ -5,13 +5,14 @@ if [[ -z "$ELASTIC_USER" ]]; then
export ELASTIC_USER=elastic
fi
ENV_VARS=("TA_USERNAME" "TA_PASSWORD" "ELASTIC_PASSWORD" "ELASTIC_USER")
for each in "${ENV_VARS[@]}"; do
if ! [[ -v $each ]]; then
echo "missing environment variable $each"
exit 1
fi
done
cachedir=/cache
[[ -d $cachedir ]] || cachedir=.
lockfile=${cachedir}/initsu.lock
required="Missing required environment variable"
[[ -f $lockfile ]] || : "${TA_USERNAME:?$required}"
: "${TA_PASSWORD:?$required}"
: "${ELASTIC_PASSWORD:?$required}"
# ugly nginx and uwsgi port overwrite with env vars
if [[ -n "$TA_PORT" ]]; then
@ -39,12 +40,27 @@ done
# start python application
python manage.py makemigrations
python manage.py migrate
export DJANGO_SUPERUSER_PASSWORD=$TA_PASSWORD && \
python manage.py createsuperuser --noinput --name "$TA_USERNAME"
if [[ -f $lockfile ]]; then
echo -e "\e[33;1m[WARNING]\e[0m This is not the first run! Skipping" \
"superuser creation.\nTo force it, remove $lockfile"
else
export DJANGO_SUPERUSER_PASSWORD=$TA_PASSWORD
output="$(python manage.py createsuperuser --noinput --name "$TA_USERNAME" 2>&1)"
case "$output" in
*"Superuser created successfully"*)
echo "$output" && touch $lockfile ;;
*"That name is already taken."*)
echo "Superuser already exists. Creation will be skipped on next start."
touch $lockfile ;;
*) echo "$output" && exit 1
esac
fi
python manage.py collectstatic --noinput -c
nginx &
celery -A home.tasks worker --loglevel=INFO &
celery -A home beat --loglevel=INFO \
-s "${BEAT_SCHEDULE_PATH:-/cache/celerybeat-schedule}" &
-s "${BEAT_SCHEDULE_PATH:-${cachedir}/celerybeat-schedule}" &
uwsgi --ini uwsgi.ini

View File

@ -233,11 +233,14 @@ List of valid task names:
## Cookie View
Check your youtube cookie settings
Check your youtube cookie settings, *status* turns to `true` if cookie has been validated.
GET /api/cookie/
```json
{
"cookie_enabled": true
"cookie_enabled": true,
"status": true,
"validated": <timestamp>,
"validated_str": "timestamp"
}
```

View File

@ -488,9 +488,11 @@ class CookieView(ApiBaseView):
"""handle get request"""
# pylint: disable=unused-argument
config = AppConfig().config
cookie_enabled = config["downloads"]["cookie_import"]
valid = RedisArchivist().get_message("cookie:valid")
response = {"cookie_enabled": config["downloads"]["cookie_import"]}
response.update(valid)
return Response({"cookie_enabled": cookie_enabled})
return Response(response)
@staticmethod
def post(request):

View File

@ -5,6 +5,7 @@ functionality:
"""
import os
from datetime import datetime
from http import cookiejar
from io import StringIO
@ -102,6 +103,7 @@ class CookieHandler:
def revoke():
"""revoke cookie"""
RedisArchivist().del_message("cookie")
RedisArchivist().del_message("cookie:valid")
RedisArchivist().set_message(
"config", False, path=".downloads.cookie_import"
)
@ -115,7 +117,8 @@ class CookieHandler:
"extract_flat": True,
}
validator = YtWrap(obs_request, self.config)
response = validator.extract("LL")
response = bool(validator.extract("LL"))
self.store_validation(response)
# update in redis to avoid expiring
modified = validator.obs["cookiefile"].getvalue()
@ -134,4 +137,15 @@ class CookieHandler:
)
print("cookie validation failed, exiting...")
return bool(response)
return response
@staticmethod
def store_validation(response):
"""remember last validation"""
now = datetime.now()
message = {
"status": response,
"validated": int(now.strftime("%s")),
"validated_str": now.strftime("%Y-%m-%d %H:%M"),
}
RedisArchivist().set_message("cookie:valid", message)

View File

@ -9,4 +9,4 @@ requests==2.28.0
ryd-client==0.0.3
uWSGI==2.0.20
whitenoise==6.2.0
yt_dlp==2022.5.18
yt_dlp==2022.6.22.1

View File

@ -1086,8 +1086,12 @@ button:hover {
}
/* tablet */
@media screen and (max-width: 1000px) {
.boxed-content {
@media screen and (max-width: 1000px), screen and (max-height: 850px) {
.boxed-content,
.boxed-content.boxed-4,
.boxed-content.boxed-5,
.boxed-content.boxed-6,
.boxed-content.boxed-7 {
width: 90%;
}
.video-list.grid.grid-3,