Skip to content

Commit cd48ace

Browse files
authored
Merge pull request #2 from juzibot/feat/videosupport
Feat/videosupport
2 parents ae635a6 + af034a6 commit cd48ace

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/google/google-proxy.controller.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,17 @@ export class GoogleProxyController {
6666
const queryString = new URLSearchParams(query).toString();
6767
const uploadUrl = `https://generativelanguage.googleapis.com/upload/v1beta/files?${queryString}`;
6868
const bufferBody = req.body;
69-
return this.service.uploadFileData(uploadUrl, bufferBody, headers);
69+
const result = await this.service.uploadFileData(uploadUrl, bufferBody, headers);
70+
if (result && typeof result === 'object' && 'status' in result) {
71+
res.status(result.status);
72+
if (result.headers) {
73+
Object.keys(result.headers).forEach(key => {
74+
res.setHeader(key, result.headers[key]);
75+
});
76+
}
77+
return result.data;
78+
}
79+
return result;
7080
}
7181
const result = await this.service.uploadFileInit(body, headers);
7282
res.status(result.status);
@@ -110,8 +120,9 @@ export class GoogleProxyController {
110120
async getFile(
111121
@Param('path') path: string,
112122
@Headers() headers: any,
123+
@Query() query: any,
113124
) {
114125
const url = `https://generativelanguage.googleapis.com/v1beta/${path}`;
115-
return this.service.getFileInfo(url, headers);
126+
return this.service.getFileInfo(url, headers, query);
116127
}
117128
}

src/google/google-proxy.service.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ export class GoogleProxyService {
5555
timeout: 5 * MINUTE,
5656
maxContentLength: Infinity,
5757
maxBodyLength: Infinity,
58-
validateStatus: (status) => status === 200 || status === 308,
58+
validateStatus: (status) => status === 200 || status === 201 || status === 308,
5959
isBinaryData: true,
60+
returnFullResponse: true,
6061
});
62+
63+
if (result.status === 201) {
64+
return result;
65+
}
6166
return result.data;
6267
}
6368

@@ -82,14 +87,18 @@ export class GoogleProxyService {
8287
timeout: 5 * MINUTE,
8388
maxContentLength: Infinity,
8489
maxBodyLength: Infinity,
85-
validateStatus: (status) => status === 200 || status === 308,
90+
validateStatus: (status) => status === 200 || status === 201 || status === 308,
8691
isBinaryData: true,
92+
returnFullResponse: true,
8793
});
94+
if (result.status === 201) {
95+
return result;
96+
}
8897
return result.data;
8998
}
9099

91-
async getFileInfo(url: string, headers: any) {
92-
return this.makeRequest(url, headers, null, {}, false, {
100+
async getFileInfo(url: string, headers: any, query?: any) {
101+
return this.makeRequest(url, headers, null, query || {}, false, {
93102
method: 'GET',
94103
timeout: 30000,
95104
});

0 commit comments

Comments
 (0)