|
381 | 381 | } |
382 | 382 | } |
383 | 383 |
|
| 384 | + async function exportConfig(slug: string) { |
| 385 | + try { |
| 386 | + const response = await fetch(`/api/configs/${slug}`); |
| 387 | + const data = await response.json(); |
| 388 | + const config = data.config; |
| 389 | + const exported = { |
| 390 | + name: config.name, |
| 391 | + description: config.description || '', |
| 392 | + base_preset: config.base_preset, |
| 393 | + packages: config.packages || [], |
| 394 | + custom_script: config.custom_script || '', |
| 395 | + dotfiles_repo: config.dotfiles_repo || '', |
| 396 | + snapshot: config.snapshot || null, |
| 397 | + visibility: config.visibility || 'unlisted', |
| 398 | + alias: config.alias || null |
| 399 | + }; |
| 400 | + const blob = new Blob([JSON.stringify(exported, null, 2)], { type: 'application/json' }); |
| 401 | + const url = URL.createObjectURL(blob); |
| 402 | + const a = document.createElement('a'); |
| 403 | + a.href = url; |
| 404 | + a.download = `${slug}.json`; |
| 405 | + a.click(); |
| 406 | + URL.revokeObjectURL(url); |
| 407 | + } catch (e) { |
| 408 | + alert('Failed to export configuration'); |
| 409 | + } |
| 410 | + } |
| 411 | +
|
384 | 412 | function copyToClipboard(text: string, configId: string) { |
385 | 413 | navigator.clipboard.writeText(text); |
386 | 414 | copiedId = configId; |
|
556 | 584 | <Button variant="secondary" onclick={() => editConfig(config.slug)}>Edit</Button> |
557 | 585 | <Button variant="secondary" onclick={() => duplicateConfig(config.slug)}>Duplicate</Button> |
558 | 586 | <Button variant="secondary" onclick={() => shareConfig(config)}>Share</Button> |
| 587 | + <Button variant="secondary" onclick={() => exportConfig(config.slug)}>Export</Button> |
559 | 588 | <Button variant="danger" onclick={() => deleteConfig(config.slug)}>Delete</Button> |
560 | 589 | </div> |
561 | 590 | </div> |
|
0 commit comments