2022-05-03 20:53:32 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class PostHotlinkedMedia < ActiveRecord::Base
|
|
|
|
belongs_to :post
|
|
|
|
belongs_to :upload
|
|
|
|
enum status: {
|
|
|
|
downloaded: "downloaded",
|
|
|
|
too_large: "too_large",
|
|
|
|
download_failed: "download_failed",
|
|
|
|
upload_create_failed: "upload_create_failed",
|
|
|
|
}
|
2022-05-13 21:11:45 +08:00
|
|
|
|
2023-06-20 09:49:22 +08:00
|
|
|
def self.normalize_src(src, reset_scheme: true)
|
2022-05-13 21:11:45 +08:00
|
|
|
uri = Addressable::URI.heuristic_parse(src)
|
|
|
|
uri.normalize!
|
2023-06-20 09:49:22 +08:00
|
|
|
uri.scheme = nil if reset_scheme
|
2022-05-13 21:11:45 +08:00
|
|
|
uri.to_s
|
|
|
|
rescue URI::Error, Addressable::URI::InvalidURIError
|
|
|
|
src
|
|
|
|
end
|
2022-05-03 20:53:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: post_hotlinked_media
|
|
|
|
#
|
|
|
|
# id :bigint not null, primary key
|
|
|
|
# post_id :bigint not null
|
|
|
|
# url :string not null
|
|
|
|
# status :enum not null
|
|
|
|
# upload_id :bigint
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
2022-05-03 22:47:58 +08:00
|
|
|
# index_post_hotlinked_media_on_post_id_and_url_md5 (post_id, md5((url)::text)) UNIQUE
|
2022-05-03 20:53:32 +08:00
|
|
|
#
|