integrate official Tripo async models

This commit is contained in:
wlx committed 2026-09-27 16:45:36 +08:00
1 parent a022162382
commit 962eef26e5
11 files changed
+160 -20

No files matched your search

@@ -85,12 +85,18 @@ public class AsyncProviderClient {
Map<String,Object> row = jdbc.queryForMap("SELECT code, base_url, credential_ciphertext FROM model_providers WHERE id=? AND status='active' AND deleted_at IS NULL", id);
String ciphertext = row.get("credential_ciphertext") == null ? "" : String.valueOf(row.get("credential_ciphertext"));
String key = ciphertext.isBlank() ? "" : cipher.decrypt(ciphertext);
if (key.isBlank()) throw new ApiException("PROVIDER_NOT_CONFIGURED", "异步渠道尚未配置 API Key", 503);
String code = String.valueOf(row.get("code"));
List<String> keys = new ArrayList<>();
keys.add(key);
if (!key.isBlank()) keys.add(key);
addEnvironmentKeys(keys, code);
addEnvironmentKeys(keys, id);
// Tripo's official API key may be supplied through the server secret
// environment so it never has to be committed or exposed in SQL.
if (key.isBlank() && isTripo(code, String.valueOf(row.get("base_url")))) {
addEnvironmentKeys(keys, "TRIPO_API_KEY");
addEnvironmentKeys(keys, "MOYI_TRIPO_API_KEY");
}
if (keys.isEmpty()) throw new ApiException("PROVIDER_NOT_CONFIGURED", "异步渠道尚未配置 API Key", 503);
return new Provider(code, String.valueOf(row.get("base_url")), keys.stream().distinct().toList());
} catch (EmptyResultDataAccessException exception) { throw new ApiException("PROVIDER_NOT_CONFIGURED", "异步渠道不存在或已停用", 503); }
}
@@ -100,10 +106,15 @@ public class AsyncProviderClient {
private String encode(String value) { return java.net.URLEncoder.encode(value, java.nio.charset.StandardCharsets.UTF_8); }
private String write(Object value) throws JsonProcessingException { return mapper.writeValueAsString(value == null ? Map.of() : value); }
private void addEnvironmentKeys(List<String> keys, String alias) {
String name = "MOYI_UPSTREAM_API_KEYS_" + alias.toUpperCase(java.util.Locale.ROOT).replace('-', '_');
String name = alias.endsWith("_API_KEY") ? alias : "MOYI_UPSTREAM_API_KEYS_" + alias.toUpperCase(java.util.Locale.ROOT).replace('-', '_');
String configured = environment.getProperty(name);
if (configured != null && !configured.isBlank()) for (String value : configured.split("\\|")) if (!value.isBlank()) keys.add(value.trim());
}
private boolean isTripo(String code, String baseUrl) {
String normalizedCode = code == null ? "" : code.toLowerCase(java.util.Locale.ROOT);
String normalizedUrl = baseUrl == null ? "" : baseUrl.toLowerCase(java.util.Locale.ROOT);
return normalizedCode.contains("tripo") || normalizedUrl.contains("tripo3d");
}
private record Provider(String code, String baseUrl, List<String> apiKeys, AtomicInteger cursor) {
private Provider(String code, String baseUrl, List<String> apiKeys) { this(code, baseUrl, apiKeys, new AtomicInteger()); }
private String nextApiKey() { return apiKeys.get(Math.floorMod(cursor.getAndIncrement(), apiKeys.size())); }