diff --git a/apps/dashboard/package.json b/apps/dashboard/package.json index d2ee3c7ff2..61d500b878 100644 --- a/apps/dashboard/package.json +++ b/apps/dashboard/package.json @@ -25,7 +25,7 @@ "@trigger.dev/nextjs": "^2.2.11", "@vercel/edge-config": "^0.4.1", "@vercel/toolbar": "^0.1.6", - "@zip.js/zip.js": "2.7.31", + "@zip.js/zip.js": "2.7.32", "change-case": "^5.2.0", "framer-motion": "^10.16.14", "ms": "^2.1.3", diff --git a/apps/dashboard/src/components/tables/vault/upload-zone.tsx b/apps/dashboard/src/components/tables/vault/upload-zone.tsx index 7a4824e32d..f88e1bc636 100644 --- a/apps/dashboard/src/components/tables/vault/upload-zone.tsx +++ b/apps/dashboard/src/components/tables/vault/upload-zone.tsx @@ -2,9 +2,9 @@ import { createFolderAction } from "@/actions/create-folder-action"; import { invalidateCacheAction } from "@/actions/invalidate-cache-action"; +import { resumableUpload } from "@/utils/upload"; import { createClient } from "@midday/supabase/client"; import { getCurrentUserTeamQuery } from "@midday/supabase/queries"; -import { resumableUpload } from "@midday/supabase/storage"; import { ContextMenu, ContextMenuContent, diff --git a/apps/dashboard/src/utils/upload.ts b/apps/dashboard/src/utils/upload.ts new file mode 100644 index 0000000000..efe1021f10 --- /dev/null +++ b/apps/dashboard/src/utils/upload.ts @@ -0,0 +1,59 @@ +import * as tus from "tus-js-client"; + +type ResumableUploadParmas = { + file: File; + path: string; + bucket: string; + onProgress?: (bytesUploaded: number, bytesTotal: number) => void; +}; + +export async function resumableUpload( + client: SupabaseClient, + { file, path, bucket, onProgress }: ResumableUploadParmas +) { + const { + data: { session }, + } = await client.auth.getSession(); + + const fullPath = `${path}/${file.name}`; + + return new Promise((resolve, reject) => { + const upload = new tus.Upload(file, { + endpoint: `https://${process.env.NEXT_PUBLIC_SUPABASE_ID}.supabase.co/storage/v1/upload/resumable`, + retryDelays: [0, 3000, 5000, 10000], + headers: { + authorization: `Bearer ${session?.access_token}`, + // optionally set upsert to true to overwrite existing files + "x-upsert": "true", + }, + uploadDataDuringCreation: true, + // Important if you want to allow re-uploading the same file https://github.com/tus/tus-js-client/blob/main/docs/api.md#removefingerprintonsuccess + removeFingerprintOnSuccess: true, + metadata: { + bucketName: bucket, + objectName: fullPath, + contentType: file.type, + cacheControl: "3600", + }, + // NOTE: it must be set to 6MB (for now) do not change it + chunkSize: 6 * 1024 * 1024, + onError: (error) => { + reject(error); + }, + onProgress, + onSuccess: () => { + resolve(upload); + }, + }); + + // Check if there are any previous uploads to continue. + return upload.findPreviousUploads().then((previousUploads) => { + // Found previous uploads so we select the first one. + if (previousUploads.length) { + upload.resumeFromPreviousUpload(previousUploads[0]); + } + + upload.start(); + }); + }); +} diff --git a/bun.lockb b/bun.lockb index e884001e8a..6d018e6acc 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/supabase/src/utils/storage.ts b/packages/supabase/src/utils/storage.ts index a5ccd79582..a6359939f6 100644 --- a/packages/supabase/src/utils/storage.ts +++ b/packages/supabase/src/utils/storage.ts @@ -1,5 +1,4 @@ import { SupabaseClient } from "@supabase/supabase-js"; -import * as tus from "tus-js-client"; export const EMPTY_FOLDER_PLACEHOLDER_FILE_NAME = ".emptyFolderPlaceholder"; @@ -28,64 +27,6 @@ export async function upload( throw result.error; } -type ResumableUploadParmas = { - file: File; - path: string; - bucket: string; - onProgress?: (bytesUploaded: number, bytesTotal: number) => void; -}; - -export async function resumableUpload( - client: SupabaseClient, - { file, path, bucket, onProgress }: ResumableUploadParmas -) { - const { - data: { session }, - } = await client.auth.getSession(); - - const fullPath = `${path}/${file.name}`; - - return new Promise((resolve, reject) => { - const upload = new tus.Upload(file, { - endpoint: `https://${process.env.NEXT_PUBLIC_SUPABASE_ID}.supabase.co/storage/v1/upload/resumable`, - retryDelays: [0, 3000, 5000, 10000], - headers: { - authorization: `Bearer ${session?.access_token}`, - // optionally set upsert to true to overwrite existing files - "x-upsert": "true", - }, - uploadDataDuringCreation: true, - // Important if you want to allow re-uploading the same file https://github.com/tus/tus-js-client/blob/main/docs/api.md#removefingerprintonsuccess - removeFingerprintOnSuccess: true, - metadata: { - bucketName: bucket, - objectName: fullPath, - contentType: file.type, - cacheControl: "3600", - }, - // NOTE: it must be set to 6MB (for now) do not change it - chunkSize: 6 * 1024 * 1024, - onError: (error) => { - reject(error); - }, - onProgress, - onSuccess: () => { - resolve(upload); - }, - }); - - // Check if there are any previous uploads to continue. - return upload.findPreviousUploads().then((previousUploads) => { - // Found previous uploads so we select the first one. - if (previousUploads.length) { - upload.resumeFromPreviousUpload(previousUploads[0]); - } - - upload.start(); - }); - }); -} - type RemoveParams = { path: string; bucket: string;