MCPcopy Create free account
hub / github.com/Rfym21/Qwen2API / uploadToOssWithSts

Function uploadToOssWithSts

src/utils/upload.js:188–235  ·  view source on GitHub ↗
(fileBuffer, stsCredentials, ossInfo, fileContentTypeFull, retryCount = 0)

Source from the content-addressed store, hash-verified

186 error.response?.status >= 500)) {
187
188 const delayMs = UPLOAD_CONFIG.retryDelay * Math.pow(2, retryCount)
189 logger.warn(`等待 ${delayMs}ms 后重试...`, 'UPLOAD', '⏳')
190 await delay(delayMs)
191
192 return requestStsToken(filename, filesize, filetypeSimple, authToken, retryCount + 1, account)
193 }
194
195 throw error
196 }
197}
198
199/**
200 * Preserve the OSS buffered-upload response contract while bypassing Bun's Node agent shim.
201 */
202const createOssProxyClient = (account) => {
203 if (!process.versions.bun || !getProxyAgent(account)) return undefined;
204 return {
205 async request(url, options) {
206 let response;
207 try {
208 response = await axios.request(applyProxyToAxiosConfig({
209 url,
210 method: options.method,
211 headers: options.headers,
212 data: options.content,
213 timeout: options.timeout,
214 responseType: 'arraybuffer',
215 validateStatus: () => true
216 }, account));
217 } catch (error) {
218 // ali-oss recognizes urllib's transport status codes when preserving errors.
219 error.status = ['ETIMEDOUT', 'ECONNABORTED'].includes(error.code) ? -2 : -1;
220 throw error;
221 }
222 const data = Buffer.from(response.data);
223 const headers = response.headers.toJSON();
224 return {
225 status: response.status,
226 headers,
227 data,
228 res: { status: response.status, statusCode: response.status, headers, size: data.length }
229 };
230 }
231 };
232};
233
234/**
235 * 使用STS凭证将文件Buffer上传到阿里云OSS(带重试机制)
236 * @param {Buffer} fileBuffer - 文件内容的Buffer
237 * @param {Object} stsCredentials - STS凭证
238 * @param {Object} ossInfo - OSS信息

Callers 1

uploadFileToQwenOssFunction · 0.85

Calls 5

errorMethod · 0.80
infoMethod · 0.80
successMethod · 0.80
warnMethod · 0.80
delayFunction · 0.70

Tested by

no test coverage detected