mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-08 21:07:08 +10:00
#37 check if url is valid
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class Api::V1::PostsController < Api::V1::ApplicationController
|
||||
|
||||
before_action :permit_params, :map_post_type, :get_post, only: [:create]
|
||||
before_action :permit_params, :check_url, :map_post_type, :get_post, only: [:create]
|
||||
before_action :load_post, only: [:add_viewed_times, :show]
|
||||
|
||||
skip_before_action :authenticate_user_from_token, only: [:posts, :show, :liked_posts, :bookmarked_posts]
|
||||
@@ -57,7 +57,7 @@ class Api::V1::PostsController < Api::V1::ApplicationController
|
||||
|
||||
def search
|
||||
params.permit(:keywords)
|
||||
render json: Post.where('title LIKE ?',"%#{params[:keywords]}%").page(params[:page]), each_serializer: EachPostSerializer
|
||||
render json: Post.where('title LIKE ?', "%#{params[:keywords]}%").page(params[:page]), each_serializer: EachPostSerializer
|
||||
end
|
||||
|
||||
private
|
||||
@@ -86,8 +86,18 @@ class Api::V1::PostsController < Api::V1::ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def check_url
|
||||
begin
|
||||
uri = URI.parse params[:url]
|
||||
res = uri.kind_of?(URI::HTTP)
|
||||
rescue URI::InvalidURIError
|
||||
res = false
|
||||
end
|
||||
return render json: {msg: 'URL不合法, 请重新输入'}, status: 400 unless res
|
||||
end
|
||||
|
||||
def process_post
|
||||
if !@post.processed
|
||||
if !@post.processed
|
||||
ProcessPostWorker.perform_async @post.url
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user