Skip to content

Commit b84ba43

Browse files
committed
chore: clean up headers needed for short fs ttl
1 parent 65f402b commit b84ba43

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ts/session/apis/file_server_api/FileServerApi.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ import { FS, type FILE_SERVER_TARGET_TYPE } from './FileServerTarget';
2020
const RELEASE_VERSION_ENDPOINT = '/session_version';
2121
const FILE_ENDPOINT = '/file';
2222

23+
function getShortTTLHeadersIfNeeded(): Record<string, string> {
24+
if (window.sessionFeatureFlags?.fsTTL30s) {
25+
return { 'X-FS-TTL': '30' };
26+
}
27+
return {};
28+
}
29+
2330
/**
2431
* Upload a file to the file server v2 using the onion v4 encoding
2532
* @param fileContent the data to send
@@ -48,7 +55,7 @@ export const uploadFileToFsWithOnionV4 = async (
4855
endpoint: FILE_ENDPOINT,
4956
method: 'POST',
5057
timeoutMs: 30 * DURATION.SECONDS, // longer time for file upload
51-
headers: window.sessionFeatureFlags.fsTTL30s ? { 'X-FS-TTL': '30' } : {},
58+
headers: getShortTTLHeadersIfNeeded(),
5259
});
5360

5461
if (!batchGlobalIsSuccess(result)) {
@@ -203,20 +210,16 @@ export const extendFileExpiry = async (fileId: string, fsTarget: FILE_SERVER_TAR
203210

204211
const method = 'POST';
205212
const endpoint = `/file/${fileId}/extend`;
206-
const headers: Record<string, string> = window.sessionFeatureFlags.fsTTL30s
207-
? { 'X-FS-TTL': '30' }
208-
: {};
209-
const params = {
213+
214+
const result = await OnionSending.sendJsonViaOnionV4ToFileServer({
210215
abortSignal: new AbortController().signal,
211216
endpoint,
212217
method,
213218
stringifiedBody: null,
214-
headers,
219+
headers: getShortTTLHeadersIfNeeded(),
215220
timeoutMs: 10 * DURATION.SECONDS,
216221
target: fsTarget,
217-
};
218-
219-
const result = await OnionSending.sendJsonViaOnionV4ToFileServer(params);
222+
});
220223

221224
if (!batchGlobalIsSuccess(result)) {
222225
return null;

0 commit comments

Comments
 (0)