@blu1606/create-walrus-app 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.js +1 -0
- package/dist/generator/layers.js +3 -0
- package/dist/index.js +1 -0
- package/dist/post-install/index.js +5 -0
- package/dist/post-install/walrus-deploy.d.ts +6 -0
- package/dist/post-install/walrus-deploy.js +77 -0
- package/dist/prompts.js +17 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/presets/react-mysten-gallery/README.md +60 -0
- package/presets/react-mysten-gallery/package.json +2 -1
- package/presets/react-mysten-gallery/scripts/setup-walrus-deploy.sh +282 -0
- package/presets/react-mysten-simple-upload/README.md +60 -0
- package/presets/react-mysten-simple-upload/package.json +2 -1
- package/presets/react-mysten-simple-upload/scripts/setup-walrus-deploy.sh +286 -0
- package/presets/react-mysten-simple-upload-enoki/.env.example +40 -0
- package/presets/react-mysten-simple-upload-enoki/.gitkeep +4 -0
- package/presets/react-mysten-simple-upload-enoki/README.md +332 -0
- package/presets/react-mysten-simple-upload-enoki/index.html +13 -0
- package/presets/react-mysten-simple-upload-enoki/package.json +37 -0
- package/presets/react-mysten-simple-upload-enoki/scripts/setup-walrus-deploy.sh +286 -0
- package/presets/react-mysten-simple-upload-enoki/src/App.tsx +27 -0
- package/presets/react-mysten-simple-upload-enoki/src/components/features/enoki-auth-button.tsx +29 -0
- package/presets/react-mysten-simple-upload-enoki/src/components/features/file-preview.tsx +73 -0
- package/presets/react-mysten-simple-upload-enoki/src/components/features/upload-form.tsx +61 -0
- package/presets/react-mysten-simple-upload-enoki/src/components/features/wallet-connect.tsx +38 -0
- package/presets/react-mysten-simple-upload-enoki/src/components/layout/app-layout.tsx +21 -0
- package/presets/react-mysten-simple-upload-enoki/src/hooks/use-download.ts +24 -0
- package/presets/react-mysten-simple-upload-enoki/src/hooks/use-enoki-auth.ts +52 -0
- package/presets/react-mysten-simple-upload-enoki/src/hooks/use-upload.ts +45 -0
- package/presets/react-mysten-simple-upload-enoki/src/hooks/use-wallet.ts +32 -0
- package/presets/react-mysten-simple-upload-enoki/src/index.css +322 -0
- package/presets/react-mysten-simple-upload-enoki/src/index.ts +24 -0
- package/presets/react-mysten-simple-upload-enoki/src/lib/enoki/constants.ts +23 -0
- package/presets/react-mysten-simple-upload-enoki/src/lib/enoki/index.ts +6 -0
- package/presets/react-mysten-simple-upload-enoki/src/lib/enoki/storage-adapter.ts +31 -0
- package/presets/react-mysten-simple-upload-enoki/src/lib/walrus/adapter.ts +197 -0
- package/presets/react-mysten-simple-upload-enoki/src/lib/walrus/client.ts +87 -0
- package/presets/react-mysten-simple-upload-enoki/src/lib/walrus/index.ts +4 -0
- package/presets/react-mysten-simple-upload-enoki/src/lib/walrus/types.ts +92 -0
- package/presets/react-mysten-simple-upload-enoki/src/main.tsx +19 -0
- package/presets/react-mysten-simple-upload-enoki/src/providers/EnokiProvider.tsx +23 -0
- package/presets/react-mysten-simple-upload-enoki/src/providers/QueryProvider.tsx +18 -0
- package/presets/react-mysten-simple-upload-enoki/src/providers/WalletProvider.tsx +52 -0
- package/presets/react-mysten-simple-upload-enoki/src/providers/index.ts +7 -0
- package/presets/react-mysten-simple-upload-enoki/src/utils/env.ts +41 -0
- package/presets/react-mysten-simple-upload-enoki/src/utils/mime-type.ts +97 -0
- package/presets/react-mysten-simple-upload-enoki/tsconfig.json +39 -0
- package/presets/react-mysten-simple-upload-enoki/tsconfig.node.json +10 -0
- package/presets/react-mysten-simple-upload-enoki/vite.config.ts +19 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { walrus, WalrusClient } from '@mysten/walrus';
|
|
2
|
+
import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
|
|
3
|
+
import { loadEnv } from '../../utils/env.js';
|
|
4
|
+
|
|
5
|
+
// Types
|
|
6
|
+
export type WalrusNetwork = 'testnet' | 'mainnet';
|
|
7
|
+
|
|
8
|
+
export interface MystenWalrusConfig {
|
|
9
|
+
network: WalrusNetwork;
|
|
10
|
+
publisherUrl?: string;
|
|
11
|
+
aggregatorUrl?: string;
|
|
12
|
+
suiRpcUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type WalrusExtendedClient = SuiClient & { walrus: WalrusClient };
|
|
16
|
+
|
|
17
|
+
// Network Configurations
|
|
18
|
+
const NETWORK_CONFIGS: Record<WalrusNetwork, MystenWalrusConfig> = {
|
|
19
|
+
testnet: {
|
|
20
|
+
network: 'testnet',
|
|
21
|
+
publisherUrl: 'https://publisher.walrus-testnet.walrus.space',
|
|
22
|
+
aggregatorUrl: 'https://aggregator.walrus-testnet.walrus.space',
|
|
23
|
+
suiRpcUrl: 'https://fullnode.testnet.sui.io:443',
|
|
24
|
+
},
|
|
25
|
+
mainnet: {
|
|
26
|
+
network: 'mainnet',
|
|
27
|
+
publisherUrl: 'https://publisher.walrus.space',
|
|
28
|
+
aggregatorUrl: 'https://aggregator.walrus.space',
|
|
29
|
+
suiRpcUrl: 'https://fullnode.mainnet.sui.io:443',
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function getNetworkConfig(network: WalrusNetwork): MystenWalrusConfig {
|
|
34
|
+
return NETWORK_CONFIGS[network];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Client Management
|
|
38
|
+
let walrusClient: WalrusExtendedClient | null = null;
|
|
39
|
+
|
|
40
|
+
export function getWalrusClient(): WalrusExtendedClient {
|
|
41
|
+
if (walrusClient) {
|
|
42
|
+
return walrusClient;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const env = loadEnv();
|
|
46
|
+
|
|
47
|
+
// Validate network value before casting
|
|
48
|
+
const allowedNetworks: WalrusNetwork[] = ['testnet', 'mainnet'];
|
|
49
|
+
if (!allowedNetworks.includes(env.walrusNetwork as WalrusNetwork)) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Invalid WALRUS_NETWORK: ${env.walrusNetwork}. Must be one of: ${allowedNetworks.join(', ')}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const network = env.walrusNetwork as WalrusNetwork;
|
|
55
|
+
const config = getNetworkConfig(network);
|
|
56
|
+
|
|
57
|
+
// Use SuiClient (required for Walrus SDK and CoinWithBalance intent)
|
|
58
|
+
const suiClient = new SuiClient({
|
|
59
|
+
url:
|
|
60
|
+
env.suiRpc ||
|
|
61
|
+
config.suiRpcUrl ||
|
|
62
|
+
getFullnodeUrl(network === 'testnet' ? 'testnet' : 'mainnet'),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Extend the client with Walrus capabilities and upload relay
|
|
66
|
+
walrusClient = suiClient.$extend(
|
|
67
|
+
walrus({
|
|
68
|
+
network: network, // REQUIRED: Walrus SDK needs to know which network
|
|
69
|
+
// Use CDN for WASM - more reliable than bundler resolution
|
|
70
|
+
wasmUrl: 'https://unpkg.com/@mysten/walrus-wasm@latest/web/walrus_wasm_bg.wasm',
|
|
71
|
+
uploadRelay: {
|
|
72
|
+
host:
|
|
73
|
+
env.walrusPublisher ||
|
|
74
|
+
config.publisherUrl ||
|
|
75
|
+
`https://upload-relay.${network}.walrus.space`,
|
|
76
|
+
sendTip: null, // Skip tip config fetch to avoid CORS issues in development
|
|
77
|
+
},
|
|
78
|
+
...(env.walrusAggregator && { aggregatorUrl: env.walrusAggregator }),
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
return walrusClient;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function resetWalrusClient(): void {
|
|
86
|
+
walrusClient = null;
|
|
87
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Universal storage adapter interface for Walrus
|
|
3
|
+
*
|
|
4
|
+
* This interface abstracts SDK-specific implementations,
|
|
5
|
+
* allowing use case layers to work with any Walrus SDK.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { SuiClient } from '@mysten/sui/client';
|
|
9
|
+
import type { Transaction } from '@mysten/sui/transactions';
|
|
10
|
+
|
|
11
|
+
export interface BlobMetadata {
|
|
12
|
+
blobId: string;
|
|
13
|
+
size: number;
|
|
14
|
+
contentType?: string;
|
|
15
|
+
createdAt: number;
|
|
16
|
+
expiresAt?: number;
|
|
17
|
+
/** Original filename with extension */
|
|
18
|
+
fileName?: string;
|
|
19
|
+
/** All tags from WalrusFile */
|
|
20
|
+
tags?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SignAndExecuteTransactionArgs {
|
|
24
|
+
transaction: Transaction;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SignAndExecuteTransactionResult {
|
|
28
|
+
digest: string;
|
|
29
|
+
effects?: unknown;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Unified signer interface
|
|
34
|
+
*
|
|
35
|
+
* Compatible with both zkLogin (Enoki) and standard Sui wallets
|
|
36
|
+
*/
|
|
37
|
+
export interface UnifiedSigner {
|
|
38
|
+
address: string;
|
|
39
|
+
signAndExecuteTransaction: (
|
|
40
|
+
args: SignAndExecuteTransactionArgs
|
|
41
|
+
) => Promise<SignAndExecuteTransactionResult>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface UploadOptions {
|
|
45
|
+
/** Number of epochs to store (Walrus-specific) */
|
|
46
|
+
epochs?: number;
|
|
47
|
+
/** MIME type of the content */
|
|
48
|
+
contentType?: string;
|
|
49
|
+
/** Sui client with Walrus extension (from useSuiClient hook) */
|
|
50
|
+
client?: SuiClient;
|
|
51
|
+
/** Wallet signer for authenticated uploads */
|
|
52
|
+
signer?: UnifiedSigner;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface DownloadOptions {
|
|
56
|
+
/** Byte range (for large files) */
|
|
57
|
+
range?: { start: number; end: number };
|
|
58
|
+
/** Output format - auto-detects if not specified */
|
|
59
|
+
format?: 'bytes' | 'text' | 'json';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface StorageAdapter {
|
|
63
|
+
/**
|
|
64
|
+
* Upload data to Walrus storage
|
|
65
|
+
* @param data - File or raw bytes to upload
|
|
66
|
+
* @param options - Upload configuration
|
|
67
|
+
* @returns Blob ID (permanent reference)
|
|
68
|
+
*/
|
|
69
|
+
upload(data: File | Uint8Array, options?: UploadOptions): Promise<string>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Download blob data by ID
|
|
73
|
+
* @param blobId - Unique blob identifier
|
|
74
|
+
* @param options - Download configuration
|
|
75
|
+
* @returns Blob data in requested format (Uint8Array, string, or JSON)
|
|
76
|
+
*/
|
|
77
|
+
download(blobId: string, options?: DownloadOptions): Promise<Uint8Array | string | unknown>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get blob metadata without downloading content
|
|
81
|
+
* @param blobId - Unique blob identifier
|
|
82
|
+
* @returns Metadata object
|
|
83
|
+
*/
|
|
84
|
+
getMetadata(blobId: string): Promise<BlobMetadata>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Check if blob exists
|
|
88
|
+
* @param blobId - Unique blob identifier
|
|
89
|
+
* @returns True if blob is accessible
|
|
90
|
+
*/
|
|
91
|
+
exists(blobId: string): Promise<boolean>;
|
|
92
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom/client';
|
|
3
|
+
import { QueryProvider } from './providers/QueryProvider.js';
|
|
4
|
+
import { EnokiProvider } from './providers/EnokiProvider.js';
|
|
5
|
+
import { WalletProvider } from './providers/WalletProvider.js';
|
|
6
|
+
import App from './App.js';
|
|
7
|
+
import './index.css';
|
|
8
|
+
|
|
9
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
10
|
+
<React.StrictMode>
|
|
11
|
+
<QueryProvider>
|
|
12
|
+
<EnokiProvider>
|
|
13
|
+
<WalletProvider>
|
|
14
|
+
<App />
|
|
15
|
+
</WalletProvider>
|
|
16
|
+
</EnokiProvider>
|
|
17
|
+
</QueryProvider>
|
|
18
|
+
</React.StrictMode>
|
|
19
|
+
);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EnokiFlowProvider } from '@mysten/enoki/react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { enokiConfig, sessionStorageAdapter } from '../lib/enoki/index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* EnokiProvider wraps the app with zkLogin authentication support
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Google OAuth via Enoki zkLogin
|
|
10
|
+
* - Tab-isolated sessions (sessionStorage)
|
|
11
|
+
* - Environment validation with Zod
|
|
12
|
+
*/
|
|
13
|
+
export function EnokiProvider({ children }: { children: ReactNode }) {
|
|
14
|
+
return (
|
|
15
|
+
<EnokiFlowProvider
|
|
16
|
+
apiKey={enokiConfig.VITE_ENOKI_API_KEY}
|
|
17
|
+
storageAdapter={sessionStorageAdapter}
|
|
18
|
+
storageKey="enoki:walrus-upload"
|
|
19
|
+
>
|
|
20
|
+
{children}
|
|
21
|
+
</EnokiFlowProvider>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
const queryClient = new QueryClient({
|
|
5
|
+
defaultOptions: {
|
|
6
|
+
queries: {
|
|
7
|
+
refetchOnWindowFocus: false,
|
|
8
|
+
retry: 1,
|
|
9
|
+
staleTime: 5 * 60 * 1000,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export function QueryProvider({ children }: { children: ReactNode }) {
|
|
15
|
+
return (
|
|
16
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createNetworkConfig,
|
|
3
|
+
SuiClientProvider,
|
|
4
|
+
WalletProvider as SuiWalletProvider,
|
|
5
|
+
} from '@mysten/dapp-kit';
|
|
6
|
+
import { getFullnodeUrl, SuiClient } from '@mysten/sui/client';
|
|
7
|
+
import { walrus } from '@mysten/walrus';
|
|
8
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
9
|
+
import { ReactNode } from 'react';
|
|
10
|
+
import { loadEnv } from '../utils/env.js';
|
|
11
|
+
|
|
12
|
+
const env = loadEnv();
|
|
13
|
+
|
|
14
|
+
const validatedNetwork =
|
|
15
|
+
env.suiNetwork === 'mainnet' || env.suiNetwork === 'testnet'
|
|
16
|
+
? env.suiNetwork
|
|
17
|
+
: 'testnet';
|
|
18
|
+
|
|
19
|
+
const { networkConfig } = createNetworkConfig({
|
|
20
|
+
[validatedNetwork]: {
|
|
21
|
+
url: env.suiRpc || getFullnodeUrl(validatedNetwork),
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const walletQueryClient = new QueryClient();
|
|
26
|
+
|
|
27
|
+
export function WalletProvider({ children }: { children: ReactNode }) {
|
|
28
|
+
return (
|
|
29
|
+
<QueryClientProvider client={walletQueryClient}>
|
|
30
|
+
<SuiClientProvider
|
|
31
|
+
networks={networkConfig}
|
|
32
|
+
defaultNetwork={validatedNetwork}
|
|
33
|
+
createClient={(network: string | number, config: { readonly url: string }) => {
|
|
34
|
+
// Create SuiClient with Walrus extension
|
|
35
|
+
const client = new SuiClient({
|
|
36
|
+
url: config.url,
|
|
37
|
+
}).$extend(
|
|
38
|
+
walrus({
|
|
39
|
+
network: network as 'testnet' | 'mainnet',
|
|
40
|
+
wasmUrl: 'https://unpkg.com/@mysten/walrus-wasm@latest/web/walrus_wasm_bg.wasm',
|
|
41
|
+
// No uploadRelay - upload directly to storage nodes
|
|
42
|
+
// This avoids tip payment requirements but uses ~2200 requests
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
return client;
|
|
46
|
+
}}
|
|
47
|
+
>
|
|
48
|
+
<SuiWalletProvider>{children}</SuiWalletProvider>
|
|
49
|
+
</SuiClientProvider>
|
|
50
|
+
</QueryClientProvider>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface EnvConfig {
|
|
2
|
+
walrusNetwork: string;
|
|
3
|
+
walrusAggregator: string;
|
|
4
|
+
walrusPublisher: string;
|
|
5
|
+
suiNetwork: string;
|
|
6
|
+
suiRpc: string;
|
|
7
|
+
blockberryKey?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function loadEnv(): EnvConfig {
|
|
11
|
+
const getEnv = (key: string, required = true): string => {
|
|
12
|
+
const value = import.meta.env[key];
|
|
13
|
+
if (required && !value) {
|
|
14
|
+
throw new Error(`Missing required environment variable: ${key}`);
|
|
15
|
+
}
|
|
16
|
+
return value || '';
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
walrusNetwork: getEnv('VITE_WALRUS_NETWORK'),
|
|
21
|
+
walrusAggregator: getEnv('VITE_WALRUS_AGGREGATOR'),
|
|
22
|
+
walrusPublisher: getEnv('VITE_WALRUS_PUBLISHER'),
|
|
23
|
+
suiNetwork: getEnv('VITE_SUI_NETWORK'),
|
|
24
|
+
suiRpc: getEnv('VITE_SUI_RPC'),
|
|
25
|
+
blockberryKey: getEnv('VITE_BLOCKBERRY_KEY', false),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function validateEnv(config: EnvConfig): void {
|
|
30
|
+
if (!['testnet', 'mainnet', 'devnet'].includes(config.walrusNetwork)) {
|
|
31
|
+
throw new Error(`Invalid WALRUS_NETWORK: ${config.walrusNetwork}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!config.walrusAggregator.startsWith('http')) {
|
|
35
|
+
throw new Error('WALRUS_AGGREGATOR must be a valid HTTP URL');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!config.walrusPublisher.startsWith('http')) {
|
|
39
|
+
throw new Error('WALRUS_PUBLISHER must be a valid HTTP URL');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIME type detection from file extensions
|
|
3
|
+
* Handles common file types that browsers may not auto-detect
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const MIME_TYPES: Record<string, string> = {
|
|
7
|
+
// Text formats
|
|
8
|
+
'.txt': 'text/plain',
|
|
9
|
+
'.md': 'text/markdown',
|
|
10
|
+
'.markdown': 'text/markdown',
|
|
11
|
+
'.csv': 'text/csv',
|
|
12
|
+
'.html': 'text/html',
|
|
13
|
+
'.css': 'text/css',
|
|
14
|
+
'.js': 'text/javascript',
|
|
15
|
+
'.ts': 'text/typescript',
|
|
16
|
+
'.json': 'application/json',
|
|
17
|
+
'.xml': 'application/xml',
|
|
18
|
+
|
|
19
|
+
// Images
|
|
20
|
+
'.jpg': 'image/jpeg',
|
|
21
|
+
'.jpeg': 'image/jpeg',
|
|
22
|
+
'.png': 'image/png',
|
|
23
|
+
'.gif': 'image/gif',
|
|
24
|
+
'.svg': 'image/svg+xml',
|
|
25
|
+
'.webp': 'image/webp',
|
|
26
|
+
'.ico': 'image/x-icon',
|
|
27
|
+
|
|
28
|
+
// Documents
|
|
29
|
+
'.pdf': 'application/pdf',
|
|
30
|
+
'.doc': 'application/msword',
|
|
31
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
32
|
+
'.xls': 'application/vnd.ms-excel',
|
|
33
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
34
|
+
'.ppt': 'application/vnd.ms-powerpoint',
|
|
35
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
36
|
+
|
|
37
|
+
// Archives
|
|
38
|
+
'.zip': 'application/zip',
|
|
39
|
+
'.rar': 'application/x-rar-compressed',
|
|
40
|
+
'.tar': 'application/x-tar',
|
|
41
|
+
'.gz': 'application/gzip',
|
|
42
|
+
'.7z': 'application/x-7z-compressed',
|
|
43
|
+
|
|
44
|
+
// Audio
|
|
45
|
+
'.mp3': 'audio/mpeg',
|
|
46
|
+
'.wav': 'audio/wav',
|
|
47
|
+
'.ogg': 'audio/ogg',
|
|
48
|
+
'.m4a': 'audio/mp4',
|
|
49
|
+
|
|
50
|
+
// Video
|
|
51
|
+
'.mp4': 'video/mp4',
|
|
52
|
+
'.webm': 'video/webm',
|
|
53
|
+
'.avi': 'video/x-msvideo',
|
|
54
|
+
'.mov': 'video/quicktime',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Detect MIME type from filename
|
|
59
|
+
* @param fileName - File name with extension
|
|
60
|
+
* @returns MIME type or null if not found
|
|
61
|
+
*/
|
|
62
|
+
export function getMimeTypeFromFileName(fileName: string): string | null {
|
|
63
|
+
const extension = fileName.toLowerCase().match(/\.[^.]+$/)?.[0];
|
|
64
|
+
if (!extension) return null;
|
|
65
|
+
|
|
66
|
+
return MIME_TYPES[extension] || null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get content type with fallback logic
|
|
71
|
+
* Priority: explicit contentType > File.type > extension detection > fallback
|
|
72
|
+
* @param file - File object, Uint8Array, or filename
|
|
73
|
+
* @param explicitType - Explicitly provided content type
|
|
74
|
+
* @returns Best-match content type
|
|
75
|
+
*/
|
|
76
|
+
export function getContentType(
|
|
77
|
+
file: File | Uint8Array | string,
|
|
78
|
+
explicitType?: string
|
|
79
|
+
): string {
|
|
80
|
+
// Priority 1: Explicit content type
|
|
81
|
+
if (explicitType) return explicitType;
|
|
82
|
+
|
|
83
|
+
// Priority 2: File.type (if not empty and not generic)
|
|
84
|
+
if (file instanceof File && file.type && file.type !== 'application/octet-stream') {
|
|
85
|
+
return file.type;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Priority 3: Detect from filename extension
|
|
89
|
+
const fileName = typeof file === 'string' ? file : file instanceof File ? file.name : '';
|
|
90
|
+
if (fileName) {
|
|
91
|
+
const detectedType = getMimeTypeFromFileName(fileName);
|
|
92
|
+
if (detectedType) return detectedType;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Fallback: Generic binary
|
|
96
|
+
return 'application/octet-stream';
|
|
97
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": [
|
|
6
|
+
"ES2020",
|
|
7
|
+
"DOM",
|
|
8
|
+
"DOM.Iterable"
|
|
9
|
+
],
|
|
10
|
+
"module": "ESNext",
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
"jsx": "react-jsx",
|
|
18
|
+
"types": [
|
|
19
|
+
"vite/client"
|
|
20
|
+
],
|
|
21
|
+
"strict": true,
|
|
22
|
+
"noUnusedLocals": true,
|
|
23
|
+
"noUnusedParameters": true,
|
|
24
|
+
"noFallthroughCasesInSwitch": true,
|
|
25
|
+
"paths": {
|
|
26
|
+
"@/*": [
|
|
27
|
+
"./src/*"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"include": [
|
|
32
|
+
"src"
|
|
33
|
+
],
|
|
34
|
+
"references": [
|
|
35
|
+
{
|
|
36
|
+
"path": "./tsconfig.node.json"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
plugins: [react()],
|
|
6
|
+
server: {
|
|
7
|
+
port: 3000,
|
|
8
|
+
open: true,
|
|
9
|
+
},
|
|
10
|
+
build: {
|
|
11
|
+
target: 'esnext',
|
|
12
|
+
outDir: 'dist',
|
|
13
|
+
},
|
|
14
|
+
resolve: {
|
|
15
|
+
alias: {
|
|
16
|
+
'@': '/src',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
});
|