feat: add markdown link extraction and HF URL normalization in ComfyModelAnalyzer and ModelSearchService

This commit is contained in:
Thomas
2026-04-22 19:39:11 +02:00
parent 9d722bf251
commit 75b536980c
24 changed files with 1661 additions and 250 deletions
@@ -4,35 +4,74 @@ import org.json.JSONObject;
import org.springframework.stereotype.Service;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
@Service
public class ConfigService {
private static final String CONFIG_FILE = "app_settings.json";
private JSONObject settings;
private static final String VAULT_FILE = "settings.vault";
private JSONObject settings = new JSONObject();
private String masterPassword = null;
public ConfigService() {
load();
/**
* Use the current working directory for application data.
*/
public String getAppDataPath() {
return System.getProperty("user.dir");
}
private void load() {
try {
File file = new File(CONFIG_FILE);
if (file.exists()) {
settings = new JSONObject(Files.readString(file.toPath()));
public File getFileInAppData(String filename) {
return new File(getAppDataPath(), filename);
}
public void unlock(String password) throws Exception {
File vault = getFileInAppData(VAULT_FILE);
System.out.println("Attempting to unlock vault at: " + vault.getAbsolutePath());
if (vault.exists()) {
String encrypted = Files.readString(vault.toPath(), StandardCharsets.UTF_8);
try {
String decrypted = EncryptionUtils.decrypt(encrypted, password);
JSONObject decryptedJson = new JSONObject(decrypted);
this.settings = decryptedJson;
this.masterPassword = password;
System.out.println("Vault unlocked successfully. Keys found: " + settings.keySet());
} catch (Exception e) {
System.err.println("Failed to unlock vault: " + e.getMessage());
throw new Exception("Wrong password or corrupted vault!");
}
} else {
this.masterPassword = password;
File oldFile = getFileInAppData(CONFIG_FILE);
if (oldFile.exists()) {
try {
String content = Files.readString(oldFile.toPath(), StandardCharsets.UTF_8);
this.settings = new JSONObject(content);
save();
oldFile.delete();
System.out.println("Migrated old settings to encrypted vault.");
} catch (Exception e) {
System.err.println("Failed to migrate old settings: " + e.getMessage());
}
} else {
settings = new JSONObject();
System.out.println("No vault found, initialized new empty vault at: " + vault.getAbsolutePath());
save();
}
} catch (Exception e) {
settings = new JSONObject();
}
}
public void save() {
if (masterPassword == null) {
System.err.println("Cannot save: Vault not unlocked.");
return;
}
try {
Files.writeString(Paths.get(CONFIG_FILE), settings.toString(4));
String encrypted = EncryptionUtils.encrypt(settings.toString(), masterPassword);
Files.writeString(getFileInAppData(VAULT_FILE).toPath(), encrypted, StandardCharsets.UTF_8);
System.out.println("Vault saved successfully to: " + getFileInAppData(VAULT_FILE).getAbsolutePath());
} catch (Exception e) {
System.err.println("Error saving vault: " + e.getMessage());
e.printStackTrace();
}
}
@@ -42,4 +81,11 @@ public class ConfigService {
public String getHfToken() { return settings.optString("hf_token", ""); }
public void setHfToken(String token) { settings.put("hf_token", token); save(); }
}
public String getModelsPath() { return settings.optString("models_path", "C:\\pinokio\\api\\comfy.git\\app\\models"); }
public void setModelsPath(String path) { settings.put("models_path", path); save(); }
public boolean isUnlocked() {
return masterPassword != null;
}
}