@muhgholy/next-drive 0.1.2 → 1.0.2

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/README.md CHANGED
@@ -61,8 +61,9 @@ export const drive = driveConfiguration({
61
61
  information: async (req): Promise<TDriveConfigInformation> => {
62
62
  // Implement your auth verification here
63
63
  const auth = await verifyAuth(req);
64
+ if (!auth) throw new Error("Unauthenticated");
64
65
  return {
65
- key: auth ? { userId: auth.userId } : null,
66
+ key: { userId: auth.userId },
66
67
  storage: { quotaInBytes: 1024 * 1024 * 1024 }, // 1GB limit
67
68
  };
68
69
  },
@@ -73,15 +74,16 @@ export const drive = driveConfiguration({
73
74
 
74
75
  Set up the API route handler that `next-drive` will use to communicate with the client.
75
76
 
76
- ```typescript
77
- // pages/api/drive.ts (Pages Router)
78
- // or app/api/drive/route.ts (App Router)
77
+ **Important:** The API route must be in the `pages` folder (Pages Router) for Next.js to handle the request properly.
79
78
 
80
- import { drive } from "@/lib/drive";
79
+ ```typescript
80
+ // pages/api/drive.ts
81
+ import "@/lib/drive";
81
82
  import { driveAPIHandler } from "@muhgholy/next-drive/server";
83
+ import type { NextApiRequest, NextApiResponse } from "next";
82
84
 
83
- export default function handler(req, res) {
84
- return driveAPIHandler(drive, req, res);
85
+ export default async function handler(req: NextApiRequest, res: NextApiResponse) {
86
+ return driveAPIHandler(req, res);
85
87
  }
86
88
  ```
87
89
 
@@ -125,6 +127,24 @@ function MyForm() {
125
127
  }
126
128
  ```
127
129
 
130
+ **Zod Validation:**
131
+
132
+ You can use the exported `driveFileSchemaZod` to validate file data in your forms or API routes.
133
+
134
+ ```typescript
135
+ import { z } from "zod";
136
+ import { driveFileSchemaZod } from "@muhgholy/next-drive/client";
137
+
138
+ // Use in your form schema
139
+ const myFormSchema = z.object({
140
+ asset: driveFileSchemaZod,
141
+ title: z.string(),
142
+ description: z.string().optional(),
143
+ });
144
+
145
+ type MyFormData = z.infer<typeof myFormSchema>;
146
+ ```
147
+
128
148
  ## Key Capabilities
129
149
 
130
150
  ### Server-Side File Access
@@ -1,5 +1,7 @@
1
1
  import React, { ReactNode } from 'react';
2
- import { l as TDrivePathItem, d as TDatabaseDrive, m as TDriveQuota, i as TDriveAPIResponse, n as TDriveUploadState, e as TDriveFile } from '../index-DE7-rwJm.js';
2
+ import { l as TDrivePathItem, d as TDatabaseDrive, m as TDriveQuota, i as TDriveAPIResponse, n as TDriveUploadState, e as TDriveFile } from '../index-CIbbTroj.js';
3
+ export { o as driveFileSchemaZod } from '../index-CIbbTroj.js';
4
+ import 'zod';
3
5
 
4
6
  type TDriveContext = {
5
7
  apiEndpoint: string;
@@ -111,11 +113,6 @@ declare const DriveUpload: (props: Readonly<{
111
113
  onComplete?: (item: unknown) => void;
112
114
  }>) => React.JSX.Element;
113
115
 
114
- declare const DriveFilePreview: (props: Readonly<{
115
- item: TDatabaseDrive;
116
- onClose: () => void;
117
- }>) => React.JSX.Element | null;
118
-
119
116
  declare const DriveStorageIndicator: (props: Readonly<{
120
117
  compact?: boolean;
121
118
  className?: string;
@@ -125,4 +122,4 @@ declare const DriveHeader: () => React.JSX.Element;
125
122
 
126
123
  declare const DriveSidebar: () => React.JSX.Element;
127
124
 
128
- export { DriveExplorer, DriveFileChooser, DriveFilePreview, DriveHeader, DrivePathBar, DriveProvider, DriveSidebar, DriveStorageIndicator, DriveUpload, type TDriveContext, TDriveFile, useDrive, useUpload };
125
+ export { DriveExplorer, DriveFileChooser, DriveHeader, DrivePathBar, DriveProvider, DriveSidebar, DriveStorageIndicator, DriveUpload, type TDriveContext, TDriveFile, useDrive, useUpload };