-module(kitazith@internal@validation@attachment). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/kitazith/internal/validation/attachment.gleam"). -export([attachment_filenames/1, validate_attachments/2, attachment_reference_filename/1, validate_attachment_reference/3]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC(false). -file("src/kitazith/internal/validation/attachment.gleam", 10). ?DOC(false). -spec attachment_filenames(list(kitazith@attachment:attachment())) -> list(binary()). attachment_filenames(Attachments) -> _pipe = Attachments, gleam@list:map(_pipe, fun(Attachment) -> erlang:element(3, Attachment) end). -file("src/kitazith/internal/validation/attachment.gleam", 95). ?DOC(false). -spec duplicate_attachment_filename_errors( binary(), list(kitazith@attachment:attachment()) ) -> list(kitazith@validation:validation_error()). duplicate_attachment_filename_errors(Path, Attachments) -> _pipe = Attachments, _pipe@1 = gleam@list:index_map( _pipe, fun(Attachment, Index) -> {occurrence, erlang:element(3, Attachment), Index} end ), _pipe@2 = kitazith@internal@validation@duplicate:find(_pipe@1), gleam@list:map( _pipe@2, fun(Duplicate) -> kitazith@internal@validation@common:error( Path, {duplicate_attachment_filename, erlang:element(2, Duplicate), erlang:element(3, Duplicate)} ) end ). -file("src/kitazith/internal/validation/attachment.gleam", 16). ?DOC(false). -spec validate_attachments(binary(), list(kitazith@attachment:attachment())) -> list(kitazith@validation:validation_error()). validate_attachments(Path, Attachments) -> lists:append( [begin _pipe = Attachments, _pipe@1 = gleam@list:index_map( _pipe, fun(Attachment, Index) -> case erlang:element(4, Attachment) of {some, Description} -> kitazith@internal@validation@common:validate_string_length( kitazith@internal@validation@common:join_path( kitazith@internal@validation@common:indexed_path( Path, Index ), <<"description"/utf8>> ), Description, 1, 1024 ); none -> [] end end ), lists:append(_pipe@1) end, duplicate_attachment_filename_errors(Path, Attachments)] ). -file("src/kitazith/internal/validation/attachment.gleam", 88). ?DOC(false). -spec contains_string(list(binary()), binary()) -> boolean(). contains_string(Items, Target) -> case Items of [] -> false; [Item | Rest] -> (Item =:= Target) orelse contains_string(Rest, Target) end. -file("src/kitazith/internal/validation/attachment.gleam", 73). ?DOC(false). -spec attachment_reference_filename(binary()) -> gleam@option:option(binary()). attachment_reference_filename(Url) -> Prefix = <<"attachment://"/utf8>>, case gleam_stdlib:string_starts_with(Url, Prefix) of true -> {some, gleam@string:slice( Url, string:length(Prefix), string:length(Url) - string:length(Prefix) )}; false -> none end. -file("src/kitazith/internal/validation/attachment.gleam", 40). ?DOC(false). -spec validate_attachment_reference( binary(), binary(), gleam@option:option(list(binary())) ) -> list(kitazith@validation:validation_error()). validate_attachment_reference(Path, Url, Attachment_filenames) -> case attachment_reference_filename(Url) of {some, Filename} -> case Filename =:= <<""/utf8>> of true -> [kitazith@internal@validation@common:error( Path, attachment_reference_missing_filename )]; false -> case Attachment_filenames of {some, Attachment_filenames@1} -> case contains_string( Attachment_filenames@1, Filename ) of true -> []; false -> [kitazith@internal@validation@common:error( Path, {missing_attachment_reference, Filename} )] end; none -> [] end end; none -> [] end.