@adventurelabs/scout-core 1.0.127 → 1.0.128
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 +11 -12
- package/package.json +1 -1
package/dist/helpers/storage.js
CHANGED
|
@@ -6,14 +6,13 @@ import { SIGNED_URL_EXPIRATION_SECONDS, } from "../constants/db";
|
|
|
6
6
|
* @param filePath
|
|
7
7
|
* @returns IFilePathParts | null - null if invalid file path
|
|
8
8
|
*/
|
|
9
|
-
function
|
|
9
|
+
function getBucketFromFilePath(filePath) {
|
|
10
10
|
const parts = filePath.split("/");
|
|
11
11
|
if (parts.length < 2) {
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
14
14
|
const bucket_name = parts[0];
|
|
15
|
-
|
|
16
|
-
return { bucket_name, path };
|
|
15
|
+
return bucket_name;
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* Generates a signed URL for a file in Supabase storage
|
|
@@ -25,14 +24,14 @@ function getPartsFromFilePath(filePath) {
|
|
|
25
24
|
export async function generateSignedUrl(filePath, expiresIn = SIGNED_URL_EXPIRATION_SECONDS, supabaseClient) {
|
|
26
25
|
try {
|
|
27
26
|
const supabase = supabaseClient || (await newServerClient());
|
|
28
|
-
const
|
|
29
|
-
if (!
|
|
27
|
+
const bucket_name = getBucketFromFilePath(filePath);
|
|
28
|
+
if (!bucket_name) {
|
|
30
29
|
console.error("Invalid file path:", filePath);
|
|
31
30
|
return null;
|
|
32
31
|
}
|
|
33
32
|
const { data, error } = await supabase.storage
|
|
34
|
-
.from(
|
|
35
|
-
.createSignedUrl(
|
|
33
|
+
.from(bucket_name)
|
|
34
|
+
.createSignedUrl(filePath, expiresIn);
|
|
36
35
|
if (error) {
|
|
37
36
|
console.error("Error generating signed URL:", error.message);
|
|
38
37
|
return null;
|
|
@@ -49,16 +48,16 @@ export async function generateSignedUrlsBatch(filePaths, expiresIn = SIGNED_URL_
|
|
|
49
48
|
const supabase = supabaseClient || (await newServerClient());
|
|
50
49
|
const signedUrlPromises = filePaths.map(async (filePath) => {
|
|
51
50
|
try {
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
51
|
+
const bucket_name = getBucketFromFilePath(filePath);
|
|
52
|
+
if (!bucket_name) {
|
|
54
53
|
console.error("Invalid file path:", filePath);
|
|
55
54
|
return null;
|
|
56
55
|
}
|
|
57
56
|
const { data, error } = await supabase.storage
|
|
58
|
-
.from(
|
|
59
|
-
.createSignedUrl(
|
|
57
|
+
.from(bucket_name)
|
|
58
|
+
.createSignedUrl(filePath, expiresIn);
|
|
60
59
|
if (error) {
|
|
61
|
-
console.
|
|
60
|
+
console.warn(`Error generating signed URL for ${filePath}:`, error.message);
|
|
62
61
|
return null;
|
|
63
62
|
}
|
|
64
63
|
return data.signedUrl;
|