refactor: migrate direct fetch calls to API handler pattern

Replace raw fetch() in settings, share-key, and import-shared with
centralized API handlers via src/lib/api.ts. Also auto-create the data/
directory on startup so the SQLite db path is always valid.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
VarunandClaude Sonnet 4.6 committed 2026-04-03 19:34:09 +05:30
1 parent 362f6d861b
commit eafb44a4e9
9 files changed
+91 -62

No files matched your search

+6 -7
View File
@@ -3,6 +3,7 @@ import { Dialog, DialogTitle, DialogContent, DialogHeader, DialogTrigger, Dialog
import { Button, ButtonProps } from '../ui/button';
import { ShareLinkFilters } from '@/types/shareLink';
import { generateShareLink } from '@/handlers/api/shareLink.handler';
import { createShareKey, getShareKey } from '@/handlers/api/share-key.handler';
import { Input } from '../ui/input';
import { Label } from '@radix-ui/react-label';
@@ -28,8 +29,7 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets
const [keyError, setKeyError] = useState<string | null>(null);
const checkShareKey = async () => {
const res = await fetch('/api/share-key');
const data = await res.json();
const data = await getShareKey();
setEndpointConfigured(data.endpointConfigured);
setShareKeyExists(data.exists);
};
@@ -37,12 +37,11 @@ export default function ShareAssetsTrigger({ filters, buttonProps }: ShareAssets
const handleCreateKey = async () => {
setCreatingKey(true);
setKeyError(null);
const res = await fetch('/api/share-key', { method: 'POST' });
if (res.ok) {
try {
await createShareKey();
setShareKeyExists(true);
} else {
const data = await res.json();
setKeyError(data.message ?? 'Failed to create share key');
} catch (err: any) {
setKeyError(err.message ?? 'Failed to create share key');
}
setCreatingKey(false);
};