Generated by Spark: Theres a hard to diagnose fault with this program where its interfering with the Github Spark GUI and causing extra prompts to be sent.

This commit is contained in:
2026-01-17 19:47:49 +00:00
committed by GitHub
parent b2f5718f4f
commit 6b2ee2a29f
3 changed files with 42 additions and 11 deletions

View File

@@ -203,10 +203,15 @@ function getFlaskAdapter(): FlaskStorageAdapter | null {
const config = getStorageConfig()
if (config.backend === 'flask' && config.flaskUrl) {
if (!flaskAdapter || flaskAdapter['baseUrl'] !== config.flaskUrl) {
flaskAdapter = new FlaskStorageAdapter(config.flaskUrl)
try {
if (!flaskAdapter || flaskAdapter['baseUrl'] !== config.flaskUrl) {
flaskAdapter = new FlaskStorageAdapter(config.flaskUrl)
}
return flaskAdapter
} catch (error) {
console.warn('Failed to create Flask adapter:', error)
return null
}
return flaskAdapter
}
return null
}
@@ -852,6 +857,4 @@ export async function syncTemplatesFromJSON(templates: SnippetTemplate[]): Promi
addedCount++
}
}
console.log(`Synced ${templates.length} templates from JSON, added ${addedCount} new templates`)
}

View File

@@ -62,23 +62,42 @@ export class FlaskStorageAdapter {
private baseUrl: string
constructor(baseUrl: string) {
if (!baseUrl || baseUrl.trim() === '') {
throw new Error('Flask backend URL cannot be empty')
}
this.baseUrl = baseUrl.replace(/\/$/, '')
}
async testConnection(): Promise<boolean> {
private isValidUrl(): boolean {
try {
const response = await fetch(`${this.baseUrl}/health`, {
new URL(this.baseUrl)
return true
} catch {
return false
}
}
async testConnection(): Promise<boolean> {
if (!this.isValidUrl()) {
return false
}
try {
const url = new URL('/health', this.baseUrl)
const response = await fetch(url.toString(), {
method: 'GET',
signal: AbortSignal.timeout(5000)
})
return response.ok
} catch (error) {
console.error('Flask connection test failed:', error)
return false
}
}
async getAllSnippets(): Promise<Snippet[]> {
if (!this.isValidUrl()) {
throw new Error('Invalid Flask backend URL')
}
const response = await fetch(`${this.baseUrl}/api/snippets`)
if (!response.ok) {
throw new Error(`Failed to fetch snippets: ${response.statusText}`)
@@ -92,6 +111,9 @@ export class FlaskStorageAdapter {
}
async getSnippet(id: string): Promise<Snippet | null> {
if (!this.isValidUrl()) {
throw new Error('Invalid Flask backend URL')
}
const response = await fetch(`${this.baseUrl}/api/snippets/${id}`)
if (response.status === 404) {
return null
@@ -108,6 +130,9 @@ export class FlaskStorageAdapter {
}
async createSnippet(snippet: Snippet): Promise<void> {
if (!this.isValidUrl()) {
throw new Error('Invalid Flask backend URL')
}
const response = await fetch(`${this.baseUrl}/api/snippets`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -123,6 +148,9 @@ export class FlaskStorageAdapter {
}
async updateSnippet(snippet: Snippet): Promise<void> {
if (!this.isValidUrl()) {
throw new Error('Invalid Flask backend URL')
}
const response = await fetch(`${this.baseUrl}/api/snippets/${snippet.id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
@@ -138,6 +166,9 @@ export class FlaskStorageAdapter {
}
async deleteSnippet(id: string): Promise<void> {
if (!this.isValidUrl()) {
throw new Error('Invalid Flask backend URL')
}
const response = await fetch(`${this.baseUrl}/api/snippets/${id}`, {
method: 'DELETE'
})

View File

@@ -70,9 +70,6 @@ export function SettingsPage() {
setStorageBackend(config.backend)
setFlaskUrl(config.flaskUrl || envFlaskUrl || 'http://localhost:5000')
if (config.backend === 'flask' && config.flaskUrl) {
testFlaskConnection(config.flaskUrl)
}
}, [])
const handleExport = async () => {