mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-23 22:50:51 +08:00
feat: use DiceBear for default avatars
This commit is contained in:
25
src/main/java/com/openisle/service/AvatarGenerator.java
Normal file
25
src/main/java/com/openisle/service/AvatarGenerator.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.openisle.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Service
|
||||
public class AvatarGenerator {
|
||||
|
||||
@Value("${app.avatar.base-url:https://api.dicebear.com/6.x}")
|
||||
private String baseUrl;
|
||||
|
||||
@Value("${app.avatar.style:identicon}")
|
||||
private String style;
|
||||
|
||||
@Value("${app.avatar.size:64}")
|
||||
private int size;
|
||||
|
||||
public String generate(String seed) {
|
||||
String encoded = URLEncoder.encode(seed, StandardCharsets.UTF_8);
|
||||
return String.format("%s/%s/png?seed=%s&size=%d", baseUrl, style, encoded, size);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user