mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-08 21:07:08 +10:00
#27 Should get page title even if post is a page.
This commit is contained in:
@@ -87,7 +87,7 @@ class Api::V1::PostsController < Api::V1::ApplicationController
|
||||
end
|
||||
|
||||
def process_post
|
||||
if !@post.processed && @post.type != 'WebPage'
|
||||
if !@post.processed
|
||||
ProcessPostWorker.perform_async @post.url
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,14 +13,13 @@ class ProcessPostWorker
|
||||
if page.images.best.present?
|
||||
post.create_thumbnail file: URI.parse(page.images.best)
|
||||
end
|
||||
post.save
|
||||
rescue SocketError => e
|
||||
Rails.logger.error "出错了: #{e}"
|
||||
ensure
|
||||
readability_extract_content post
|
||||
end
|
||||
|
||||
post.save
|
||||
readability_extract_content post
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
@@ -31,8 +30,9 @@ class ProcessPostWorker
|
||||
response = RestClient.get "https://readability.com/api/content/v1/parser?token=#{token}&url=#{post.url}"
|
||||
if response.code == 200
|
||||
post_json = JSON.parse response.body
|
||||
|
||||
post.content = HTMLEntities.new.decode post_json['content']
|
||||
post.good_format = true
|
||||
post.good_format = true if post.type != 'WebPage'
|
||||
post.title = post_json['title']
|
||||
post.save
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user