Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cleanup Screenshot URL Handling
  • Loading branch information
symkat committed Nov 24, 2021
1 parent 68ce9c6 commit 4d75ac0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
15 changes: 5 additions & 10 deletions Web/lib/BlogDB/Web/Controller/Blog.pm
Expand Up @@ -63,8 +63,6 @@ sub get_new_blogs ($c) {
}

sub post_new_blog ($c) {


$c->set_template( 'index' );

my $blog_url = $c->stash->{form_url} = $c->param('url');
Expand All @@ -91,10 +89,10 @@ sub post_new_blog ($c) {
),
});

$c->minion->enqueue( download_screenshot => [ $blog->url, $blog->id ] );
$c->minion->enqueue( populate_blog_entires => [ $blog->id, 'pending' ]);
$c->minion->enqueue( populate_blog_screenshot => [ $blog->id, 'pending' ]);


#$c->redirect_to( $c->url_for( 'do_blog_edit', id => $blog->id, title => 'new' ) );
$c->redirect_to( $c->url_for( 'edit_new_blog', id => $blog->id ) );
}

sub get_edit_new_blog ($c) {
Expand All @@ -108,7 +106,6 @@ sub get_edit_new_blog ($c) {

$c->stash->{form_title} = $blog->title;
$c->stash->{form_url} = $blog->url;
$c->stash->{form_img_url} = $blog->img_url;
$c->stash->{form_rss_url} = $blog->rss_url;
$c->stash->{form_tagline} = $blog->tagline;
$c->stash->{form_about} = $blog->about;
Expand Down Expand Up @@ -136,15 +133,13 @@ sub post_edit_new_blog ($c) {
# such permissions as allows editing it.
$c->stash->{form_title} = $c->param("title");
$c->stash->{form_url} = $c->param("url");
$c->stash->{form_img_url} = $c->param("img_url");
$c->stash->{form_rss_url} = $c->param("rss_url");
$c->stash->{form_tagline} = $c->param("tagline");
$c->stash->{form_about} = $c->param("about");
$c->stash->{form_adult} = $c->param("is_adult") ? 1 : 0;

$blog->title ( $c->stash->{form_title} );
$blog->url ( $c->stash->{form_url} );
$blog->img_url ( $c->stash->{form_img_url} );
$blog->rss_url ( $c->stash->{form_rss_url} );
$blog->tagline ( $c->stash->{form_tagline} );
$blog->about ( $c->stash->{form_about} );
Expand Down Expand Up @@ -187,8 +182,8 @@ sub post_publish_new_blog ($c) {
}
$pb->delete;

$c->minion->enqueue( populate_blog_entires => [ $blog->id ]);
$c->minion->enqueue( populate_blog_screenshot => [ $blog->id ]);
$c->minion->enqueue( populate_blog_entires => [ $blog->id, 'prod' ]);
$c->minion->enqueue( populate_blog_screenshot => [ $blog->id, 'prod' ]);

$c->redirect_to( $c->url_for( 'view_blog', slug => $blog->slug ) );
}
Expand Down
25 changes: 11 additions & 14 deletions Web/lib/BlogDB/Web/Plugin/MinionTasks.pm
Expand Up @@ -48,15 +48,9 @@ sub register ( $self, $app, $config ) {
return [ @items ];
});

$app->minion->add_task(download_screenshot => sub ( $job, $blog_url, $blog_id ) {
$screenshot->store_screenshot(
url => $blog_url,
out_file => $job->app->config->{ws_screenshot}->{datadir} . "$blog_id.jpg",
);
});

$app->minion->add_task(populate_blog_screenshot => sub ( $job, $blog_id ) {
my $blog = $job->app->db->resultset('Blog')->find( $blog_id );
$app->minion->add_task(populate_blog_screenshot => sub ( $job, $blog_id, $type ) {
my $rs1 = $type eq 'pending' ? 'PendingBlog' : 'Blog';
my $blog = $job->app->db->resultset($rs1)->find( $blog_id );

make_path( $job->app->static->paths->[0] . '/screenshots/' );
my $out = tempfile(
Expand All @@ -74,27 +68,30 @@ sub register ( $self, $app, $config ) {
$blog->update;
});

$app->minion->add_task(populate_blog_entires => sub ( $job, $blog_id ) {
my $blog = $job->app->db->resultset('Blog')->find( $blog_id );
$app->minion->add_task(populate_blog_entires => sub ( $job, $blog_id, $type ) {
my $rs1 = $type eq 'pending' ? 'PendingBlog' : 'Blog';
my $rs2 = $type eq 'pending' ? 'PendingBlogEntry' : 'BlogEntry';
my $rs3 = $type eq 'pending' ? 'pending_blog_entries' : 'blog_entries';

my $blog = $job->app->db->resultset($rs1)->find( $blog_id );

return unless $blog->rss_url;

my $entries = $job->app->extract_feed( $blog->rss_url );

foreach my $entry ( @{$entries} ) {
my $entry_count = $job->app->db->resultset('BlogEntry')->search({
my $entry_count = $job->app->db->resultset($rs2)->search({
url => $entry->{link},
})->count;

next if $entry_count >= 1;

$blog->create_related( 'blog_entries', {
$blog->create_related( $rs3, {
title => $entry->{title},
url => $entry->{link},
publish_date => $entry->{date},
});
}

});
}

Expand Down
8 changes: 1 addition & 7 deletions Web/templates/default/blog/new/item.html.tx
Expand Up @@ -72,12 +72,6 @@
%% value => $form_url,
%% };

%% include 'default/_/form/input.tx' { type => 'text', name => 'img_url',
%% title => 'Homepage Image URL',
%% help => 'A URL to a screenshot of the homepage.',
%% value => $form_img_url,
%% };

%% include 'default/_/form/input.tx' { type => 'text', name => 'rss_url',
%% title => 'RSS URL',
%% help => 'A URL to an RSS feed for the blog.',
Expand All @@ -89,7 +83,7 @@
</form>
</div>
<div class="col">
<img width="80%" src="/blog_screenshots/[% $blog_id %].jpg">
<img width="80%" src="[% $blog_obj.img_url %]">
</div>
</div>

Expand Down

0 comments on commit 4d75ac0

Please sign in to comment.