Move calculation of portrait ID to interface
This commit is contained in:
parent
ffa66fb1bb
commit
bc8ba10557
|
@ -8,9 +8,6 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
@Slf4j
|
||||
public record LocalPortraitStore(Config config) implements PortraitStore {
|
||||
|
@ -38,7 +35,7 @@ public record LocalPortraitStore(Config config) implements PortraitStore {
|
|||
|
||||
@Override
|
||||
public void writePortrait(String modelUrl, byte[] data) throws IOException {
|
||||
String portraitId = config.getSettings().modelPortraits.getOrDefault(modelUrl, UUID.nameUUIDFromBytes(modelUrl.getBytes(UTF_8)).toString());
|
||||
String portraitId = config.getSettings().modelPortraits.getOrDefault(modelUrl, idForModelUrl(modelUrl));
|
||||
File portraitFile = getPortraitFile(portraitId);
|
||||
Files.write(portraitFile.toPath(), data);
|
||||
config.getSettings().modelPortraits.put(modelUrl, portraitId);
|
||||
|
|
|
@ -2,6 +2,9 @@ package ctbrec.image;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
public interface PortraitStore {
|
||||
|
||||
|
@ -15,4 +18,8 @@ public interface PortraitStore {
|
|||
void writePortrait(String modelUrl, byte[] data) throws IOException;
|
||||
|
||||
void removePortrait(String modelUrl) throws IOException;
|
||||
|
||||
default String idForModelUrl(String modelUrl) {
|
||||
return UUID.nameUUIDFromBytes(modelUrl.getBytes(UTF_8)).toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue