@@ -0,0 +1,15 @@
|
||||
package com.rdkr.tide_display.backend.firmware.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/")
|
||||
public class RootController {
|
||||
|
||||
@GetMapping()
|
||||
public String index() {
|
||||
return "Tide Display Backend";
|
||||
}
|
||||
}
|
@@ -20,7 +20,7 @@ public class VersionController {
|
||||
|
||||
@GetMapping()
|
||||
public ResponseEntity<List<Firmware>> getVersions() {
|
||||
return ResponseEntity.of(Optional.of(firmwareService.getFirmwareVersions()));
|
||||
return ResponseEntity.of(Optional.ofNullable(firmwareService.getFirmwareVersions()));
|
||||
}
|
||||
|
||||
@GetMapping("latest")
|
||||
|
@@ -27,7 +27,7 @@ public class FirmwareServiceImpl implements FirmwareService {
|
||||
public Optional<Firmware> getFirmwareVersion(String version) {
|
||||
return
|
||||
storageService.getFirmwareVersions().stream()
|
||||
.filter(firmware -> firmware.version().equals(version))
|
||||
//.filter(firmware -> firmware.version().equals(version))
|
||||
.findFirst();
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,30 @@
|
||||
package com.rdkr.tide_display.backend.gcp;
|
||||
|
||||
public record Firmware(String version, String url, String checksum) {
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import java.time.OffsetDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Firmware {
|
||||
|
||||
@JsonIgnore
|
||||
private int major;
|
||||
|
||||
@JsonIgnore
|
||||
private int minor;
|
||||
|
||||
@JsonIgnore
|
||||
private int patch;
|
||||
|
||||
private String url;
|
||||
|
||||
private String eTag;
|
||||
|
||||
private OffsetDateTime lastModified;
|
||||
|
||||
public String getVersion() {
|
||||
return String.format("%d.%d.%d", major, minor, patch);
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,13 @@
|
||||
package com.rdkr.tide_display.backend.gcp.service;
|
||||
|
||||
import com.google.cloud.storage.Storage.BlobListOption;
|
||||
import com.google.cloud.storage.StorageOptions;
|
||||
import com.rdkr.tide_display.backend.gcp.Firmware;
|
||||
import com.rdkr.tide_display.backend.gcp.StorageService;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.val;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@@ -10,9 +15,35 @@ public class StorageServiceImpl implements StorageService {
|
||||
|
||||
@Override
|
||||
public List<Firmware> getFirmwareVersions() {
|
||||
return List.of(
|
||||
new Firmware("1.0.1", "/firmware/1.0.1/firmware.bin", "0987654321"),
|
||||
new Firmware("1.0.0", "/firmware/1.0.0/firmware.bin", "1234567890")
|
||||
);
|
||||
val result = new ArrayList<Firmware>();
|
||||
val storage = StorageOptions.getDefaultInstance().getService();
|
||||
String bucketName = "ec804bd8-38d2-4fcc-8f04-5addb55b3c90";
|
||||
val bucket = storage.list(bucketName, BlobListOption.currentDirectory(), BlobListOption.prefix("firmware/"));
|
||||
for (val directory : bucket.iterateAll()) {
|
||||
val files = storage.list(bucketName, BlobListOption.currentDirectory(), BlobListOption.prefix(directory.getName()));
|
||||
for (val file : files.iterateAll()) {
|
||||
val name = file.getName();
|
||||
if (name.endsWith(".bin")) {
|
||||
val version = directory.getName().replace("firmware/", "").replace("/", "").split("\\.");
|
||||
if (version.length == 3) {
|
||||
int major = Integer.parseInt(version[0]);
|
||||
int minor = Integer.parseInt(version[1]);
|
||||
int patch = Integer.parseInt(version[2]);
|
||||
result.add(new Firmware(major, minor, patch, "/files/" + major + "." + minor + "." + patch + "/firmware.bin", file.getEtag(), file.getUpdateTimeOffsetDateTime()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result.sort((a, b) -> {
|
||||
if (a.getMajor() != b.getMajor()) {
|
||||
return a.getMajor() - b.getMajor();
|
||||
}
|
||||
if (a.getMinor() != b.getMinor()) {
|
||||
return a.getMinor() - b.getMinor();
|
||||
}
|
||||
return a.getPatch() - b.getPatch();
|
||||
});
|
||||
|
||||
return result.reversed();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user