Skip to content

Commit

Permalink
Reuse gather_valid_files in thumbnail generation
Browse files Browse the repository at this point in the history
  • Loading branch information
hv0905 committed Dec 29, 2023
1 parent f669b83 commit 4966194
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions scripts/local_create_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from app.Services.provider import db_context
from app.config import config
from .local_utility import gather_valid_files


async def main():
Expand All @@ -14,17 +15,14 @@ async def main():
if not static_thumb_path.exists():
static_thumb_path.mkdir()
count = 0
for item in static_path.glob('*.*'):
for item in gather_valid_files(static_path, '*.*'):
count += 1
logger.info("[{}] Processing {}", str(count), str(item.relative_to(static_path)))
size = item.stat().st_size
if size < 1024 * 500:
logger.warning("File size too small: {}. Skip...", size)
continue
try:
if item.suffix not in ['.jpg', '.png', '.jpeg']:
logger.warning("Unsupported file type: {}. Skip...", item.suffix)
continue
if (static_thumb_path / f'{item.stem}.webp').exists():
logger.warning("Thumbnail for {} already exists. Skip...", item.stem)
continue
Expand Down
4 changes: 2 additions & 2 deletions scripts/local_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from loguru import logger


def gather_valid_files(root: Path):
for item in root.glob('**/*.*'):
def gather_valid_files(root: Path, pattern: str = '**/*.*'):
for item in root.glob(pattern):
if item.suffix in ['.jpg', '.png', '.jpeg', '.jfif', '.webp', '.gif']:
yield item
else:
Expand Down

0 comments on commit 4966194

Please sign in to comment.