-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Danbooru download Cloudflare 403 error
- Loading branch information
Showing
11 changed files
with
190 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,51 @@ | ||
from os import path | ||
from typing import List, Optional | ||
|
||
from environs import Env | ||
|
||
env = Env() | ||
# read config from .env file if exists | ||
env.read_env() | ||
|
||
ENV = env.str("ENV", default="production") | ||
TOKEN = env.str("TOKEN") | ||
ENV: str = env.str("ENV", default="production") | ||
TOKEN: str = env.str("TOKEN") | ||
|
||
# Webhook url, eg: https://xxx.fly.dev/, should end with '/' | ||
WEBHOOK_URL = env.str("WEBHOOK_URL", default=None) | ||
HOST = env.str("HOST", default="0.0.0.0") | ||
WEBHOOK_URL: str = env.str("WEBHOOK_URL", default=None) | ||
HOST: str = env.str("HOST", default="0.0.0.0") | ||
# Port is automatically set if on Heroku or fly.io | ||
PORT = env.int("PORT", default=80) | ||
PORT: int = env.int("PORT", default=80) | ||
|
||
STORAGE = env.list("STORAGE", subcast=str, default=["Local"]) | ||
STORAGE_DIR = env.str("STORAGE_DIR", default="Pictures") | ||
STORAGE: List[str] = env.list("STORAGE", subcast=str, default=["Local"]) | ||
STORAGE_DIR: str = env.str("STORAGE_DIR", default="Pictures") | ||
|
||
DATABASE = env.str("DATABASE", default="Local") | ||
DATABASE: str = env.str("DATABASE", default="Local") | ||
# Nazurin data collection in database | ||
NAZURIN_DATA = "nazurin" | ||
NAZURIN_DATA: str = "nazurin" | ||
# Ignored items in image caption | ||
CAPTION_IGNORE = env.list("CAPTION_IGNORE", subcast=str, default=[]) | ||
CAPTION_IGNORE: List[str] = env.list("CAPTION_IGNORE", subcast=str, default=[]) | ||
|
||
GALLERY_ID = env.int("GALLERY_ID", default=None) | ||
GALLERY_ID: Optional[int] = env.int("GALLERY_ID", default=None) | ||
|
||
ADMIN_ID = env.int("ADMIN_ID") | ||
IS_PUBLIC = env.bool("IS_PUBLIC", default=False) | ||
ADMIN_ID: int = env.int("ADMIN_ID") | ||
IS_PUBLIC: bool = env.bool("IS_PUBLIC", default=False) | ||
# If IS_PUBLIC is True, the following items will be ignored | ||
ALLOW_ID = env.list("ALLOW_ID", subcast=int, default=[]) | ||
ALLOW_USERNAME = env.list("ALLOW_USERNAME", default=[]) | ||
ALLOW_GROUP = env.list("ALLOW_GROUP", subcast=int, default=[]) | ||
|
||
RETRIES = env.int("RETRIES", default=5) | ||
TIMEOUT = env.int("TIMEOUT", default=20) | ||
DOWNLOAD_CHUNK_SIZE = env.int("DOWNLOAD_CHUNK_SIZE", default=4096) | ||
PROXY = env.str("HTTP_PROXY", default=None) | ||
UA = ( | ||
ALLOW_ID: List[int] = env.list("ALLOW_ID", subcast=int, default=[]) | ||
ALLOW_USERNAME: List[str] = env.list("ALLOW_USERNAME", default=[]) | ||
ALLOW_GROUP: List[int] = env.list("ALLOW_GROUP", subcast=int, default=[]) | ||
|
||
RETRIES: int = env.int("RETRIES", default=5) | ||
TIMEOUT: int = env.int("TIMEOUT", default=20) | ||
DOWNLOAD_CHUNK_SIZE: int = env.int("DOWNLOAD_CHUNK_SIZE", default=4096) | ||
PROXY: str = env.str("HTTP_PROXY", default=None) | ||
UA: str = ( | ||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) " | ||
"AppleWebKit/537.36 (KHTML, like Gecko) " | ||
"Chrome/120.0.0.0 Safari/537.36" | ||
) | ||
|
||
# Local directory to store database and temporary files | ||
DATA_DIR = "data" | ||
TEMP_DIR = path.join(DATA_DIR, "temp") | ||
CLEANUP_INTERVAL = env.int("CLEANUP_INTERVAL", default=7) | ||
ACCESS_LOG_FORMAT = '%a "%r" %s %b "%{Referer}i" "%{User-Agent}i"' | ||
DATA_DIR: str = "data" | ||
TEMP_DIR: str = path.join(DATA_DIR, "temp") | ||
CLEANUP_INTERVAL: int = env.int("CLEANUP_INTERVAL", default=7) | ||
ACCESS_LOG_FORMAT: str = '%a "%r" %s %b "%{Referer}i" "%{User-Agent}i"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from dataclasses import dataclass | ||
|
||
from nazurin.models import Illust | ||
from nazurin.utils.network import CurlRequest | ||
|
||
|
||
@dataclass | ||
class DanbooruIllust(Illust): | ||
async def download(self, **kwargs): | ||
await super().download(request_class=CurlRequest, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.