diff --git a/map.go b/map.go index 687fc24..3e3455a 100644 --- a/map.go +++ b/map.go @@ -18,6 +18,7 @@ import ( // ErrUnsupportedFormat is returned when an unsupported map format is used. var ErrUnsupportedFormat = errors.New("unsupported map format") +var extensionFormats = []string{".asc", ".sha", ".torrent"} // loadMapFile loads a file as a map func loadMapFile(file string, specialExtensions map[string]string) (map[string]string, error) { @@ -128,18 +129,18 @@ func loadMapJSON(f io.Reader, specialExtensions map[string]string) (map[string]s } } - sb.WriteString(".") + // Also add entries for .asc .sha and .torrent + for _, ext := range extensionFormats { + if strings.HasSuffix(file.Extension, ext) { + continue + } - if strings.HasSuffix(file.Extension, ".sha") { - sb.WriteString("sha") - } else if strings.HasSuffix(file.Extension, ".asc") { - sb.WriteString("asc") - } else if strings.HasSuffix(file.Extension, ".torrent") { - sb.WriteString("torrent") - } else { - sb.WriteString(file.Extension) + m[sb.String()+ext] = u.Path + ext } + sb.WriteString(".") + sb.WriteString(file.Extension) + m[sb.String()] = u.Path // Add board into the map with an extension } diff --git a/map_test.go b/map_test.go index 4466dac..6e23448 100644 --- a/map_test.go +++ b/map_test.go @@ -60,19 +60,6 @@ var _ = Describe("Map", func() { "download_repository": "archive", "file_extension": "img.xz" }, - { - "board_slug": "khadas-vim1", - "file_url": "https://dl.armbian.com/khadas-vim1/archive/Armbian_23.11.1_Khadas-vim1_bookworm_current_6.1.63_xfce_desktop.img.xz.sha", - "file_updated": "2023-11-30T01:06:34Z", - "file_size": "1605260504", - "distro_release": "bookworm", - "kernel_branch": "current", - "image_variant": "xfce", - "preinstalled_application": "", - "promoted": "false", - "download_repository": "archive", - "file_extension": "img.xz.sha" - }, { "board_slug": "khadas-vim1", "file_url": "https://dl.armbian.com/khadas-vim1/archive/Armbian_23.11.1_Khadas-vim1_bookworm_current_6.1.63_xfce_desktop.img.xz", @@ -112,34 +99,6 @@ var _ = Describe("Map", func() { "promoted": "true", "download_repository": "archive", "file_extension": "oowow.img.xz" - }, - { - "board_slug": "khadas-vim4", - "armbian_version": "23.11.1", - "file_url": "https://dl.armbian.com/khadas-vim4/archive/Armbian_23.11.1_Khadas-vim4_bookworm_legacy_5.4.180.oowow.img.xz.asc", - "file_updated": "2023-11-30T01:03:05Z", - "file_size": "833", - "distro_release": "bookworm", - "kernel_branch": "legacy", - "image_variant": "server", - "preinstalled_application": "", - "promoted": "true", - "download_repository": "archive", - "file_extension": "oowow.img.xz.asc" - }, - { - "board_slug": "khadas-vim4", - "armbian_version": "23.11.1", - "file_url": "https://dl.armbian.com/khadas-vim4/archive/Armbian_23.11.1_Khadas-vim4_bookworm_legacy_5.4.180.oowow.img.xz.sha", - "file_updated": "2023-11-30T01:03:05Z", - "file_size": "178", - "distro_release": "bookworm", - "kernel_branch": "legacy", - "image_variant": "server", - "preinstalled_application": "", - "promoted": "true", - "download_repository": "archive", - "file_extension": "oowow.img.xz.sha" }, { "board_slug": "uefi-arm64", @@ -155,36 +114,6 @@ var _ = Describe("Map", func() { "promoted": "false", "download_repository": "archive", "file_extension": "img.qcow2" - }, - { - "board_slug": "uefi-arm64", - "armbian_version": "24.5.5", - "file_url": "https://dl.armbian.com/uefi-arm64/archive/Armbian_24.5.5_Uefi-arm64_bookworm_current_6.6.42_minimal.img.qcow2.asc", - "redi_url": "https://dl.armbian.com/uefi-arm64/Bookworm_current_minimal.asc", - "file_updated": "2024-07-25T18:01:20Z", - "file_size": "833", - "distro_release": "bookworm", - "kernel_branch": "current", - "image_variant": "minimal", - "preinstalled_application": "", - "promoted": "false", - "download_repository": "archive", - "file_extension": "img.qcow2.asc" - }, - { - "board_slug": "uefi-arm64", - "armbian_version": "24.5.5", - "file_url": "https://dl.armbian.com/uefi-arm64/archive/Armbian_24.5.5_Uefi-arm64_bookworm_current_6.6.42_minimal.img.qcow2.sha", - "redi_url": "https://dl.armbian.com/uefi-arm64/Bookworm_current_minimal.sha", - "file_updated": "2024-07-25T18:01:20Z", - "file_size": "194", - "distro_release": "bookworm", - "kernel_branch": "current", - "image_variant": "minimal", - "preinstalled_application": "", - "promoted": "false", - "download_repository": "archive", - "file_extension": "img.qcow2.sha" }, { "board_slug": "qemu-uboot-arm64",