Skip to content

Commit

Permalink
Feat--get-the-list-of-supported-extensions-from-the-server-#134 (#166)
Browse files Browse the repository at this point in the history
#134 Immich server can serves the list of file types it can handling. Now Immich-go use this list instead a build in list.
  • Loading branch information
simulot committed Feb 25, 2024
1 parent a47cca4 commit 3f92c68
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 87 deletions.
3 changes: 3 additions & 0 deletions browser/files/localassets.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func (la *LocalAssetBrowser) handleFolder(ctx context.Context, fsys fs.FS, fileC
default:
la.log.AddEntry(fileName, logger.Unsupported, "")
continue
case immich.TypeIgnored:
la.log.AddEntry(name, logger.Discarded, "File ignored")
continue
case immich.TypeSidecar:
la.log.AddEntry(name, logger.Metadata, "")
continue
Expand Down
26 changes: 25 additions & 1 deletion cmd/upload/e2e_upload_folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,16 @@ func runCase(t *testing.T, tc testCase) {

ctx := context.Background()
ic, err := immich.NewImmichClient(host, key, false)

if err != nil {
t.Error(err)
return
}
u, err := ic.ValidateConnection(ctx)
if err != nil {
t.Error(err)
return
}
_ = u
if tc.resetImmich {
err := resetImmich(ic, user)
if err != nil {
Expand Down Expand Up @@ -340,6 +349,21 @@ func Test_Issue_128(t *testing.T) {
runCase(t, tc)
}

func Test_ExtensionsFromTheServer(t *testing.T) {
initMyEnv(t)

tc := testCase{
name: "ExtensionsFromTheServer",
args: []string{
myEnv["IMMICH_TESTFILES"] + "/low_high/high",
},

// resetImmich: true,
expectError: false,
}
runCase(t, tc)
}

// ResetImmich
// ⛔: will remove the content of the server.‼️
// Give the user of the connection to confirm the server instance: debug@example.com
Expand Down
112 changes: 26 additions & 86 deletions immich/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func (ic *ImmichClient) ValidateConnection(ctx context.Context) (User, error) {
if err != nil {
return user, err
}
sm["ignored-files"] = []string{".html", ".mp"}
sm[".html"] = TypeIgnored
sm[".mp"] = TypeIgnored
ic.supportedMediaTypes = sm
return user, nil
}
Expand Down Expand Up @@ -125,7 +126,7 @@ func (ic *ImmichClient) GetServerStatistics(ctx context.Context) (ServerStatisti
return s, err
}

type SupportedMedia map[string][]string
type SupportedMedia map[string]string

const (
TypeVideo = "video"
Expand All @@ -136,94 +137,35 @@ const (
)

var DefaultSupportedMedia = SupportedMedia{
TypeVideo: []string{
".3gp",
".avi",
".flv",
".insv",
".m2ts",
".m4v",
".mkv",
".mov",
".mp4",
".mpg",
".mts",
".webm",
".wmv",
},
TypeImage: []string{
".3fr",
".ari",
".arw",
".avif",
".bmp",
".cap",
".cin",
".cr2",
".cr3",
".crw",
".dcr",
".dng",
".erf",
".fff",
".gif",
".heic",
".heif",
".hif",
".iiq",
".insp",
".jpe",
".jpeg",
".jpg",
".jxl",
".k25",
".kdc",
".mrw",
".nef",
".orf",
".ori",
".pef",
".png",
".psd",
".raf",
".raw",
".rw2",
".rwl",
".sr2",
".srf",
".srw",
".tif",
".tiff",
".webp",
".x3f",
},
TypeSidecar: []string{
".xmp",
},
TypeIgnored: []string{
".mp",
".html",
},
".3gp": TypeVideo, ".avi": TypeVideo, ".flv": TypeVideo, ".insv": TypeVideo, ".m2ts": TypeVideo, ".m4v": TypeVideo, ".mkv": TypeVideo, ".mov": TypeVideo, ".mp4": TypeVideo, ".mpg": TypeVideo, ".mts": TypeVideo, ".webm": TypeVideo, ".wmv": TypeVideo,
".3fr": TypeImage, ".ari": TypeImage, ".arw": TypeImage, ".avif": TypeImage, ".bmp": TypeImage, ".cap": TypeImage, ".cin": TypeImage, ".cr2": TypeImage, ".cr3": TypeImage, ".crw": TypeImage, ".dcr": TypeImage, ".dng": TypeImage, ".erf": TypeImage,
".fff": TypeImage, ".gif": TypeImage, ".heic": TypeImage, ".heif": TypeImage, ".hif": TypeImage, ".iiq": TypeImage, ".insp": TypeImage, ".jpe": TypeImage, ".jpeg": TypeImage, ".jpg": TypeImage,
".jxl": TypeImage, ".k25": TypeImage, ".kdc": TypeImage, ".mrw": TypeImage, ".nef": TypeImage, ".orf": TypeImage, ".ori": TypeImage, ".pef": TypeImage, ".png": TypeImage, ".psd": TypeImage, ".raf": TypeImage, ".raw": TypeImage, ".rw2": TypeImage,
".rwl": TypeImage, ".sr2": TypeImage, ".srf": TypeImage, ".srw": TypeImage, ".tif": TypeImage, ".tiff": TypeImage, ".webp": TypeImage, ".x3f": TypeImage,
".xmp": TypeSidecar,
".mp": TypeIgnored, ".html": TypeIgnored,
}

func (ic *ImmichClient) GetSupportedMediaTypes(ctx context.Context) (SupportedMedia, error) {
var s SupportedMedia
var s map[string][]string

err := ic.newServerCall(ctx, "GetSupportedMediaTypes").do(get("/server-info/media-types", setAcceptJSON()), responseJSON(&s))
s[TypeIgnored] = []string{".mp", ".html"}
return s, err
if err != nil {
return nil, err
}
sm := make(SupportedMedia)
for t, l := range s {
for _, e := range l {
sm[e] = t
}
}

return sm, err
}

func (sm SupportedMedia) TypeFromExt(ext string) string {
ext = strings.ToLower(ext)
for t, l := range sm {
for _, e := range l {
if e == ext {
return t
}
}
}
return ""
return sm[ext]
}

func (sm SupportedMedia) IsMedia(ext string) bool {
Expand All @@ -233,12 +175,10 @@ func (sm SupportedMedia) IsMedia(ext string) bool {

func (sm SupportedMedia) IsExtensionPrefix(ext string) bool {
ext = strings.ToLower(ext)
for t, l := range sm {
for e, t := range sm {
if t == TypeVideo || t == TypeImage {
for _, e := range l {
if ext == e[:len(e)-1] {
return true
}
if ext == e[:len(e)-1] {
return true
}
}
}
Expand Down

0 comments on commit 3f92c68

Please sign in to comment.