fix: sanitize ChromaDB URL and update docker-compose CORS config
- src/semantic-cache.ts: Add robust URL sanitization in initialize(). Trim whitespace and reject malformed URLs (e.g. empty host like 'http://:8666') before passing to ChromaClient. - src/main.ts: Validate ChromaDB URL in the settings tab onChange. Fall back to 'http://localhost:8000' if the value is empty or lacks '://'. - docker-compose.yml: Add CHROMA_SERVER_CORS_ALLOW_ORIGINS=["*"] to allow cross-origin requests from Obsidian's app://obsidian.md origin.
This commit is contained in:
+2
-1
@@ -2,10 +2,11 @@ services:
|
||||
chroma:
|
||||
image: chromadb/chroma:latest
|
||||
ports:
|
||||
- "8666:8000"
|
||||
- '8666:8000'
|
||||
environment:
|
||||
- CHROMA_SERVER_HOST=0.0.0.0
|
||||
- CHROMA_SERVER_HTTP_PORT=8000
|
||||
- CHROMA_SERVER_CORS_ALLOW_ORIGINS=["*"]
|
||||
volumes:
|
||||
- chroma_data:/chroma/chroma
|
||||
restart: unless-stopped
|
||||
|
||||
@@ -7947,7 +7947,8 @@ var SemanticCacheService = class _SemanticCacheService {
|
||||
async initialize() {
|
||||
if (!this.config.enabled) return;
|
||||
try {
|
||||
const chromaURL = this.config.chromaURL || "http://localhost:8000";
|
||||
const rawURL = this.config.chromaURL?.trim() || "http://localhost:8000";
|
||||
const chromaURL = rawURL.includes("://") ? rawURL : "http://localhost:8000";
|
||||
this.client = new ChromaClient({ path: chromaURL });
|
||||
this.collection = await this.client.getOrCreateCollection({
|
||||
name: this.config.collectionName,
|
||||
@@ -9540,7 +9541,8 @@ var OllamaSettingTab = class extends import_obsidian4.PluginSettingTab {
|
||||
);
|
||||
new import_obsidian4.Setting(containerEl).setName("ChromaDB URL").setDesc("URL for your ChromaDB instance (default: http://localhost:8000)").addText(
|
||||
(text) => text.setValue(this.plugin.settings.cacheConfig.chromaURL || "http://localhost:8000").onChange(async (value) => {
|
||||
this.plugin.settings.cacheConfig.chromaURL = value;
|
||||
const trimmed = value.trim();
|
||||
this.plugin.settings.cacheConfig.chromaURL = trimmed && trimmed.includes("://") ? trimmed : "http://localhost:8000";
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
+4
-1
@@ -189,7 +189,10 @@ class OllamaSettingTab extends PluginSettingTab {
|
||||
text
|
||||
.setValue(this.plugin.settings.cacheConfig.chromaURL || 'http://localhost:8000')
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.cacheConfig.chromaURL = value;
|
||||
const trimmed = value.trim();
|
||||
// Ensure a valid-looking URL; fall back to default if empty or malformed
|
||||
this.plugin.settings.cacheConfig.chromaURL =
|
||||
trimmed && trimmed.includes('://') ? trimmed : 'http://localhost:8000';
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
@@ -19,7 +19,9 @@ export class SemanticCacheService {
|
||||
if (!this.config.enabled) return;
|
||||
|
||||
try {
|
||||
const chromaURL = this.config.chromaURL || 'http://localhost:8000';
|
||||
const rawURL = this.config.chromaURL?.trim() || 'http://localhost:8000';
|
||||
// Guard against malformed URLs like 'http://:8666'
|
||||
const chromaURL = rawURL.includes('://') ? rawURL : 'http://localhost:8000';
|
||||
this.client = new ChromaClient({ path: chromaURL });
|
||||
this.collection = await this.client.getOrCreateCollection({
|
||||
name: this.config.collectionName,
|
||||
|
||||
Reference in New Issue
Block a user