fix: rebuilding posts and media fixed, also removed unnecessary thumbnail rebuild
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -196,7 +196,7 @@ defmodule BDS.MediaTest do
|
||||
thumbnail_paths = BDS.Media.thumbnail_paths(media)
|
||||
|
||||
Enum.each(Map.values(thumbnail_paths), fn path ->
|
||||
assert File.exists?(Path.join(temp_dir, path))
|
||||
refute File.exists?(Path.join(temp_dir, path))
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -240,6 +240,44 @@ defmodule BDS.MediaTest do
|
||||
assert media.updated_at == 1_773_847_870_146
|
||||
end
|
||||
|
||||
test "rebuild_media_from_files does not regenerate thumbnails", %{
|
||||
project: project,
|
||||
temp_dir: temp_dir
|
||||
} do
|
||||
media_dir = Path.join([temp_dir, "media", "2026", "04"])
|
||||
File.mkdir_p!(media_dir)
|
||||
|
||||
binary_path = Path.join(media_dir, "asset.jpg")
|
||||
sidecar_path = binary_path <> ".meta"
|
||||
|
||||
File.write!(binary_path, tiny_jpeg_binary())
|
||||
|
||||
File.write!(
|
||||
sidecar_path,
|
||||
[
|
||||
"id: media-without-thumbnails",
|
||||
"originalName: original.jpg",
|
||||
"mimeType: image/jpeg",
|
||||
"size: #{byte_size(tiny_jpeg_binary())}",
|
||||
"width: 3",
|
||||
"height: 2",
|
||||
"title: Recovered",
|
||||
"createdAt: 2024-03-30T21:20:00.000Z",
|
||||
"updatedAt: 2024-03-31T21:20:00.000Z",
|
||||
"tags:",
|
||||
" - alpha",
|
||||
""
|
||||
]
|
||||
|> Enum.join("\n")
|
||||
)
|
||||
|
||||
assert {:ok, [media]} = BDS.Media.rebuild_media_from_files(project.id)
|
||||
|
||||
Enum.each(Map.values(BDS.Media.thumbnail_paths(media)), fn path ->
|
||||
refute File.exists?(Path.join(temp_dir, path))
|
||||
end)
|
||||
end
|
||||
|
||||
test "import_media generates the four thumbnail files in bucketed thumbnail paths", %{
|
||||
project: project,
|
||||
temp_dir: temp_dir
|
||||
|
||||
@@ -429,6 +429,85 @@ defmodule BDS.PostsTest do
|
||||
assert post.published_at == 1_036_497_600_000
|
||||
end
|
||||
|
||||
test "rebuild_posts_from_files parses folded multiline title and slug scalars alongside translations" do
|
||||
temp_dir =
|
||||
Path.join(System.tmp_dir!(), "bds-post-rebuild-folded-#{System.unique_integer([:positive])}")
|
||||
|
||||
File.mkdir_p!(temp_dir)
|
||||
on_exit(fn -> File.rm_rf(temp_dir) end)
|
||||
|
||||
assert {:ok, project} =
|
||||
BDS.Projects.create_project(%{name: "Folded Rebuild", data_path: temp_dir})
|
||||
|
||||
posts_dir = Path.join([BDS.Projects.project_data_dir(project), "posts", "2010", "11"])
|
||||
File.mkdir_p!(posts_dir)
|
||||
|
||||
File.write!(
|
||||
Path.join(
|
||||
posts_dir,
|
||||
"introducing-thirty-ten-my-guide-to-creating-a-twenty-ten-child-theme-aaron-jorb-inaaron-jorb-in.md"
|
||||
),
|
||||
[
|
||||
"---",
|
||||
"id: 66865ffe-c6d9-4379-a031-0581f33b68b4",
|
||||
"title: >-",
|
||||
" Introducing Thirty Ten, my guide to creating a Twenty Ten Child Theme |",
|
||||
" aaron.jorb.inaaron.jorb.in",
|
||||
"slug: >-",
|
||||
" introducing-thirty-ten-my-guide-to-creating-a-twenty-ten-child-theme-aaron-jorb-inaaron-jorb-in",
|
||||
"status: published",
|
||||
"createdAt: '2010-11-13T12:37:55.000Z'",
|
||||
"updatedAt: '2026-03-03T12:31:37.661Z'",
|
||||
"tags:",
|
||||
" - wordpress",
|
||||
"categories:",
|
||||
" - aside",
|
||||
"author: hugo",
|
||||
"language: de",
|
||||
"publishedAt: '2010-11-13T11:37:55.000Z'",
|
||||
"---",
|
||||
"Quelle",
|
||||
""
|
||||
]
|
||||
|> Enum.join("\n")
|
||||
)
|
||||
|
||||
File.write!(
|
||||
Path.join(
|
||||
posts_dir,
|
||||
"introducing-thirty-ten-my-guide-to-creating-a-twenty-ten-child-theme-aaron-jorb-inaaron-jorb-in.en.md"
|
||||
),
|
||||
[
|
||||
"---",
|
||||
"translationFor: 66865ffe-c6d9-4379-a031-0581f33b68b4",
|
||||
"language: en",
|
||||
"title: >-",
|
||||
" Introducing Thirty Ten, my guide to creating a Twenty Ten Child Theme |",
|
||||
" aaron.jorb.inaaron.jorb.in",
|
||||
"---",
|
||||
"Translated body",
|
||||
""
|
||||
]
|
||||
|> Enum.join("\n")
|
||||
)
|
||||
|
||||
assert {:ok, [post]} = BDS.Posts.rebuild_posts_from_files(project.id)
|
||||
assert post.id == "66865ffe-c6d9-4379-a031-0581f33b68b4"
|
||||
|
||||
assert post.slug ==
|
||||
"introducing-thirty-ten-my-guide-to-creating-a-twenty-ten-child-theme-aaron-jorb-inaaron-jorb-in"
|
||||
|
||||
assert post.title ==
|
||||
"Introducing Thirty Ten, my guide to creating a Twenty Ten Child Theme | aaron.jorb.inaaron.jorb.in"
|
||||
|
||||
assert {:ok, [translation]} = BDS.Posts.list_post_translations(post.id)
|
||||
|
||||
assert translation.translation_for == post.id
|
||||
|
||||
assert translation.title ==
|
||||
"Introducing Thirty Ten, my guide to creating a Twenty Ten Child Theme | aaron.jorb.inaaron.jorb.in"
|
||||
end
|
||||
|
||||
defp errors_on(changeset) do
|
||||
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
|
||||
Regex.replace(~r"%{(\w+)}", message, fn _, key ->
|
||||
|
||||
46
test/bds/real_blog_rebuild_diagnostic_test.exs
Normal file
46
test/bds/real_blog_rebuild_diagnostic_test.exs
Normal file
@@ -0,0 +1,46 @@
|
||||
defmodule BDS.RealBlogRebuildDiagnosticTest do
|
||||
use ExUnit.Case, async: false
|
||||
|
||||
@real_blog_path System.get_env("BDS_REAL_BLOG_PATH")
|
||||
@moduletag timeout: :infinity
|
||||
|
||||
if is_binary(@real_blog_path) and @real_blog_path != "" do
|
||||
setup do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(BDS.Repo, ownership_timeout: 600_000)
|
||||
|
||||
now = BDS.Persistence.now_ms()
|
||||
unique = Integer.to_string(System.unique_integer([:positive]))
|
||||
|
||||
project =
|
||||
%BDS.Projects.Project{}
|
||||
|> BDS.Projects.Project.changeset(%{
|
||||
id: "real-blog-#{unique}",
|
||||
name: "Real Blog Diagnostic",
|
||||
slug: "real-blog-diagnostic-#{unique}",
|
||||
data_path: Path.expand(@real_blog_path),
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
is_active: false
|
||||
})
|
||||
|> BDS.Repo.insert!()
|
||||
|
||||
%{project: project}
|
||||
end
|
||||
|
||||
test "rebuilds posts from the external real blog path", %{project: project} do
|
||||
assert {:ok, _posts} = BDS.Maintenance.rebuild_from_filesystem(project.id, "post")
|
||||
end
|
||||
|
||||
test "rebuilds media from the external real blog path", %{project: project} do
|
||||
assert {:ok, _media} = BDS.Maintenance.rebuild_from_filesystem(project.id, "media")
|
||||
end
|
||||
else
|
||||
@tag skip: "BDS_REAL_BLOG_PATH not set"
|
||||
test "rebuilds posts from the external real blog path" do
|
||||
end
|
||||
|
||||
@tag skip: "BDS_REAL_BLOG_PATH not set"
|
||||
test "rebuilds media from the external real blog path" do
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user