Пример #1
0
def _sync_post_content(post: model.Post) -> None:
    regenerate_thumb = False

    if hasattr(post, '__content'):
        content = getattr(post, '__content')
        files.save(get_post_content_path(post), content)
        delattr(post, '__content')
        regenerate_thumb = True
        if post.post_id and post.type in (
                model.Post.TYPE_IMAGE, model.Post.TYPE_ANIMATION):
            image_hash.delete_image(post.post_id)
            image_hash.add_image(post.post_id, content)

    if hasattr(post, '__thumbnail'):
        if getattr(post, '__thumbnail'):
            files.save(
                get_post_thumbnail_backup_path(post),
                getattr(post, '__thumbnail'))
        else:
            files.delete(get_post_thumbnail_backup_path(post))
        delattr(post, '__thumbnail')
        regenerate_thumb = True

    if regenerate_thumb:
        generate_post_thumbnail(post)
Пример #2
0
def _sync_post_content(post: model.Post) -> None:
    regenerate_thumb = False

    if hasattr(post, '__content'):
        content = getattr(post, '__content')
        files.save(get_post_content_path(post), content)
        delattr(post, '__content')
        regenerate_thumb = True
        if post.post_id and post.type in (
                model.Post.TYPE_IMAGE, model.Post.TYPE_ANIMATION):
            image_hash.delete_image(post.post_id)
            image_hash.add_image(post.post_id, content)

    if hasattr(post, '__thumbnail'):
        if getattr(post, '__thumbnail'):
            files.save(
                get_post_thumbnail_backup_path(post),
                getattr(post, '__thumbnail'))
        else:
            files.delete(get_post_thumbnail_backup_path(post))
        delattr(post, '__thumbnail')
        regenerate_thumb = True

    if regenerate_thumb:
        generate_post_thumbnail(post)
Пример #3
0
def _before_post_delete(
        _mapper: Any, _connection: Any, post: model.Post) -> None:
    if post.post_id:
        image_hash.delete_image(post.post_id)
        if config.config['delete_source_files']:
            files.delete(get_post_content_path(post))
            files.delete(get_post_thumbnail_path(post))
Пример #4
0
def _before_post_delete(
        _mapper: Any, _connection: Any, post: model.Post) -> None:
    if post.post_id:
        image_hash.delete_image(post.post_id)
        if config.config['delete_source_files']:
            files.delete(get_post_content_path(post))
            files.delete(get_post_thumbnail_path(post))
Пример #5
0
def update_post_thumbnail(post, content=None, delete=True):
    if content is None:
        content = files.get(get_post_content_path(post))
        if delete:
            files.delete(get_post_thumbnail_backup_path(post))
    else:
        files.save(get_post_thumbnail_backup_path(post), content)
    generate_post_thumbnail(post)
Пример #6
0
def _sync_post_content(post: model.Post) -> None:
    regenerate_thumb = False

    if hasattr(post, '__content'):
        content = getattr(post, '__content')
        files.save(get_post_content_path(post), content)
        delattr(post, '__content')
        regenerate_thumb = True

    if hasattr(post, '__thumbnail'):
        if getattr(post, '__thumbnail'):
            files.save(get_post_thumbnail_backup_path(post),
                       getattr(post, '__thumbnail'))
        else:
            files.delete(get_post_thumbnail_backup_path(post))
        delattr(post, '__thumbnail')
        regenerate_thumb = True

    if regenerate_thumb:
        generate_post_thumbnail(post)
Пример #7
0
def purge_old_uploads() -> None:
    now = datetime.now()
    for file in files.scan("temporary-uploads"):
        file_time = datetime.fromtimestamp(file.stat().st_ctime)
        if now - file_time > timedelta(minutes=MAX_MINUTES):
            files.delete("temporary-uploads/%s" % file.name)
Пример #8
0
def purge_old_uploads() -> None:
    now = datetime.now()
    for file in files.scan('temporary-uploads'):
        file_time = datetime.fromtimestamp(file.stat().st_ctime)
        if now - file_time > timedelta(minutes=MAX_MINUTES):
            files.delete('temporary-uploads/%s' % file.name)
Пример #9
0
def purge_old_uploads():
    now = datetime.datetime.now()
    for file in files.scan("temporary-uploads"):
        file_time = datetime.datetime.fromtimestamp(file.stat().st_ctime)
        if now - file_time > datetime.timedelta(minutes=MAX_MINUTES):
            files.delete("temporary-uploads/%s" % file.name)