enbas/internal/utilities/utilities.go
Dan Anglin 632a620180
feat: view media with external applications
This commit adds integration to external image viewers and video players
to allow users to view image and video attachments.

Enbas creates a cache directory where the media is downloaded to before
opening the external program for viewing.

Users can view one or more media attachments from a single status.
2024-06-22 01:16:24 +01:00

37 lines
738 B
Go

// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
//
// SPDX-License-Identifier: GPL-3.0-or-later
package utilities
import (
"fmt"
"os/exec"
"regexp"
)
func GetFQDN(url string) string {
r := regexp.MustCompile(`http(s)?:\/\/`)
return r.ReplaceAllString(url, "")
}
type UnspecifiedProgramError struct{}
func (e UnspecifiedProgramError) Error() string {
return "the program to view these files is unspecified"
}
func OpenMedia(viewer string, paths []string) error {
if viewer == "" {
return UnspecifiedProgramError{}
}
command := exec.Command(viewer, paths...)
if err := command.Start(); err != nil {
return fmt.Errorf("received an error after starting the image viewer: %w", err)
}
return nil
}