@adventurelabs/scout-core 1.0.125 → 1.0.127
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/dist/helpers/storage.js +30 -6
- package/package.json +1 -1
package/dist/helpers/storage.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
3
|
+
import { SIGNED_URL_EXPIRATION_SECONDS, } from "../constants/db";
|
|
4
|
+
/**
|
|
5
|
+
* Splits file path into bucket name and path. Must be at leaast one slash in your file path
|
|
6
|
+
* @param filePath
|
|
7
|
+
* @returns IFilePathParts | null - null if invalid file path
|
|
8
|
+
*/
|
|
9
|
+
function getPartsFromFilePath(filePath) {
|
|
10
|
+
const parts = filePath.split("/");
|
|
11
|
+
if (parts.length < 2) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const bucket_name = parts[0];
|
|
15
|
+
const path = parts.slice(1).join("/");
|
|
16
|
+
return { bucket_name, path };
|
|
17
|
+
}
|
|
4
18
|
/**
|
|
5
19
|
* Generates a signed URL for a file in Supabase storage
|
|
6
20
|
* @param filePath - The path to the file in storage (e.g., "events/123/image.jpg")
|
|
@@ -11,9 +25,14 @@ import { BUCKET_NAME_SCOUT, SIGNED_URL_EXPIRATION_SECONDS, } from "../constants/
|
|
|
11
25
|
export async function generateSignedUrl(filePath, expiresIn = SIGNED_URL_EXPIRATION_SECONDS, supabaseClient) {
|
|
12
26
|
try {
|
|
13
27
|
const supabase = supabaseClient || (await newServerClient());
|
|
28
|
+
const parts = getPartsFromFilePath(filePath);
|
|
29
|
+
if (!parts) {
|
|
30
|
+
console.error("Invalid file path:", filePath);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
14
33
|
const { data, error } = await supabase.storage
|
|
15
|
-
.from(
|
|
16
|
-
.createSignedUrl(
|
|
34
|
+
.from(parts.bucket_name)
|
|
35
|
+
.createSignedUrl(parts.path, expiresIn);
|
|
17
36
|
if (error) {
|
|
18
37
|
console.error("Error generating signed URL:", error.message);
|
|
19
38
|
return null;
|
|
@@ -30,9 +49,14 @@ export async function generateSignedUrlsBatch(filePaths, expiresIn = SIGNED_URL_
|
|
|
30
49
|
const supabase = supabaseClient || (await newServerClient());
|
|
31
50
|
const signedUrlPromises = filePaths.map(async (filePath) => {
|
|
32
51
|
try {
|
|
52
|
+
const parts = getPartsFromFilePath(filePath);
|
|
53
|
+
if (!parts) {
|
|
54
|
+
console.error("Invalid file path:", filePath);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
33
57
|
const { data, error } = await supabase.storage
|
|
34
|
-
.from(
|
|
35
|
-
.createSignedUrl(
|
|
58
|
+
.from(parts.bucket_name)
|
|
59
|
+
.createSignedUrl(parts.path, expiresIn);
|
|
36
60
|
if (error) {
|
|
37
61
|
console.error(`Error generating signed URL for ${filePath}:`, error.message);
|
|
38
62
|
return null;
|
|
@@ -40,7 +64,7 @@ export async function generateSignedUrlsBatch(filePaths, expiresIn = SIGNED_URL_
|
|
|
40
64
|
return data.signedUrl;
|
|
41
65
|
}
|
|
42
66
|
catch (error) {
|
|
43
|
-
console.
|
|
67
|
+
console.warn(`Exception generating signed URL for ${filePath}:`, error);
|
|
44
68
|
return null;
|
|
45
69
|
}
|
|
46
70
|
});
|