update js client
This commit is contained in:
+44
-4
@@ -27,9 +27,9 @@
|
||||
// ---------------------------------------------- Constants ---------------------------------------------- //
|
||||
|
||||
/**
|
||||
* Default size threshold for switching from direct to link transport (0.5MB)
|
||||
* Default size threshold for switching from direct to link transport (10KB)
|
||||
*/
|
||||
const DEFAULT_SIZE_THRESHOLD = 500_000;
|
||||
const DEFAULT_SIZE_THRESHOLD = 10_000;
|
||||
|
||||
/**
|
||||
* Default broker URL
|
||||
@@ -39,7 +39,7 @@ const DEFAULT_BROKER_URL = 'localhost:4222';
|
||||
/**
|
||||
* Default HTTP file server URL for link transport
|
||||
*/
|
||||
const DEFAULT_FILESERVER_URL = 'http://localhost:8080';
|
||||
const DEFAULT_FILESERVER_URL = 'https://fileserver.yiem.cc';
|
||||
|
||||
// ---------------------------------------------- Utility Functions ---------------------------------------------- //
|
||||
|
||||
@@ -50,7 +50,11 @@ const DEFAULT_FILESERVER_URL = 'http://localhost:8080';
|
||||
*/
|
||||
function bufferToBase64(data) {
|
||||
const bytes = new Uint8Array(data);
|
||||
const binary = String.fromCharCode(...bytes);
|
||||
let binary = '';
|
||||
const chunkSize = 8192;
|
||||
for (let i = 0; i < bytes.length; i += chunkSize) {
|
||||
binary += String.fromCharCode.apply(null, bytes.subarray(i, i + chunkSize));
|
||||
}
|
||||
return btoa(binary);
|
||||
}
|
||||
|
||||
@@ -199,6 +203,37 @@ async function deserializeData(data, payloadType, correlationId) {
|
||||
|
||||
// ---------------------------------------------- File Server Handlers ---------------------------------------------- //
|
||||
|
||||
/**
|
||||
* Upload data to a pre-signed S3 URL
|
||||
* @param {string} signUrl - Pre-signed S3 URL (complete URL, not base) or empty string
|
||||
* @param {string} dataname - The S3 key / object path
|
||||
* @param {Uint8Array} data - Raw bytes to upload
|
||||
* @param {Object} options - Additional options
|
||||
* @param {string} [options.content_type="application/json"] - MIME type for the PUT request
|
||||
* @returns {Promise<{status: number, uploadid: string, fileid: string, url: string}>}
|
||||
*/
|
||||
async function s3UploadHandler(signUrl, dataname, data, options = {}) {
|
||||
const { content_type = 'application/json' } = options;
|
||||
const buffer = data instanceof Uint8Array ? data : new Uint8Array(data);
|
||||
|
||||
if (signUrl !== '' && signUrl !== undefined) {
|
||||
const response = await fetch(signUrl, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': content_type },
|
||||
body: buffer
|
||||
});
|
||||
|
||||
return {
|
||||
status: response.status,
|
||||
uploadid: '',
|
||||
fileid: '',
|
||||
url: dataname
|
||||
};
|
||||
} else {
|
||||
throw new Error('No pre-signed URL available for S3 upload');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload data to plik server in one-shot mode
|
||||
* @param {string} fileServerUrl - Base URL of the plik server
|
||||
@@ -616,6 +651,11 @@ const msghandlerCSR = {
|
||||
*/
|
||||
plikOneshotUpload,
|
||||
|
||||
/**
|
||||
* Upload data to a pre-signed S3 URL
|
||||
*/
|
||||
s3UploadHandler,
|
||||
|
||||
/**
|
||||
* Fetch data from URL with exponential backoff
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user