-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
416 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"use server"; | ||
|
||
import { getUser } from "@midday/supabase/cached-queries"; | ||
import { createClient } from "@midday/supabase/server"; | ||
import { createFolder } from "@midday/supabase/storage"; | ||
import { revalidateTag } from "next/cache"; | ||
import { action } from "./safe-action"; | ||
import { createFolderSchema } from "./schema"; | ||
|
||
export const createFolderAction = action(createFolderSchema, async (value) => { | ||
const supabase = createClient(); | ||
const user = await getUser(); | ||
|
||
const { error } = await createFolder(supabase, { | ||
bucket: "vault", | ||
path: `${user.data.team_id}/${value.path}`, | ||
name: value.name, | ||
}); | ||
|
||
console.log(error); | ||
|
||
await revalidateTag(`vault_${user.data.team_id}`); | ||
|
||
return error; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use server"; | ||
|
||
import { getUser } from "@midday/supabase/cached-queries"; | ||
import { createClient } from "@midday/supabase/server"; | ||
import { deleteFolder, remove } from "@midday/supabase/storage"; | ||
import { revalidateTag } from "next/cache"; | ||
import { action } from "./safe-action"; | ||
import { deleteFileSchema } from "./schema"; | ||
|
||
export const deleteFileAction = action(deleteFileSchema, async (value) => { | ||
const supabase = createClient(); | ||
const user = await getUser(); | ||
|
||
if (value.isFolder) { | ||
await deleteFolder(supabase, { | ||
bucket: "vault", | ||
path: `${user.data.team_id}/${value.path}`, | ||
}); | ||
} | ||
|
||
await remove(supabase, { | ||
bucket: "vault", | ||
path: `${user.data.team_id}/${value.path}`, | ||
}); | ||
|
||
await revalidateTag(`vault_${user.data.team_id}`); | ||
|
||
return value; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use server"; | ||
|
||
import { getUser } from "@midday/supabase/cached-queries"; | ||
import { createClient } from "@midday/supabase/server"; | ||
import { share } from "@midday/supabase/storage"; | ||
import { action } from "./safe-action"; | ||
import { shareFileSchema } from "./schema"; | ||
|
||
export const shareFileAction = action(shareFileSchema, async (value) => { | ||
const supabase = createClient(); | ||
const user = await getUser(); | ||
|
||
const response = await share(supabase, { | ||
bucket: "vault", | ||
path: `${user.data.team_id}/${value.filepath}`, | ||
expireIn: value.expireIn, | ||
options: { | ||
download: true, | ||
}, | ||
}); | ||
|
||
return response?.data?.signedUrl; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletion
11
...rd/src/app/api/download/document/route.ts → ...hboard/src/app/api/download/file/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { createClient } from "@midday/supabase/server"; | ||
import { BlobReader, BlobWriter, ZipWriter } from "@zip.js/zip.js"; | ||
|
||
export const preferredRegion = "fra1"; | ||
export const runtime = "edge"; | ||
|
||
export async function GET(req, res) { | ||
const promises = []; | ||
const supabase = createClient(); | ||
const requestUrl = new URL(req.url); | ||
const path = requestUrl.searchParams.get("path"); | ||
const filename = requestUrl.searchParams.get("filename"); | ||
|
||
files.forEach((file) => { | ||
promises.push( | ||
supabaseClient.storage.from(bucket).download(`${folder}/${file.name}`) | ||
); | ||
}); | ||
|
||
const response = await Promise.allSettled(promises); | ||
|
||
const zipFileWriter = new BlobWriter("application/zip"); | ||
const zipWriter = new ZipWriter(zipFileWriter, { bufferedWrite: true }); | ||
|
||
const downloadedFiles = response.map((result, index) => { | ||
if (result.status === "fulfilled") { | ||
return { | ||
name: files[index].name, | ||
blob: result.value.data, | ||
}; | ||
} | ||
}); | ||
|
||
downloadedFiles.forEach((downloadedFile) => { | ||
if (downloadedFile) { | ||
zipWriter.add(downloadedFile.name, new BlobReader(downloadedFile.blob)); | ||
} | ||
}); | ||
|
||
// const { data } = await supabase.storage.from("vault").download(path); | ||
// const responseHeaders = new Headers(res.headers); | ||
|
||
// responseHeaders.set( | ||
// "Content-Disposition", | ||
// `attachment; filename="${filename}"` | ||
// ); | ||
|
||
// return new Response(data, { | ||
// headers: responseHeaders, | ||
// }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.