diff --git a/.reuse/dep5 b/.reuse/dep5 deleted file mode 100644 index 589ac6e..0000000 --- a/.reuse/dep5 +++ /dev/null @@ -1,10 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: enbas -Upstream-Contact: Dan Anglin -Source: https://codeflow.dananglin.me.uk/apollo/enbas - -# Sample paragraph, commented out: -# -# Files: src/* -# Copyright: $YEAR $NAME <$CONTACT> -# License: ... diff --git a/README.md b/README.md index 39bece4..4bf9ea0 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,3 @@ - - # Enbas ### Overview @@ -33,7 +27,8 @@ the `main` branch mirrored to the following forges: ### Licensing -Each file is annotated with the licensing information, but in general: +The licensing information associated with each file is specified in the [REUSE.toml](REUSE.toml) file, +but in general: - All original source code is licensed under GPL-3.0-or-later. - All documentation is licensed under CC-BY-4.0. diff --git a/REUSE.toml b/REUSE.toml new file mode 100644 index 0000000..be400c2 --- /dev/null +++ b/REUSE.toml @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: 2024 Dan Anglin +# +# SPDX-License-Identifier: CC0-1.0 + +version = 1 +SPDX-PackageName = "enbas" +SPDX-PackageSupplier = "Dan Anglin " +SPDX-PackageDownloadLocation = "https://codeflow.dananglin.me.uk/apollo/enbas" + +[[annotations]] +path = [ + "**.go", + "go.mod", + "magefiles/go.mod", +] +precedence = "override" +SPDX-FileCopyrightText = "2024 Dan Anglin " +SPDX-License-Identifier = "GPL-3.0-or-later" + +[[annotations]] +path = [ + "README.md", + "docs/*.md", + "assets/images/*.png", +] +precedence = "override" +SPDX-FileCopyrightText = "2024 Dan Anglin " +SPDX-License-Identifier = "CC-BY-4.0" + +[[annotations]] +path = [ + "go.sum", + "magefiles/go.sum", +] +precedence = "override" +SPDX-FileCopyrightText = "2024 Dan Anglin " +SPDX-License-Identifier = "CC0-1.0" diff --git a/assets/images/consent_form.png.license b/assets/images/consent_form.png.license deleted file mode 100644 index 8f40b5d..0000000 --- a/assets/images/consent_form.png.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2024 Dan Anglin - -SPDX-License-Identifier: CC-BY-4.0 diff --git a/assets/images/created_poll.png.license b/assets/images/created_poll.png.license deleted file mode 100644 index 8f40b5d..0000000 --- a/assets/images/created_poll.png.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2024 Dan Anglin - -SPDX-License-Identifier: CC-BY-4.0 diff --git a/cmd/enbas/main.go b/cmd/enbas/main.go index d49c22f..f8168a9 100644 --- a/cmd/enbas/main.go +++ b/cmd/enbas/main.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package main import ( diff --git a/cmd/enbas/usage.go b/cmd/enbas/usage.go index eb0a214..48a6332 100644 --- a/cmd/enbas/usage.go +++ b/cmd/enbas/usage.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package main import ( diff --git a/docs/changelog.md b/docs/changelog.md index 8b1a20e..825c32f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,7 +1 @@ - - # Changelog diff --git a/docs/configuration.md b/docs/configuration.md index 69c8379..5e84793 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,9 +1,3 @@ - - # Configuration reference ## Config diff --git a/docs/getting_started.md b/docs/getting_started.md index 2ae9d60..ef19951 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -1,9 +1,3 @@ - - # Getting Started ## Summary diff --git a/docs/installation.md b/docs/installation.md index b0eb959..bffc8f1 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -1,9 +1,3 @@ - - # Installation Guide ## Download diff --git a/docs/manual.md b/docs/manual.md index 51caac6..05e1cce 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -1,9 +1,3 @@ - - # User Manual ## Table of Contents @@ -722,23 +716,16 @@ video player in your configuration file respectively. See the [configuration reference page](configuration.md#integration) on how to set up integration with your media players. -- View a specific media attachment from a specific status - ``` - enbas show --type media --from status --status-id 01J0N11V4V7PWH0DDRAVT7TCFK --attachment-id 01J0N0RQSJ7CFGKHA30F7GBQXT - ``` -- View all image attachments from a specific status - ``` - enbas show --type media --from status --status-id 01J0N11V4V7PWH0DDRAVT7TCFK --all-images - ``` +``` +enbas show --type media --from status --status-id 01J0N11V4V7PWH0DDRAVT7TCFK --attachment-id 01J0N0RQSJ7CFGKHA30F7GBQXT +``` | flag | type | required | description | default | |------|------|----------|-------------|---------| | `type` | string | true | The resource you want to view.
Here this should be `media`. | | | `from` | string | true | The resource you want to view the media from.
Here this should be `status`. | | | `status-id` | string | true | The ID of the status that you want to view the media from. | | -| `attachment-id` | string | false | The ID of the media attachment to download and view.
Use this flag multiple times to specify multiple media attachments. | | -| `all-images` | boolean | false | Set to `true` to show all images from the status. | false | -| `all-videos` | boolean | false | Set to `true` to show all videos from the status. | false | +| `attachment-id` | string | true | The ID of the media attachment to download and view.
Use this flag multiple times to specify multiple media attachments. | | ## Bookmarks diff --git a/go.mod b/go.mod index 5ec9927..41121d7 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - module codeflow.dananglin.me.uk/apollo/enbas go 1.22.5 diff --git a/go.sum.license b/go.sum.license deleted file mode 100644 index 67136a5..0000000 --- a/go.sum.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2024 Dan Anglin - -SPDX-License-Identifier: CC0-1.0 diff --git a/internal/client/accounts.go b/internal/client/accounts.go index dfa417c..b63dc16 100644 --- a/internal/client/accounts.go +++ b/internal/client/accounts.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/client.go b/internal/client/client.go index f72c394..a9ff5d1 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/errors.go b/internal/client/errors.go index 7e0d393..b2f2617 100644 --- a/internal/client/errors.go +++ b/internal/client/errors.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import "fmt" diff --git a/internal/client/instance.go b/internal/client/instance.go index de531cf..4ea98f3 100644 --- a/internal/client/instance.go +++ b/internal/client/instance.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/lists.go b/internal/client/lists.go index f977a7d..d7ae52f 100644 --- a/internal/client/lists.go +++ b/internal/client/lists.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/media.go b/internal/client/media.go index bedf763..3be293d 100644 --- a/internal/client/media.go +++ b/internal/client/media.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/poll.go b/internal/client/poll.go index 7e55253..dfaea22 100644 --- a/internal/client/poll.go +++ b/internal/client/poll.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/preferences.go b/internal/client/preferences.go index cc8a88f..12eba60 100644 --- a/internal/client/preferences.go +++ b/internal/client/preferences.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/register.go b/internal/client/register.go index 9be1c32..d664787 100644 --- a/internal/client/register.go +++ b/internal/client/register.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/statuses.go b/internal/client/statuses.go index 253ff17..0befba3 100644 --- a/internal/client/statuses.go +++ b/internal/client/statuses.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/timelines.go b/internal/client/timelines.go index 8bfe753..9d4a0f9 100644 --- a/internal/client/timelines.go +++ b/internal/client/timelines.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/client/token.go b/internal/client/token.go index 4aeff04..a9df66d 100644 --- a/internal/client/token.go +++ b/internal/client/token.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package client import ( diff --git a/internal/config/config.go b/internal/config/config.go index 18ec1a6..29cae4a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package config import ( diff --git a/internal/config/credentials.go b/internal/config/credentials.go index a2fb554..57e8ee5 100644 --- a/internal/config/credentials.go +++ b/internal/config/credentials.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package config import ( diff --git a/internal/executor/accept_or_reject.go b/internal/executor/accept_or_reject.go index 767661c..71b3ff7 100644 --- a/internal/executor/accept_or_reject.go +++ b/internal/executor/accept_or_reject.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/account.go b/internal/executor/account.go index b67be29..4185d3e 100644 --- a/internal/executor/account.go +++ b/internal/executor/account.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/add.go b/internal/executor/add.go index 46f116d..a9a7231 100644 --- a/internal/executor/add.go +++ b/internal/executor/add.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/block_or_unblock.go b/internal/executor/block_or_unblock.go index c383e99..3a38a62 100644 --- a/internal/executor/block_or_unblock.go +++ b/internal/executor/block_or_unblock.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/commands.go b/internal/executor/commands.go index b16a551..6ca174e 100644 --- a/internal/executor/commands.go +++ b/internal/executor/commands.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor const ( diff --git a/internal/executor/create.go b/internal/executor/create.go index a7d14a7..0360ab0 100644 --- a/internal/executor/create.go +++ b/internal/executor/create.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/delete.go b/internal/executor/delete.go index 819204f..d88d381 100644 --- a/internal/executor/delete.go +++ b/internal/executor/delete.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/edit.go b/internal/executor/edit.go index ee92375..a5f271b 100644 --- a/internal/executor/edit.go +++ b/internal/executor/edit.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/errors.go b/internal/executor/errors.go index 68aa04a..92a99e3 100644 --- a/internal/executor/errors.go +++ b/internal/executor/errors.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor type FlagNotSetError struct { @@ -116,10 +112,10 @@ func (e NotFollowingError) Error() string { return "you are not following " + e.Account } -//type UnknownMediaAttachmentError struct { -// AttachmentID string -//} -// -//func (e UnknownMediaAttachmentError) Error() string { -// return "unknown media attachment '" + e.AttachmentID + "'" -//} +type UnknownMediaAttachmentError struct { + AttachmentID string +} + +func (e UnknownMediaAttachmentError) Error() string { + return "unknown media attachment '" + e.AttachmentID + "'" +} diff --git a/internal/executor/executor.go b/internal/executor/executor.go index 01e50ad..81d73e9 100644 --- a/internal/executor/executor.go +++ b/internal/executor/executor.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import "fmt" diff --git a/internal/executor/flags.go b/internal/executor/flags.go index 61a5a80..28eba46 100644 --- a/internal/executor/flags.go +++ b/internal/executor/flags.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/follow_or_unfollow.go b/internal/executor/follow_or_unfollow.go index 697c8a3..eb7d15f 100644 --- a/internal/executor/follow_or_unfollow.go +++ b/internal/executor/follow_or_unfollow.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/init.go b/internal/executor/init.go index 54581b3..35b64a4 100644 --- a/internal/executor/init.go +++ b/internal/executor/init.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/login.go b/internal/executor/login.go index e13a1b2..971d100 100644 --- a/internal/executor/login.go +++ b/internal/executor/login.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/mute_or_unmute.go b/internal/executor/mute_or_unmute.go index 374997a..790f04d 100644 --- a/internal/executor/mute_or_unmute.go +++ b/internal/executor/mute_or_unmute.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/remove.go b/internal/executor/remove.go index eeff8b0..bc30e4b 100644 --- a/internal/executor/remove.go +++ b/internal/executor/remove.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/resources.go b/internal/executor/resources.go index 12b02f6..d60102a 100644 --- a/internal/executor/resources.go +++ b/internal/executor/resources.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor const ( diff --git a/internal/executor/show.go b/internal/executor/show.go index 7e76119..09e740d 100644 --- a/internal/executor/show.go +++ b/internal/executor/show.go @@ -1,17 +1,13 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( "flag" "fmt" "path/filepath" + "strings" "codeflow.dananglin.me.uk/apollo/enbas/internal/client" "codeflow.dananglin.me.uk/apollo/enbas/internal/config" - "codeflow.dananglin.me.uk/apollo/enbas/internal/media" "codeflow.dananglin.me.uk/apollo/enbas/internal/model" "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" "codeflow.dananglin.me.uk/apollo/enbas/internal/utilities" @@ -32,8 +28,6 @@ type ShowExecutor struct { showUserPreferences bool showStatuses bool skipAccountRelationship bool - getAllImages bool - getAllVideos bool resourceType string accountName string statusID string @@ -64,8 +58,6 @@ func NewShowExecutor(printer *printer.Printer, config *config.Config, name, summ showExe.BoolVar(&showExe.onlyPinned, flagOnlyPinned, false, "Set to true to show only the account's pinned statuses") showExe.BoolVar(&showExe.onlyMedia, flagOnlyMedia, false, "Set to true to show only the statuses with media attachments") showExe.BoolVar(&showExe.onlyPublic, flagOnlyPublic, false, "Set to true to show only the account's public posts") - showExe.BoolVar(&showExe.getAllImages, "all-images", false, "Set to true to show all images from a status") - showExe.BoolVar(&showExe.getAllVideos, "all-videos", false, "Set to true to show all videos from a status") showExe.StringVar(&showExe.resourceType, flagType, "", "Specify the type of resource to display") showExe.StringVar(&showExe.accountName, flagAccountName, "", "Specify the account name in full (username@domain)") showExe.StringVar(&showExe.statusID, flagStatusID, "", "Specify the ID of the status to display") @@ -533,6 +525,10 @@ func (s *ShowExecutor) showMedia(gtsClient *client.Client) error { } func (s *ShowExecutor) showMediaFromStatus(gtsClient *client.Client) error { + if len(s.attachmentIDs) == 0 { + return FlagNotSetError{flagText: flagAttachmentID} + } + if s.statusID == "" { return FlagNotSetError{flagText: flagStatusID} } @@ -551,26 +547,65 @@ func (s *ShowExecutor) showMediaFromStatus(gtsClient *client.Client) error { return fmt.Errorf("unable to ensure the existence of the directory %q: %w", cacheDir, err) } - mediaBundle := media.NewBundle( - cacheDir, - status.MediaAttachments, - s.getAllImages, - s.getAllVideos, - s.attachmentIDs, - ) - - if err := mediaBundle.Download(gtsClient); err != nil { - return fmt.Errorf("unable to download the media bundle: %w", err) + type media struct { + url string + mediaType string + } + + attachmentsHashMap := make(map[string]media) + imageFiles := make([]string, 0) + videoFiles := make([]string, 0) + + for _, statusAttachment := range status.MediaAttachments { + attachmentsHashMap[statusAttachment.ID] = media{ + url: statusAttachment.URL, + mediaType: statusAttachment.Type, + } + } + + for _, attachmentID := range s.attachmentIDs { + mediaObj, ok := attachmentsHashMap[attachmentID] + if !ok { + return UnknownMediaAttachmentError{AttachmentID: attachmentID} + } + + split := strings.Split(mediaObj.url, "/") + filename := split[len(split)-1] + filePath := filepath.Join(cacheDir, filename) + + fileExists, err := utilities.FileExists(filePath) + if err != nil { + return fmt.Errorf( + "unable to check if the media file is already downloaded for %s: %w", + attachmentID, + err, + ) + } + + if !fileExists { + if err := gtsClient.DownloadMedia(mediaObj.url, filePath); err != nil { + return fmt.Errorf( + "unable to download the media attachment for %s: %w", + attachmentID, + err, + ) + } + } + + switch mediaObj.mediaType { + case "image": + imageFiles = append(imageFiles, filePath) + case "video": + videoFiles = append(videoFiles, filePath) + } } - imageFiles := mediaBundle.ImageFiles() if len(imageFiles) > 0 { if err := utilities.OpenMedia(s.config.Integrations.ImageViewer, imageFiles); err != nil { return fmt.Errorf("unable to open the image viewer: %w", err) } } - videoFiles := mediaBundle.VideoFiles() if len(videoFiles) > 0 { if err := utilities.OpenMedia(s.config.Integrations.VideoPlayer, videoFiles); err != nil { return fmt.Errorf("unable to open the video player: %w", err) diff --git a/internal/executor/switch.go b/internal/executor/switch.go index e86eb9b..bb974d5 100644 --- a/internal/executor/switch.go +++ b/internal/executor/switch.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/usage.go b/internal/executor/usage.go index dfd26de..67d2718 100644 --- a/internal/executor/usage.go +++ b/internal/executor/usage.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/version.go b/internal/executor/version.go index 4dbf632..ad89c5a 100644 --- a/internal/executor/version.go +++ b/internal/executor/version.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/executor/whoami.go b/internal/executor/whoami.go index 4d068e9..69677a9 100644 --- a/internal/executor/whoami.go +++ b/internal/executor/whoami.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package executor import ( diff --git a/internal/internal.go b/internal/internal.go index 7e36795..b47f3df 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package internal const ( diff --git a/internal/media/media.go b/internal/media/media.go deleted file mode 100644 index 41be89f..0000000 --- a/internal/media/media.go +++ /dev/null @@ -1,174 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - -package media - -import ( - "fmt" - "path/filepath" - "strings" - - "codeflow.dananglin.me.uk/apollo/enbas/internal/client" - "codeflow.dananglin.me.uk/apollo/enbas/internal/model" - "codeflow.dananglin.me.uk/apollo/enbas/internal/utilities" -) - -const ( - mediaTypeImage string = "image" - mediaTypeVideo string = "video" -) - -type media struct { - source string - destination string - mediaType string -} - -func (m *media) download(gtsClient *client.Client) error { - fileExists, err := utilities.FileExists(m.destination) - if err != nil { - return fmt.Errorf( - "unable to determine if %s exists: %w", - m.destination, - err, - ) - } - - if fileExists { - return nil - } - - if err := gtsClient.DownloadMedia(m.source, m.destination); err != nil { - return fmt.Errorf( - "downloading %s -> %s failed: %w", - m.source, - m.destination, - err, - ) - } - - return nil -} - -func newMediaHashmap(cacheDir string, attachments []model.Attachment) map[string]media { - hashmap := make(map[string]media) - - for ind := range attachments { - hashmap[attachments[ind].ID] = media{ - source: attachments[ind].URL, - destination: mediaFilepath(cacheDir, attachments[ind].URL), - mediaType: attachments[ind].Type, - } - } - - return hashmap -} - -type Bundle struct { - images []media - videos []media -} - -func NewBundle( - cacheDir string, - attachments []model.Attachment, - getAllImages bool, - getAllVideos bool, - attachmentIDs []string, -) Bundle { - mediaHashmap := newMediaHashmap(cacheDir, attachments) - images := make([]media, 0) - videos := make([]media, 0) - - if !getAllImages && !getAllVideos && len(attachmentIDs) == 0 { - return Bundle{ - images: images, - videos: videos, - } - } - - if getAllImages || getAllVideos { - if getAllImages { - for _, m := range mediaHashmap { - if m.mediaType == mediaTypeImage { - images = append(images, m) - } - } - } - - if getAllVideos { - for _, m := range mediaHashmap { - if m.mediaType == mediaTypeVideo { - videos = append(videos, m) - } - } - } - - return Bundle{ - images: images, - videos: videos, - } - } - - for _, attachmentID := range attachmentIDs { - obj, ok := mediaHashmap[attachmentID] - if !ok { - continue - } - - switch obj.mediaType { - case mediaTypeImage: - images = append(images, obj) - case mediaTypeVideo: - videos = append(videos, obj) - } - } - - return Bundle{ - images: images, - videos: videos, - } -} - -func (m *Bundle) Download(gtsClient *client.Client) error { - for ind := range m.images { - if err := m.images[ind].download(gtsClient); err != nil { - return fmt.Errorf("received an error trying to download the image files: %w", err) - } - } - - for ind := range m.videos { - if err := m.videos[ind].download(gtsClient); err != nil { - return fmt.Errorf("received an error trying to download the video files: %w", err) - } - } - - return nil -} - -func (m *Bundle) ImageFiles() []string { - filepaths := make([]string, len(m.images)) - - for ind := range m.images { - filepaths[ind] = m.images[ind].destination - } - - return filepaths -} - -func (m *Bundle) VideoFiles() []string { - filepaths := make([]string, len(m.videos)) - - for ind := range m.videos { - filepaths[ind] = m.videos[ind].destination - } - - return filepaths -} - -func mediaFilepath(cacheDir, mediaURL string) string { - split := strings.Split(mediaURL, "/") - - return filepath.Join(cacheDir, split[len(split)-1]) -} diff --git a/internal/model/account.go b/internal/model/account.go index e89266b..b0fcb8b 100644 --- a/internal/model/account.go +++ b/internal/model/account.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model import ( diff --git a/internal/model/application.go b/internal/model/application.go index f251fd8..67f0e63 100644 --- a/internal/model/application.go +++ b/internal/model/application.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model type Application struct { diff --git a/internal/model/const.go b/internal/model/const.go index e3c4c52..c794dcc 100644 --- a/internal/model/const.go +++ b/internal/model/const.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model const ( diff --git a/internal/model/emoji.go b/internal/model/emoji.go index 41b174c..a71f31c 100644 --- a/internal/model/emoji.go +++ b/internal/model/emoji.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model type Emoji struct { diff --git a/internal/model/instance_v2.go b/internal/model/instance_v2.go index 83a438f..4826477 100644 --- a/internal/model/instance_v2.go +++ b/internal/model/instance_v2.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model type InstanceV2 struct { diff --git a/internal/model/list.go b/internal/model/list.go index bbd6a30..4d6e953 100644 --- a/internal/model/list.go +++ b/internal/model/list.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model import ( diff --git a/internal/model/poll.go b/internal/model/poll.go index 72d174b..14bd6a2 100644 --- a/internal/model/poll.go +++ b/internal/model/poll.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model import ( diff --git a/internal/model/preferences.go b/internal/model/preferences.go index c20023e..389e57c 100644 --- a/internal/model/preferences.go +++ b/internal/model/preferences.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model type Preferences struct { diff --git a/internal/model/status.go b/internal/model/status.go index cc8aa32..057e64a 100644 --- a/internal/model/status.go +++ b/internal/model/status.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model import ( diff --git a/internal/model/status_content_type.go b/internal/model/status_content_type.go index 8b252a9..f888c8c 100644 --- a/internal/model/status_content_type.go +++ b/internal/model/status_content_type.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model import ( diff --git a/internal/model/status_visibility.go b/internal/model/status_visibility.go index b001427..9003867 100644 --- a/internal/model/status_visibility.go +++ b/internal/model/status_visibility.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model import ( diff --git a/internal/model/timeline.go b/internal/model/timeline.go index 4169193..d431199 100644 --- a/internal/model/timeline.go +++ b/internal/model/timeline.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package model const ( diff --git a/internal/printer/account.go b/internal/printer/account.go index daf26e7..cc101ad 100644 --- a/internal/printer/account.go +++ b/internal/printer/account.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/printer/html.go b/internal/printer/html.go index ff6644d..8cbb533 100644 --- a/internal/printer/html.go +++ b/internal/printer/html.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/printer/instance.go b/internal/printer/instance.go index a19f53b..a1619ed 100644 --- a/internal/printer/instance.go +++ b/internal/printer/instance.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/printer/list.go b/internal/printer/list.go index 8695a90..8a92599 100644 --- a/internal/printer/list.go +++ b/internal/printer/list.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/printer/media_attachment.go b/internal/printer/media_attachment.go index bb72cd3..0e0be83 100644 --- a/internal/printer/media_attachment.go +++ b/internal/printer/media_attachment.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/printer/poll.go b/internal/printer/poll.go index 8a8a34d..16c99fe 100644 --- a/internal/printer/poll.go +++ b/internal/printer/poll.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/printer/printer.go b/internal/printer/printer.go index 9b1f641..6ac2325 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/printer/status.go b/internal/printer/status.go index 0dc7692..38ae7a7 100644 --- a/internal/printer/status.go +++ b/internal/printer/status.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/printer/version.go b/internal/printer/version.go index 695fbb0..93e9c5e 100644 --- a/internal/printer/version.go +++ b/internal/printer/version.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/printer/wrap.go b/internal/printer/wrap.go index bae7a58..96791cc 100644 --- a/internal/printer/wrap.go +++ b/internal/printer/wrap.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package printer import ( diff --git a/internal/utilities/absolute.go b/internal/utilities/absolute.go index 81c9a41..777be3b 100644 --- a/internal/utilities/absolute.go +++ b/internal/utilities/absolute.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package utilities import ( diff --git a/internal/utilities/directories.go b/internal/utilities/directories.go index afa9233..60b79ae 100644 --- a/internal/utilities/directories.go +++ b/internal/utilities/directories.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package utilities import ( diff --git a/internal/utilities/file.go b/internal/utilities/file.go index decce89..eb80ccd 100644 --- a/internal/utilities/file.go +++ b/internal/utilities/file.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package utilities import ( diff --git a/internal/utilities/utilities.go b/internal/utilities/utilities.go index 141eb91..3c66121 100644 --- a/internal/utilities/utilities.go +++ b/internal/utilities/utilities.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - package utilities import ( diff --git a/magefiles/go.mod b/magefiles/go.mod index 1ff7087..56ed109 100644 --- a/magefiles/go.mod +++ b/magefiles/go.mod @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - module codeflow.dananglin.me.uk/apollo/enbas/magefiles go 1.22.3 diff --git a/magefiles/go.sum.license b/magefiles/go.sum.license deleted file mode 100644 index 67136a5..0000000 --- a/magefiles/go.sum.license +++ /dev/null @@ -1,3 +0,0 @@ -SPDX-FileCopyrightText: 2024 Dan Anglin - -SPDX-License-Identifier: CC0-1.0 diff --git a/magefiles/mage.go b/magefiles/mage.go index 511cd74..55ab68b 100644 --- a/magefiles/mage.go +++ b/magefiles/mage.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - //go:build mage package main diff --git a/magefiles/main.go b/magefiles/main.go index 95cf826..8883df9 100644 --- a/magefiles/main.go +++ b/magefiles/main.go @@ -1,7 +1,3 @@ -// SPDX-FileCopyrightText: 2024 Dan Anglin -// -// SPDX-License-Identifier: GPL-3.0-or-later - //go:build ignore package main