Skip to content

Commit 5ed2e0e

Browse files
author
sunlei
committed
update supabase result structure
1 parent 995a502 commit 5ed2e0e

File tree

4 files changed

+339
-3
lines changed

4 files changed

+339
-3
lines changed

server/node-service/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@types/lodash": "^4.14.190",
4343
"@types/morgan": "^1.9.3",
4444
"@types/node": "^18.11.18",
45+
"@types/node-fetch": "^2.6.2",
4546
"axios": "^1.2.0",
4647
"base64-arraybuffer": "^1.0.2",
4748
"dynamodb-data-types": "^4.0.1",
@@ -55,10 +56,12 @@
5556
"lodash": "^4.17.21",
5657
"loglevel": "^1.8.1",
5758
"morgan": "^1.10.0",
59+
"node-fetch": "2",
5860
"openapi-types": "^12.1.0",
5961
"openblocks-core": "^0.0.7",
6062
"openblocks-sdk": "0.0.38",
6163
"pino": "^8.11.0",
64+
"proxy-agent": "^5.0.0",
6265
"stylis": "^4.1.3",
6366
"swagger-client": "^3.18.5",
6467
"typescript": "^4.9.3",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import nodeFetch, { RequestInit, RequestInfo } from "node-fetch";
2+
import proxyAgent from "proxy-agent";
3+
4+
export function fetch(url: RequestInfo, init?: RequestInit) {
5+
return nodeFetch(url, { agent: proxyAgent(), ...init });
6+
}

server/node-service/src/plugins/supabase/run.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { createClient, SupabaseClient } from "@supabase/supabase-js";
2+
import { fetch } from "../../common/fetch";
23
import path from "path";
34
import { ServiceError } from "../../common/error";
45
import { DataSourceDataType } from "./dataSourceConfig";
56
import { ActionDataType } from "./queryConfig";
67

78
function getClient(params: DataSourceDataType) {
8-
return createClient(params.projectUrl, params.apiKey);
9+
return createClient(params.projectUrl, params.apiKey, {
10+
global: {
11+
fetch: fetch as any,
12+
},
13+
});
914
}
1015

1116
function getBucket(actionConfig: ActionDataType, dataSourceConfig: DataSourceDataType) {
@@ -115,7 +120,14 @@ export default async function run(action: ActionDataType, dataSourceConfig: Data
115120
if (ret.error) {
116121
throw ret.error;
117122
}
118-
return ret;
123+
let signedUrl;
124+
if (action.returnSignedUrl) {
125+
signedUrl = await getFileSignedUrl(bucket, action.fileName, client);
126+
}
127+
return {
128+
...ret.data,
129+
signedUrl,
130+
};
119131
}
120132

121133
if (action.actionName === "deleteFile") {
@@ -129,6 +141,9 @@ export default async function run(action: ActionDataType, dataSourceConfig: Data
129141
}
130142

131143
if (action.actionName === "createSignedUrl") {
132-
return await getFileSignedUrl(bucket, action.fileName, client);
144+
const signedUrl = await getFileSignedUrl(bucket, action.fileName, client);
145+
return {
146+
signedUrl,
147+
};
133148
}
134149
}

0 commit comments

Comments
 (0)