parse posted_at from fa static file url

This commit is contained in:
Dylan Knutson
2025-07-24 17:17:42 +00:00
parent 457a4e4609
commit af4d84ccb1
6 changed files with 150 additions and 4 deletions

View File

@@ -0,0 +1,38 @@
# typed: false
require "rails_helper"
RSpec.describe FaUriHelper do
describe "#parse_fa_media_url" do
it "parses a media URL with same timestamps" do
url =
"https://d.furaffinity.net/art/zzreg/1740700581/1740700581.zzreg_stippling-crop.jpg"
parsed = described_class.parse_fa_media_url(url)
expect(parsed).to eq(
FaUriHelper::FaMediaUrlInfo.new(
url_name: "zzreg",
original_file_posted: 1_740_700_581,
latest_file_posted: 1_740_700_581,
filename: "zzreg_stippling-crop.jpg",
),
)
expect(parsed.original_file_posted_at).to eq(Time.at(1_740_700_581))
expect(parsed.latest_file_posted_at).to eq(Time.at(1_740_700_581))
end
it "parses a media URL with different timestamps" do
url =
"https://d.furaffinity.net/art/zzreg/1753374875/1740700581.zzreg_stippling-crop.jpg"
parsed = described_class.parse_fa_media_url(url)
expect(parsed).to eq(
FaUriHelper::FaMediaUrlInfo.new(
url_name: "zzreg",
original_file_posted: 1_740_700_581,
latest_file_posted: 1_753_374_875,
filename: "zzreg_stippling-crop.jpg",
),
)
expect(parsed.original_file_posted_at).to eq(Time.at(1_740_700_581))
expect(parsed.latest_file_posted_at).to eq(Time.at(1_753_374_875))
end
end
end

View File

@@ -48,6 +48,53 @@ RSpec.describe Domain::Post::FaPost do
end
end
describe "posted_at" do
let(:post_url_str) do
"https://d.furaffinity.net/art/zzreg/1740700581/1740700581.zzreg_stippling-crop.jpg"
end
let(:post) { create(:domain_post_fa_post, posted_at: 1.day.ago) }
let(:post_file) do
create(:domain_post_file, post: post, url_str: post_url_str)
end
it "can be extracted from file uri if no explicit posted_at is set" do
post_file # ensure the file is created
post.posted_at = nil
post.save!
post.reload
expect(post.posted_at).to eq(Time.at(1_740_700_581))
end
it "uses the existing posted_at if it is set" do
post_file # ensure the file is created
expect(post.posted_at).to be_within(10.seconds).of(1.day.ago)
end
it "guesses it from the submission log entry if all else fails" do
# do not create the post file
post.posted_at = nil
post.last_submission_log_entry =
create(
:http_log_entry,
response:
create(
:blob_file,
contents:
File.read(
Rails.root.join(
"test/fixtures/files/domain/fa/submission/submission_page_59723907.html",
),
),
),
)
post.save!
post.reload
expect(post.posted_at).to be_within(1.minute).of(
Time.parse("Feb 1, 2025 07:15 AM PST"),
)
end
end
describe "attributes" do
let(:post) { build(:domain_post_fa_post) }
let(:time) { Time.now }