2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-08-28 15:09:36 -04:00
|
|
|
class PermalinksController < ApplicationController
|
2020-03-05 20:33:25 -05:00
|
|
|
skip_before_action :check_xhr, :preload_json, only: [:show]
|
2014-08-28 15:09:36 -04:00
|
|
|
|
|
|
|
def show
|
2015-07-21 23:40:45 -04:00
|
|
|
url = request.fullpath
|
2015-04-23 16:45:28 -04:00
|
|
|
|
2014-09-10 13:58:52 -04:00
|
|
|
permalink = Permalink.find_by_url(url)
|
2015-04-23 16:45:28 -04:00
|
|
|
|
|
|
|
raise Discourse::NotFound unless permalink
|
|
|
|
|
2018-08-19 23:10:49 -04:00
|
|
|
if permalink.target_url
|
2024-06-27 09:09:16 -04:00
|
|
|
redirect_to permalink.target_url, status: :moved_permanently, allow_other_host: true
|
2014-08-28 15:09:36 -04:00
|
|
|
else
|
|
|
|
raise Discourse::NotFound
|
|
|
|
end
|
|
|
|
end
|
2015-04-23 16:45:28 -04:00
|
|
|
|
2020-03-05 20:33:25 -05: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
|
|
|
|
data = { found: false, html: build_not_found_page(status: 200) }
|
|
|
|
render json: MultiJson.dump(data)
|
|
|
|
end
|
|
|
|
end
|
2014-08-28 15:09:36 -04:00
|
|
|
end
|