taskbridgeapp.notes.model.note.Attachment

class taskbridgeapp.notes.model.note.Attachment(file_type='', file_name='', url='', b64_data=None, uuid='')

Bases: object

Represents an attachment in a note.

Methods

delete_remote

Deletes the remote file linked to this attachment.

get_supported_image_types

Get a list of supported image types.

get_supported_image_types_string

Get a list of supported image types as a pipe-separated string.

parse_local

Parses attachments from a staged file content into a list of Attachment.

parse_remote

Parses attachments from a remote note and updates Attachment fields

save_image_to_file

Saves a Base64 image attachment to a file.

Attributes

TYPE_IMAGE

used to denote that this attachment is an image.

TYPE_LINK

used to denote that this attachment is a hyperlink.

TYPE_UNSUPPORTED

used to denote that this attachment is of an unsupported type.

_SUPPORTED_IMAGE_TYPES

TYPE_IMAGE: int = 0

used to denote that this attachment is an image.

used to denote that this attachment is a hyperlink.

TYPE_UNSUPPORTED: int = 10

used to denote that this attachment is of an unsupported type.

__init__(file_type='', file_name='', url='', b64_data=None, uuid='')

Creates a new instance of Attachment.

Parameters:

file_type (int) – the type of attachment. Accepts Attachment.TYPE_IMAGE, Attachment.TYPE_LINK or

Attachment.TYPE_UNSUPPORTED. :type file_name: str :param file_name: the file name of the attachment (for images). :type url: str :param url: the url of the attachment (location for images, address for links). :type b64_data: str | None :param b64_data: the Base64 encoded data of an image. :type uuid: str :param uuid: the UUID for this attachment.

static _get_local_image(staged_lines, image_index)

Given the lines of a staged file and an index, retrieves the associated image src attribute.

Parameters:
  • staged_lines (List[str]) – the lines from a staged file.

  • image_index (int) – the index of the image attachment to retrieve.

Return type:

str | None

Returns:

-success (bool) - true if image source is retrieved successfully.

-data (None | str) - nothing on failure, or the src attribute.

static _get_remote_image(url)

Given the path to an image, returns a Base64 representation of the image.

Parameters:

url (str) – the path to the image.

Return type:

str | None

Returns:

-success (bool) - true if image is parsed successfully.

-data (None | str) - nothing on failure, or the Base64 image data.

delete_remote()

Deletes the remote file linked to this attachment.

Return type:

tuple[bool, str]

Returns:

-success (bool) - true if the note is successfully deleted.

-data (str) - success message, or error message on failure.

static get_supported_image_types()

Get a list of supported image types.

Return type:

List[str]

Returns:

a list of supported image types.

static get_supported_image_types_string()

Get a list of supported image types as a pipe-separated string.

Return type:

str

Returns:

a list of supported image types as a pipe-separated string.

static parse_local(attachments, staged_lines, dest_folder)

Parses attachments from a staged file content into a list of Attachment.

Parameters:
  • attachments (List[Attachment]) – the list of attachment. Each object should contain the file name

  • staged_lines (List[str]) – a list of lines from the staged file

  • dest_folder (Path) – the directory where parsed attachments are to be saved (for images)

Return type:

Union[List[Attachment], tuple[bool, str]]

Returns:

-success (bool) - true if the note is successfully parsed.

-data (str | List[Attachment]) - error message on failure or List[Attachment].

static parse_remote(attachments)

Parses attachments from a remote note and updates Attachment fields

Parameters:

attachments (List[Attachment]) – the list of attachments from the file

Return type:

List[Attachment]

Returns:

the list of parsed attachments for this note

save_image_to_file(file_path)

Saves a Base64 image attachment to a file.

Parameters:

file_path (Path) – the path where to save the image excluding file name.

Return type:

tuple[bool, Path] | tuple[bool, str]

Returns:

-success (bool) - true if the note is successfully created.

-data (str | Path) - error message on failure, or path to created image.