2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-08-28 14:09:36 -05:00
|
|
|
class PermalinksController < ApplicationController
|
2020-03-05 19:33:25 -06:00
|
|
|
skip_before_action :check_xhr, :preload_json, only: [:show]
|
2014-08-28 14:09:36 -05:00
|
|
|
|
|
|
|
def show
|
2015-07-21 22:40:45 -05:00
|
|
|
url = request.fullpath
|
2015-04-23 15:45:28 -05:00
|
|
|
|
2014-09-10 12:58:52 -05:00
|
|
|
permalink = Permalink.find_by_url(url)
|
2015-04-23 15:45:28 -05:00
|
|
|
|
|
|
|
raise Discourse::NotFound unless permalink
|
|
|
|
|
2018-08-19 22:10:49 -05:00
|
|
|
if permalink.target_url
|
2015-10-12 15:48:32 -05:00
|
|
|
redirect_to permalink.target_url, status: :moved_permanently
|
2014-08-28 14:09:36 -05:00
|
|
|
else
|
|
|
|
raise Discourse::NotFound
|
|
|
|
end
|
|
|
|
end
|
2015-04-23 15:45:28 -05:00
|
|
|
|
2020-03-05 19:33:25 -06:00
|
|
|
def check
|
|
|
|
begin
|
|
|
|
raise Discourse::NotFound if params[:path].blank?
|
|
|
|
|
|
|
|
permalink = Permalink.find_by_url(params[:path])
|
|
|
|
|
|
|
|
raise Discourse::NotFound unless permalink
|
|
|
|
|
|
|
|
data = {
|
|
|
|
found: true,
|
|
|
|
internal: permalink.external_url.nil?,
|
|
|
|
target_url: permalink.target_url,
|
|
|
|
}
|
|
|
|
|
|
|
|
render json: MultiJson.dump(data)
|
|
|
|
rescue Discourse::NotFound
|
2023-01-09 06:20:10 -06:00
|
|
|
data = { found: false, html: build_not_found_page(status: 200) }
|
2020-03-05 19:33:25 -06:00
|
|
|
render json: MultiJson.dump(data)
|
|
|
|
end
|
|
|
|
end
|
2014-08-28 14:09:36 -05:00
|
|
|
end
|