mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-02 23:57:59 +01:00
78 lines
2.4 KiB
Elixir
78 lines
2.4 KiB
Elixir
defmodule Philomena.Processors do
|
|
@moduledoc """
|
|
Utilities for processing uploads.
|
|
|
|
Processors have 3 methods available:
|
|
|
|
- process/3:
|
|
Takes an analysis, file path, and version list and generates an
|
|
"edit script" that represents how to store this file according to the
|
|
given version list. See Philomena.Images.Thumbnailer for more
|
|
information on how this works.
|
|
|
|
- post_process/2:
|
|
Takes an analysis and file path and performs optimizations on the
|
|
upload. See Philomena.Images.Thumbnailer for more information on how this
|
|
works.
|
|
|
|
- intensities/2:
|
|
Takes an analysis and file path and generates an intensities map
|
|
appropriate for use by Philomena.DuplicateReports.
|
|
"""
|
|
|
|
alias Philomena.Processors.Gif
|
|
alias Philomena.Processors.Jpeg
|
|
alias Philomena.Processors.Png
|
|
alias Philomena.Processors.Svg
|
|
alias Philomena.Processors.Webm
|
|
|
|
@doc """
|
|
Returns a processor, with the processor being a module capable
|
|
of processing this content type, or nil.
|
|
"""
|
|
@spec processor(String.t()) :: module() | nil
|
|
def processor(content_type)
|
|
|
|
def processor("image/gif"), do: Gif
|
|
def processor("image/jpeg"), do: Jpeg
|
|
def processor("image/png"), do: Png
|
|
def processor("image/svg+xml"), do: Svg
|
|
def processor("video/webm"), do: Webm
|
|
def processor(_content_type), do: nil
|
|
|
|
@doc """
|
|
Takes a MIME type and version list and generates a list of versions to be
|
|
generated (e.g., ["thumb.png"]). List contents differ based on file type.
|
|
"""
|
|
@spec versions(String.t(), keyword) :: [String.t()]
|
|
def versions(mime_type, valid_sizes) do
|
|
processor(mime_type).versions(valid_sizes)
|
|
end
|
|
|
|
@doc """
|
|
Takes an analyzer, file path, and version list and runs the appropriate
|
|
processor's process/3.
|
|
"""
|
|
@spec process(map(), String.t(), keyword) :: map()
|
|
def process(analysis, file, versions) do
|
|
processor(analysis.mime_type).process(analysis, file, versions)
|
|
end
|
|
|
|
@doc """
|
|
Takes an analyzer and file path and runs the appropriate processor's
|
|
post_process/2.
|
|
"""
|
|
@spec post_process(map(), String.t()) :: map()
|
|
def post_process(analysis, file) do
|
|
processor(analysis.mime_type).post_process(analysis, file)
|
|
end
|
|
|
|
@doc """
|
|
Takes an analyzer and file path and runs the appropriate processor's
|
|
intensities/2.
|
|
"""
|
|
@spec intensities(map(), String.t()) :: map()
|
|
def intensities(analysis, file) do
|
|
processor(analysis.mime_type).intensities(analysis, file)
|
|
end
|
|
end
|