feat: add mime type field to files
This commit is contained in:
@@ -48,8 +48,12 @@ export const saveFile = mutation({
|
|||||||
directoryId: v.optional(v.id("directories")),
|
directoryId: v.optional(v.id("directories")),
|
||||||
storageId: v.id("_storage"),
|
storageId: v.id("_storage"),
|
||||||
userId: v.id("users"),
|
userId: v.id("users"),
|
||||||
|
mimeType: v.optional(v.string()),
|
||||||
},
|
},
|
||||||
handler: async (ctx, { name, storageId, directoryId, userId, size }) => {
|
handler: async (
|
||||||
|
ctx,
|
||||||
|
{ name, storageId, directoryId, userId, size, mimeType },
|
||||||
|
) => {
|
||||||
const now = new Date().toISOString()
|
const now = new Date().toISOString()
|
||||||
await ctx.db.insert("files", {
|
await ctx.db.insert("files", {
|
||||||
name,
|
name,
|
||||||
@@ -57,6 +61,7 @@ export const saveFile = mutation({
|
|||||||
storageId,
|
storageId,
|
||||||
directoryId,
|
directoryId,
|
||||||
userId,
|
userId,
|
||||||
|
mimeType,
|
||||||
createdAt: now,
|
createdAt: now,
|
||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
})
|
})
|
||||||
|
@@ -14,6 +14,7 @@ const schema = defineSchema({
|
|||||||
directoryId: v.optional(v.id("directories")),
|
directoryId: v.optional(v.id("directories")),
|
||||||
name: v.string(),
|
name: v.string(),
|
||||||
size: v.number(),
|
size: v.number(),
|
||||||
|
mimeType: v.optional(v.string()),
|
||||||
createdAt: v.string(),
|
createdAt: v.string(),
|
||||||
updatedAt: v.string(),
|
updatedAt: v.string(),
|
||||||
deletedAt: v.optional(v.string()),
|
deletedAt: v.optional(v.string()),
|
||||||
|
@@ -4,7 +4,7 @@ import { query } from "./_generated/server"
|
|||||||
export const getCurrentUser = query({
|
export const getCurrentUser = query({
|
||||||
handler: async (ctx) => {
|
handler: async (ctx) => {
|
||||||
return await ctx.db.get(
|
return await ctx.db.get(
|
||||||
"jd7ampv4m200xr4yk2cfncccmh7qhj34" as Id<"users">,
|
"j574n657f521n19v1stnr88ysd7qhbs1" as Id<"users">,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@@ -55,6 +55,7 @@ export function FilesPage() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tags: upload, uploadfile, uploadfilebutton, fileupload, fileuploadbutton
|
||||||
function UploadFileButton() {
|
function UploadFileButton() {
|
||||||
const [isUploading, setIsUploading] = useState(false)
|
const [isUploading, setIsUploading] = useState(false)
|
||||||
const currentUser = useConvexQuery(api.users.getCurrentUser)
|
const currentUser = useConvexQuery(api.users.getCurrentUser)
|
||||||
@@ -90,6 +91,7 @@ function UploadFileButton() {
|
|||||||
storageId,
|
storageId,
|
||||||
name: file.name,
|
name: file.name,
|
||||||
size: file.size,
|
size: file.size,
|
||||||
|
mimeType: file.type,
|
||||||
userId: currentUser._id,
|
userId: currentUser._id,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user