implement post metadata import and views. implemented series paging and reader view.
This commit is contained in:
+49
-3
@@ -10,7 +10,7 @@ from datetime import datetime
|
||||
|
||||
from app.celery_app import celery
|
||||
from app import db
|
||||
from app.models import ImageRecord, Tag
|
||||
from app.models import ImageRecord, Tag, PostMetadata
|
||||
|
||||
log = logging.getLogger('celery.tasks.sidecar')
|
||||
|
||||
@@ -53,6 +53,7 @@ def apply_sidecar_metadata(self, image_id: int, sidecar_path: str):
|
||||
return {'status': 'no_metadata', 'reason': 'No metadata extracted'}
|
||||
|
||||
tags_added = 0
|
||||
post_tag = None # Track the post tag for PostMetadata
|
||||
|
||||
# Update date if earlier
|
||||
new_date = resolve_date_conflict(record.taken_at, enriched.get('taken_at'))
|
||||
@@ -78,17 +79,62 @@ def apply_sidecar_metadata(self, image_id: int, sidecar_path: str):
|
||||
record.tags.append(tag)
|
||||
tags_added += 1
|
||||
|
||||
# Track the post tag for PostMetadata creation
|
||||
if tag_kind == 'post':
|
||||
post_tag = tag
|
||||
|
||||
# Create or update PostMetadata for post tags
|
||||
post_metadata_created = False
|
||||
if post_tag and enriched.get('platform') and enriched.get('post_id'):
|
||||
existing_pm = PostMetadata.query.filter_by(tag_id=post_tag.id).first()
|
||||
if not existing_pm:
|
||||
# Create new PostMetadata record
|
||||
pm = PostMetadata(
|
||||
tag_id=post_tag.id,
|
||||
platform=enriched.get('platform'),
|
||||
post_id=enriched.get('post_id'),
|
||||
artist=enriched.get('artist'),
|
||||
title=enriched.get('post_title'),
|
||||
description=enriched.get('description'),
|
||||
source_url=enriched.get('source_url'),
|
||||
attachment_count=enriched.get('attachment_count', 0),
|
||||
published_at=enriched.get('taken_at'),
|
||||
)
|
||||
db.session.add(pm)
|
||||
post_metadata_created = True
|
||||
log.debug(f"Created PostMetadata for tag {post_tag.name}")
|
||||
else:
|
||||
# Update existing PostMetadata if it has missing fields
|
||||
updated = False
|
||||
if not existing_pm.title and enriched.get('post_title'):
|
||||
existing_pm.title = enriched.get('post_title')
|
||||
updated = True
|
||||
if not existing_pm.description and enriched.get('description'):
|
||||
existing_pm.description = enriched.get('description')
|
||||
updated = True
|
||||
if not existing_pm.source_url and enriched.get('source_url'):
|
||||
existing_pm.source_url = enriched.get('source_url')
|
||||
updated = True
|
||||
# Always update attachment count to get accurate count
|
||||
if enriched.get('attachment_count', 0) > existing_pm.attachment_count:
|
||||
existing_pm.attachment_count = enriched.get('attachment_count', 0)
|
||||
updated = True
|
||||
if updated:
|
||||
log.debug(f"Updated PostMetadata for tag {post_tag.name}")
|
||||
|
||||
db.session.commit()
|
||||
|
||||
log.info(f"Applied sidecar metadata to {image_id}: "
|
||||
f"platform={enriched.get('platform')}, tags_added={tags_added}")
|
||||
f"platform={enriched.get('platform')}, tags_added={tags_added}, "
|
||||
f"post_metadata_created={post_metadata_created}")
|
||||
|
||||
return {
|
||||
'status': 'applied',
|
||||
'platform': enriched.get('platform'),
|
||||
'artist': enriched.get('artist'),
|
||||
'post_id': enriched.get('post_id'),
|
||||
'tags_added': tags_added
|
||||
'tags_added': tags_added,
|
||||
'post_metadata_created': post_metadata_created
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user