From 12ec43f09887ca1682c6d02557336f3f45c7ba30 Mon Sep 17 00:00:00 2001 From: ReAnzu Date: Thu, 8 Mar 2018 00:47:58 -0600 Subject: server/posts: auto convert GIFs to WEBMs/MP4s - Default setting is false for both conversions, as this will require additional resources of the server, but is bandwidth friendly for viewers - WEBM conversion is slow, but better quality than MP4 conversion with a typically smaller file size - Tags are copied over from the original upload - Snapshots are generated for the new auto posts --- server/szurubooru/api/post_api.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'server/szurubooru/api/post_api.py') diff --git a/server/szurubooru/api/post_api.py b/server/szurubooru/api/post_api.py index 27f10c1..aaa7437 100644 --- a/server/szurubooru/api/post_api.py +++ b/server/szurubooru/api/post_api.py @@ -1,4 +1,4 @@ -from typing import Optional, Dict +from typing import Optional, Dict, List from datetime import datetime from szurubooru import db, model, errors, rest, search from szurubooru.func import ( @@ -69,13 +69,26 @@ def create_post( posts.update_post_thumbnail(post, ctx.get_file('thumbnail')) ctx.session.add(post) ctx.session.flush() - snapshots.create(post, None if anonymous else ctx.user) - for tag in new_tags: - snapshots.create(tag, None if anonymous else ctx.user) + create_snapshots_for_post(post, new_tags, None if anonymous else ctx.user) + alternate_format_posts = posts.generate_alternate_formats(post, content) + for alternate_post, alternate_post_new_tags in alternate_format_posts: + create_snapshots_for_post( + alternate_post, + alternate_post_new_tags, + None if anonymous else ctx.user) ctx.session.commit() return _serialize_post(ctx, post) +def create_snapshots_for_post( + post: model.Post, + new_tags: List[model.Tag], + user: Optional[model.User]): + snapshots.create(post, user) + for tag in new_tags: + snapshots.create(tag, user) + + @rest.routes.get('/post/(?P[^/]+)/?') def get_post(ctx: rest.Context, params: Dict[str, str]) -> rest.Response: auth.verify_privilege(ctx.user, 'posts:view') -- cgit v1.3