vibesuite 1.3.2 → 2.0.1
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 +8 -1
- package/assets/.agent/skills/avoid-feature-creep/SKILL.md +307 -0
- package/assets/.agent/skills/avoid-feature-creep/agents/openai.yaml +3 -0
- package/assets/.agent/skills/avoid-feature-creep/assets/large-logo.png +0 -0
- package/assets/.agent/skills/avoid-feature-creep/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex/SKILL.md +62 -0
- package/assets/.agent/skills/convex/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-agents/SKILL.md +516 -0
- package/assets/.agent/skills/convex-agents/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-agents/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-agents/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-best-practices/SKILL.md +369 -0
- package/assets/.agent/skills/convex-best-practices/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-best-practices/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-best-practices/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-component-authoring/SKILL.md +457 -0
- package/assets/.agent/skills/convex-component-authoring/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-component-authoring/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-component-authoring/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-cron-jobs/SKILL.md +604 -0
- package/assets/.agent/skills/convex-cron-jobs/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-cron-jobs/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-cron-jobs/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-file-storage/SKILL.md +467 -0
- package/assets/.agent/skills/convex-file-storage/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-file-storage/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-file-storage/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-functions/SKILL.md +458 -0
- package/assets/.agent/skills/convex-functions/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-functions/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-functions/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-http-actions/SKILL.md +733 -0
- package/assets/.agent/skills/convex-http-actions/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-http-actions/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-http-actions/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-migrations/SKILL.md +712 -0
- package/assets/.agent/skills/convex-migrations/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-migrations/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-migrations/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-realtime/SKILL.md +443 -0
- package/assets/.agent/skills/convex-realtime/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-realtime/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-realtime/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-schema-validator/SKILL.md +400 -0
- package/assets/.agent/skills/convex-schema-validator/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-schema-validator/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-schema-validator/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-security-audit/SKILL.md +539 -0
- package/assets/.agent/skills/convex-security-audit/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-security-audit/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-security-audit/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/convex-security-check/SKILL.md +378 -0
- package/assets/.agent/skills/convex-security-check/agents/openai.yaml +3 -0
- package/assets/.agent/skills/convex-security-check/assets/large-logo.png +0 -0
- package/assets/.agent/skills/convex-security-check/assets/small-logo.svg +17 -0
- package/assets/.agent/skills/github-ops/SKILL.md +4 -4
- package/assets/.agent/skills/google-trends/SKILL.md +7 -7
- package/assets/.agent/skills/optimize-agent-context/SKILL.md +97 -0
- package/assets/.agent/skills/youtube-pipeline/SKILL.md +10 -10
- package/assets/.agent/workflows/LEGACY/init_smart_ops.md +2 -2
- package/assets/.agent/workflows/agent_reset.md +2 -2
- package/assets/.agent/workflows/mode-orchestrator.md +114 -640
- package/assets/.agent/workflows/mode-visionary.md +192 -0
- package/assets/.agent/workflows/optimize-agent-context.md +54 -0
- package/assets/.agent/workflows/remotion-build.md +17 -17
- package/assets/.agent/workflows/stitch.md +4 -4
- package/assets/VibeCode-Agents/custom_modes.yaml +1257 -0
- package/assets/VibeCode-Agents/vibe-orchestrator.yaml +427 -145
- package/assets/VibeCode-Agents/vibe-visionary.yaml +617 -0
- package/package.json +2 -2
- package/src/cli.js +416 -20
- package/src/harness.js +281 -0
- package/src/store.js +239 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: convex-file-storage
|
|
3
|
+
displayName: Convex File Storage
|
|
4
|
+
description: Complete file handling including upload flows, serving files via URL, storing generated files from actions, deletion, and accessing file metadata from system tables
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
author: Convex
|
|
7
|
+
tags: [convex, file-storage, uploads, images, files]
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Convex File Storage
|
|
11
|
+
|
|
12
|
+
Handle file uploads, storage, serving, and management in Convex applications with proper patterns for images, documents, and generated files.
|
|
13
|
+
|
|
14
|
+
## Documentation Sources
|
|
15
|
+
|
|
16
|
+
Before implementing, do not assume; fetch the latest documentation:
|
|
17
|
+
|
|
18
|
+
- Primary: https://docs.convex.dev/file-storage
|
|
19
|
+
- Upload Files: https://docs.convex.dev/file-storage/upload-files
|
|
20
|
+
- Serve Files: https://docs.convex.dev/file-storage/serve-files
|
|
21
|
+
- For broader context: https://docs.convex.dev/llms.txt
|
|
22
|
+
|
|
23
|
+
## Instructions
|
|
24
|
+
|
|
25
|
+
### File Storage Overview
|
|
26
|
+
|
|
27
|
+
Convex provides built-in file storage with:
|
|
28
|
+
- Automatic URL generation for serving files
|
|
29
|
+
- Support for any file type (images, PDFs, videos, etc.)
|
|
30
|
+
- File metadata via the `_storage` system table
|
|
31
|
+
- Integration with mutations and actions
|
|
32
|
+
|
|
33
|
+
### Generating Upload URLs
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// convex/files.ts
|
|
37
|
+
import { mutation } from "./_generated/server";
|
|
38
|
+
import { v } from "convex/values";
|
|
39
|
+
|
|
40
|
+
export const generateUploadUrl = mutation({
|
|
41
|
+
args: {},
|
|
42
|
+
returns: v.string(),
|
|
43
|
+
handler: async (ctx) => {
|
|
44
|
+
return await ctx.storage.generateUploadUrl();
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Client-Side Upload
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// React component
|
|
53
|
+
import { useMutation } from "convex/react";
|
|
54
|
+
import { api } from "../convex/_generated/api";
|
|
55
|
+
import { useState } from "react";
|
|
56
|
+
|
|
57
|
+
function FileUploader() {
|
|
58
|
+
const generateUploadUrl = useMutation(api.files.generateUploadUrl);
|
|
59
|
+
const saveFile = useMutation(api.files.saveFile);
|
|
60
|
+
const [uploading, setUploading] = useState(false);
|
|
61
|
+
|
|
62
|
+
const handleUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
63
|
+
const file = e.target.files?.[0];
|
|
64
|
+
if (!file) return;
|
|
65
|
+
|
|
66
|
+
setUploading(true);
|
|
67
|
+
try {
|
|
68
|
+
// Step 1: Get upload URL
|
|
69
|
+
const uploadUrl = await generateUploadUrl();
|
|
70
|
+
|
|
71
|
+
// Step 2: Upload file to storage
|
|
72
|
+
const result = await fetch(uploadUrl, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: { "Content-Type": file.type },
|
|
75
|
+
body: file,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const { storageId } = await result.json();
|
|
79
|
+
|
|
80
|
+
// Step 3: Save file reference to database
|
|
81
|
+
await saveFile({
|
|
82
|
+
storageId,
|
|
83
|
+
fileName: file.name,
|
|
84
|
+
fileType: file.type,
|
|
85
|
+
fileSize: file.size,
|
|
86
|
+
});
|
|
87
|
+
} finally {
|
|
88
|
+
setUploading(false);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div>
|
|
94
|
+
<input
|
|
95
|
+
type="file"
|
|
96
|
+
onChange={handleUpload}
|
|
97
|
+
disabled={uploading}
|
|
98
|
+
/>
|
|
99
|
+
{uploading && <p>Uploading...</p>}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Saving File References
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// convex/files.ts
|
|
109
|
+
import { mutation, query } from "./_generated/server";
|
|
110
|
+
import { v } from "convex/values";
|
|
111
|
+
|
|
112
|
+
export const saveFile = mutation({
|
|
113
|
+
args: {
|
|
114
|
+
storageId: v.id("_storage"),
|
|
115
|
+
fileName: v.string(),
|
|
116
|
+
fileType: v.string(),
|
|
117
|
+
fileSize: v.number(),
|
|
118
|
+
},
|
|
119
|
+
returns: v.id("files"),
|
|
120
|
+
handler: async (ctx, args) => {
|
|
121
|
+
return await ctx.db.insert("files", {
|
|
122
|
+
storageId: args.storageId,
|
|
123
|
+
fileName: args.fileName,
|
|
124
|
+
fileType: args.fileType,
|
|
125
|
+
fileSize: args.fileSize,
|
|
126
|
+
uploadedAt: Date.now(),
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Serving Files via URL
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
// convex/files.ts
|
|
136
|
+
export const getFileUrl = query({
|
|
137
|
+
args: { storageId: v.id("_storage") },
|
|
138
|
+
returns: v.union(v.string(), v.null()),
|
|
139
|
+
handler: async (ctx, args) => {
|
|
140
|
+
return await ctx.storage.getUrl(args.storageId);
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Get file with URL
|
|
145
|
+
export const getFile = query({
|
|
146
|
+
args: { fileId: v.id("files") },
|
|
147
|
+
returns: v.union(
|
|
148
|
+
v.object({
|
|
149
|
+
_id: v.id("files"),
|
|
150
|
+
fileName: v.string(),
|
|
151
|
+
fileType: v.string(),
|
|
152
|
+
fileSize: v.number(),
|
|
153
|
+
url: v.union(v.string(), v.null()),
|
|
154
|
+
}),
|
|
155
|
+
v.null()
|
|
156
|
+
),
|
|
157
|
+
handler: async (ctx, args) => {
|
|
158
|
+
const file = await ctx.db.get(args.fileId);
|
|
159
|
+
if (!file) return null;
|
|
160
|
+
|
|
161
|
+
const url = await ctx.storage.getUrl(file.storageId);
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
_id: file._id,
|
|
165
|
+
fileName: file.fileName,
|
|
166
|
+
fileType: file.fileType,
|
|
167
|
+
fileSize: file.fileSize,
|
|
168
|
+
url,
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Displaying Files in React
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { useQuery } from "convex/react";
|
|
178
|
+
import { api } from "../convex/_generated/api";
|
|
179
|
+
|
|
180
|
+
function FileDisplay({ fileId }: { fileId: Id<"files"> }) {
|
|
181
|
+
const file = useQuery(api.files.getFile, { fileId });
|
|
182
|
+
|
|
183
|
+
if (!file) return <div>Loading...</div>;
|
|
184
|
+
if (!file.url) return <div>File not found</div>;
|
|
185
|
+
|
|
186
|
+
// Handle different file types
|
|
187
|
+
if (file.fileType.startsWith("image/")) {
|
|
188
|
+
return <img src={file.url} alt={file.fileName} />;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (file.fileType === "application/pdf") {
|
|
192
|
+
return (
|
|
193
|
+
<iframe
|
|
194
|
+
src={file.url}
|
|
195
|
+
title={file.fileName}
|
|
196
|
+
width="100%"
|
|
197
|
+
height="600px"
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<a href={file.url} download={file.fileName}>
|
|
204
|
+
Download {file.fileName}
|
|
205
|
+
</a>
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Storing Generated Files from Actions
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
// convex/generate.ts
|
|
214
|
+
"use node";
|
|
215
|
+
|
|
216
|
+
import { action } from "./_generated/server";
|
|
217
|
+
import { v } from "convex/values";
|
|
218
|
+
import { api } from "./_generated/api";
|
|
219
|
+
|
|
220
|
+
export const generatePDF = action({
|
|
221
|
+
args: { content: v.string() },
|
|
222
|
+
returns: v.id("_storage"),
|
|
223
|
+
handler: async (ctx, args) => {
|
|
224
|
+
// Generate PDF (example using a library)
|
|
225
|
+
const pdfBuffer = await generatePDFFromContent(args.content);
|
|
226
|
+
|
|
227
|
+
// Convert to Blob
|
|
228
|
+
const blob = new Blob([pdfBuffer], { type: "application/pdf" });
|
|
229
|
+
|
|
230
|
+
// Store in Convex
|
|
231
|
+
const storageId = await ctx.storage.store(blob);
|
|
232
|
+
|
|
233
|
+
return storageId;
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// Generate and save image
|
|
238
|
+
export const generateImage = action({
|
|
239
|
+
args: { prompt: v.string() },
|
|
240
|
+
returns: v.id("_storage"),
|
|
241
|
+
handler: async (ctx, args) => {
|
|
242
|
+
// Call external API to generate image
|
|
243
|
+
const response = await fetch("https://api.example.com/generate", {
|
|
244
|
+
method: "POST",
|
|
245
|
+
body: JSON.stringify({ prompt: args.prompt }),
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const imageBuffer = await response.arrayBuffer();
|
|
249
|
+
const blob = new Blob([imageBuffer], { type: "image/png" });
|
|
250
|
+
|
|
251
|
+
return await ctx.storage.store(blob);
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Accessing File Metadata
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
// convex/files.ts
|
|
260
|
+
import { query } from "./_generated/server";
|
|
261
|
+
import { v } from "convex/values";
|
|
262
|
+
import { Id } from "./_generated/dataModel";
|
|
263
|
+
|
|
264
|
+
type FileMetadata = {
|
|
265
|
+
_id: Id<"_storage">;
|
|
266
|
+
_creationTime: number;
|
|
267
|
+
contentType?: string;
|
|
268
|
+
sha256: string;
|
|
269
|
+
size: number;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export const getFileMetadata = query({
|
|
273
|
+
args: { storageId: v.id("_storage") },
|
|
274
|
+
returns: v.union(
|
|
275
|
+
v.object({
|
|
276
|
+
_id: v.id("_storage"),
|
|
277
|
+
_creationTime: v.number(),
|
|
278
|
+
contentType: v.optional(v.string()),
|
|
279
|
+
sha256: v.string(),
|
|
280
|
+
size: v.number(),
|
|
281
|
+
}),
|
|
282
|
+
v.null()
|
|
283
|
+
),
|
|
284
|
+
handler: async (ctx, args) => {
|
|
285
|
+
const metadata = await ctx.db.system.get(args.storageId);
|
|
286
|
+
return metadata as FileMetadata | null;
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Deleting Files
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
// convex/files.ts
|
|
295
|
+
import { mutation } from "./_generated/server";
|
|
296
|
+
import { v } from "convex/values";
|
|
297
|
+
|
|
298
|
+
export const deleteFile = mutation({
|
|
299
|
+
args: { fileId: v.id("files") },
|
|
300
|
+
returns: v.null(),
|
|
301
|
+
handler: async (ctx, args) => {
|
|
302
|
+
const file = await ctx.db.get(args.fileId);
|
|
303
|
+
if (!file) return null;
|
|
304
|
+
|
|
305
|
+
// Delete from storage
|
|
306
|
+
await ctx.storage.delete(file.storageId);
|
|
307
|
+
|
|
308
|
+
// Delete database record
|
|
309
|
+
await ctx.db.delete(args.fileId);
|
|
310
|
+
|
|
311
|
+
return null;
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Image Upload with Preview
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
import { useMutation } from "convex/react";
|
|
320
|
+
import { api } from "../convex/_generated/api";
|
|
321
|
+
import { useState, useRef } from "react";
|
|
322
|
+
|
|
323
|
+
function ImageUploader({ onUpload }: { onUpload: (id: Id<"files">) => void }) {
|
|
324
|
+
const generateUploadUrl = useMutation(api.files.generateUploadUrl);
|
|
325
|
+
const saveFile = useMutation(api.files.saveFile);
|
|
326
|
+
const [preview, setPreview] = useState<string | null>(null);
|
|
327
|
+
const [uploading, setUploading] = useState(false);
|
|
328
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
329
|
+
|
|
330
|
+
const handleFileSelect = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
331
|
+
const file = e.target.files?.[0];
|
|
332
|
+
if (!file) return;
|
|
333
|
+
|
|
334
|
+
// Validate file type
|
|
335
|
+
if (!file.type.startsWith("image/")) {
|
|
336
|
+
alert("Please select an image file");
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Validate file size (max 10MB)
|
|
341
|
+
if (file.size > 10 * 1024 * 1024) {
|
|
342
|
+
alert("File size must be less than 10MB");
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Show preview
|
|
347
|
+
const reader = new FileReader();
|
|
348
|
+
reader.onload = (e) => setPreview(e.target?.result as string);
|
|
349
|
+
reader.readAsDataURL(file);
|
|
350
|
+
|
|
351
|
+
// Upload
|
|
352
|
+
setUploading(true);
|
|
353
|
+
try {
|
|
354
|
+
const uploadUrl = await generateUploadUrl();
|
|
355
|
+
const result = await fetch(uploadUrl, {
|
|
356
|
+
method: "POST",
|
|
357
|
+
headers: { "Content-Type": file.type },
|
|
358
|
+
body: file,
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
const { storageId } = await result.json();
|
|
362
|
+
const fileId = await saveFile({
|
|
363
|
+
storageId,
|
|
364
|
+
fileName: file.name,
|
|
365
|
+
fileType: file.type,
|
|
366
|
+
fileSize: file.size,
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
onUpload(fileId);
|
|
370
|
+
} finally {
|
|
371
|
+
setUploading(false);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
return (
|
|
376
|
+
<div>
|
|
377
|
+
<input
|
|
378
|
+
ref={inputRef}
|
|
379
|
+
type="file"
|
|
380
|
+
accept="image/*"
|
|
381
|
+
onChange={handleFileSelect}
|
|
382
|
+
style={{ display: "none" }}
|
|
383
|
+
/>
|
|
384
|
+
|
|
385
|
+
<button
|
|
386
|
+
onClick={() => inputRef.current?.click()}
|
|
387
|
+
disabled={uploading}
|
|
388
|
+
>
|
|
389
|
+
{uploading ? "Uploading..." : "Select Image"}
|
|
390
|
+
</button>
|
|
391
|
+
|
|
392
|
+
{preview && (
|
|
393
|
+
<img
|
|
394
|
+
src={preview}
|
|
395
|
+
alt="Preview"
|
|
396
|
+
style={{ maxWidth: 200, marginTop: 10 }}
|
|
397
|
+
/>
|
|
398
|
+
)}
|
|
399
|
+
</div>
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
## Examples
|
|
405
|
+
|
|
406
|
+
### Schema for File Storage
|
|
407
|
+
|
|
408
|
+
```typescript
|
|
409
|
+
// convex/schema.ts
|
|
410
|
+
import { defineSchema, defineTable } from "convex/server";
|
|
411
|
+
import { v } from "convex/values";
|
|
412
|
+
|
|
413
|
+
export default defineSchema({
|
|
414
|
+
files: defineTable({
|
|
415
|
+
storageId: v.id("_storage"),
|
|
416
|
+
fileName: v.string(),
|
|
417
|
+
fileType: v.string(),
|
|
418
|
+
fileSize: v.number(),
|
|
419
|
+
uploadedBy: v.id("users"),
|
|
420
|
+
uploadedAt: v.number(),
|
|
421
|
+
})
|
|
422
|
+
.index("by_user", ["uploadedBy"])
|
|
423
|
+
.index("by_type", ["fileType"]),
|
|
424
|
+
|
|
425
|
+
// User avatars
|
|
426
|
+
users: defineTable({
|
|
427
|
+
name: v.string(),
|
|
428
|
+
email: v.string(),
|
|
429
|
+
avatarStorageId: v.optional(v.id("_storage")),
|
|
430
|
+
}),
|
|
431
|
+
|
|
432
|
+
// Posts with images
|
|
433
|
+
posts: defineTable({
|
|
434
|
+
authorId: v.id("users"),
|
|
435
|
+
content: v.string(),
|
|
436
|
+
imageStorageIds: v.array(v.id("_storage")),
|
|
437
|
+
createdAt: v.number(),
|
|
438
|
+
}).index("by_author", ["authorId"]),
|
|
439
|
+
});
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
## Best Practices
|
|
443
|
+
|
|
444
|
+
- Never run `npx convex deploy` unless explicitly instructed
|
|
445
|
+
- Never run any git commands unless explicitly instructed
|
|
446
|
+
- Validate file types and sizes on the client before uploading
|
|
447
|
+
- Store file metadata (name, type, size) in your own table
|
|
448
|
+
- Use the `_storage` system table only for Convex metadata
|
|
449
|
+
- Delete storage files when deleting database references
|
|
450
|
+
- Use appropriate Content-Type headers when uploading
|
|
451
|
+
- Consider image optimization for large images
|
|
452
|
+
|
|
453
|
+
## Common Pitfalls
|
|
454
|
+
|
|
455
|
+
1. **Not setting Content-Type header** - Files may not serve correctly
|
|
456
|
+
2. **Forgetting to delete storage** - Orphaned files waste storage
|
|
457
|
+
3. **Not validating file types** - Security risk for malicious uploads
|
|
458
|
+
4. **Large file uploads without progress** - Poor UX for users
|
|
459
|
+
5. **Using deprecated getMetadata** - Use ctx.db.system.get instead
|
|
460
|
+
|
|
461
|
+
## References
|
|
462
|
+
|
|
463
|
+
- Convex Documentation: https://docs.convex.dev/
|
|
464
|
+
- Convex LLMs.txt: https://docs.convex.dev/llms.txt
|
|
465
|
+
- File Storage: https://docs.convex.dev/file-storage
|
|
466
|
+
- Upload Files: https://docs.convex.dev/file-storage/upload-files
|
|
467
|
+
- Serve Files: https://docs.convex.dev/file-storage/serve-files
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<g clip-path="url(#clip0_3_23)">
|
|
3
|
+
<g clip-path="url(#clip1_3_23)">
|
|
4
|
+
<path d="M10.0643 12.5735C12.3769 12.3166 14.5572 11.0843 15.7577 9.02756C15.1892 14.1148 9.62646 17.3302 5.08583 15.356C4.66743 15.1746 4.30728 14.8728 4.06013 14.4848C3.03973 12.8825 2.7043 10.8437 3.18626 8.99344C4.56327 11.37 7.3632 12.8267 10.0643 12.5735Z" fill="#F3B01C"/>
|
|
5
|
+
<path d="M3.1018 7.50072C2.16436 9.66714 2.12376 12.2034 3.27303 14.2907C-0.771507 11.2479 -0.72737 4.7362 3.2236 1.72378C3.58904 1.44535 4.02333 1.2801 4.47881 1.25494C6.3519 1.15614 8.25501 1.88006 9.58963 3.22909C6.87799 3.25604 4.23695 4.99308 3.1018 7.50072Z" fill="#8D2676"/>
|
|
6
|
+
<path d="M10.8974 3.89562C9.52924 1.98794 7.38779 0.68921 5.04156 0.649695C9.57686 -1.40888 15.1555 1.92867 15.7629 6.86314C15.8194 7.32119 15.7452 7.78824 15.5421 8.20138C14.6948 9.92223 13.1236 11.2569 11.2876 11.7508C12.6328 9.25579 12.4668 6.20748 10.8974 3.89562Z" fill="#EE342F"/>
|
|
7
|
+
</g>
|
|
8
|
+
</g>
|
|
9
|
+
<defs>
|
|
10
|
+
<clipPath id="clip0_3_23">
|
|
11
|
+
<rect width="16" height="16" fill="white"/>
|
|
12
|
+
</clipPath>
|
|
13
|
+
<clipPath id="clip1_3_23">
|
|
14
|
+
<rect width="16" height="16" fill="white"/>
|
|
15
|
+
</clipPath>
|
|
16
|
+
</defs>
|
|
17
|
+
</svg>
|