Added column and UI to prevent automatic deletion
This commit is contained in:
parent
86fa3a11dd
commit
1931fc0bda
7 changed files with 48 additions and 1 deletions
|
|
@ -22,7 +22,6 @@ defmodule Pinchflat.Media do
|
||||||
Repo.all(MediaItem)
|
Repo.all(MediaItem)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: add attr for excluding media items from this list (ie: keep forever)
|
|
||||||
@doc """
|
@doc """
|
||||||
Returns a list of media_items that are cullable based on the retention period
|
Returns a list of media_items that are cullable based on the retention period
|
||||||
of the source they belong to.
|
of the source they belong to.
|
||||||
|
|
@ -34,6 +33,7 @@ defmodule Pinchflat.Media do
|
||||||
|> MediaQuery.join_sources()
|
|> MediaQuery.join_sources()
|
||||||
|> MediaQuery.with_media_filepath()
|
|> MediaQuery.with_media_filepath()
|
||||||
|> MediaQuery.with_passed_retention_period()
|
|> MediaQuery.with_passed_retention_period()
|
||||||
|
|> MediaQuery.with_no_culling_prevention()
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ defmodule Pinchflat.Media.MediaItem do
|
||||||
:nfo_filepath,
|
:nfo_filepath,
|
||||||
# These are user or system controlled fields
|
# These are user or system controlled fields
|
||||||
:prevent_download,
|
:prevent_download,
|
||||||
|
:prevent_culling,
|
||||||
:culled_at
|
:culled_at
|
||||||
]
|
]
|
||||||
# Pretty much all the fields captured at index are required.
|
# Pretty much all the fields captured at index are required.
|
||||||
|
|
@ -74,6 +75,7 @@ defmodule Pinchflat.Media.MediaItem do
|
||||||
field :subtitle_filepaths, {:array, {:array, :string}}, default: []
|
field :subtitle_filepaths, {:array, {:array, :string}}, default: []
|
||||||
|
|
||||||
field :prevent_download, :boolean, default: false
|
field :prevent_download, :boolean, default: false
|
||||||
|
field :prevent_culling, :boolean, default: false
|
||||||
field :culled_at, :utc_datetime
|
field :culled_at, :utc_datetime
|
||||||
|
|
||||||
field :matching_search_term, :string, virtual: true
|
field :matching_search_term, :string, virtual: true
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,10 @@ defmodule Pinchflat.Media.MediaQuery do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_no_culling_prevention(query) do
|
||||||
|
where(query, [mi], mi.prevent_culling == false)
|
||||||
|
end
|
||||||
|
|
||||||
def with_id(query, id) do
|
def with_id(query, id) do
|
||||||
where(query, [mi], mi.id == ^id)
|
where(query, [mi], mi.id == ^id)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,12 @@
|
||||||
help="Checking excludes this media item from being downloaded"
|
help="Checking excludes this media item from being downloaded"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<.input
|
||||||
|
field={f[:prevent_culling]}
|
||||||
|
type="toggle"
|
||||||
|
label="Prevent Automatic Deletion"
|
||||||
|
help="Checking excludes media from being automatically deleted based on media retention rules"
|
||||||
|
/>
|
||||||
|
|
||||||
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto" rounding="rounded-lg">Save Media Item</.button>
|
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto" rounding="rounded-lg">Save Media Item</.button>
|
||||||
</.simple_form>
|
</.simple_form>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ defmodule Pinchflat.Repo.Migrations.AddCulledAtToMediaItems do
|
||||||
def change do
|
def change do
|
||||||
alter table(:media_items) do
|
alter table(:media_items) do
|
||||||
add :culled_at, :utc_datetime
|
add :culled_at, :utc_datetime
|
||||||
|
add :prevent_culling, :boolean, default: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ defmodule Pinchflat.Downloading.MediaRetentionWorkerTest do
|
||||||
import Pinchflat.MediaFixtures
|
import Pinchflat.MediaFixtures
|
||||||
import Pinchflat.SourcesFixtures
|
import Pinchflat.SourcesFixtures
|
||||||
|
|
||||||
|
alias Pinchflat.Media
|
||||||
alias Pinchflat.Downloading.MediaRetentionWorker
|
alias Pinchflat.Downloading.MediaRetentionWorker
|
||||||
|
|
||||||
describe "perform/1" do
|
describe "perform/1" do
|
||||||
|
|
@ -36,6 +37,17 @@ defmodule Pinchflat.Downloading.MediaRetentionWorkerTest do
|
||||||
assert Repo.reload!(old_media_item).culled_at
|
assert Repo.reload!(old_media_item).culled_at
|
||||||
assert DateTime.diff(now(), Repo.reload!(old_media_item).culled_at) < 1
|
assert DateTime.diff(now(), Repo.reload!(old_media_item).culled_at) < 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "doesn't cull media items that have prevent_culling set" do
|
||||||
|
{_source, old_media_item, _new_media_item} = prepare_records()
|
||||||
|
|
||||||
|
Media.update_media_item(old_media_item, %{prevent_culling: true})
|
||||||
|
|
||||||
|
perform_job(MediaRetentionWorker, %{})
|
||||||
|
|
||||||
|
assert File.exists?(old_media_item.media_filepath)
|
||||||
|
assert Repo.reload!(old_media_item).media_filepath
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp prepare_records do
|
defp prepare_records do
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,27 @@ defmodule Pinchflat.MediaTest do
|
||||||
|
|
||||||
assert Media.list_cullable_media_items() == [expected_media_item]
|
assert Media.list_cullable_media_items() == [expected_media_item]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "doesn't return items that are set to prevent culling" do
|
||||||
|
source = source_fixture(%{retention_period_days: 2})
|
||||||
|
|
||||||
|
_media_item =
|
||||||
|
media_item_fixture(%{
|
||||||
|
source_id: source.id,
|
||||||
|
media_filepath: "/video/#{Faker.File.file_name(:video)}",
|
||||||
|
media_downloaded_at: now_minus(3, :days),
|
||||||
|
prevent_culling: true
|
||||||
|
})
|
||||||
|
|
||||||
|
expected_media_item =
|
||||||
|
media_item_fixture(%{
|
||||||
|
source_id: source.id,
|
||||||
|
media_filepath: "/video/#{Faker.File.file_name(:video)}",
|
||||||
|
media_downloaded_at: now_minus(3, :days)
|
||||||
|
})
|
||||||
|
|
||||||
|
assert Media.list_cullable_media_items() == [expected_media_item]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "list_pending_media_items_for/1" do
|
describe "list_pending_media_items_for/1" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue