diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/request/RequestInstruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/request/RequestInstruction.ts index b9b82ecdc..2ee151ab8 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/request/RequestInstruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/request/RequestInstruction.ts @@ -95,20 +95,26 @@ async function request(config, context) { const formData = new FormData(); for (const [key, value] of Object.entries(data)) { if (key === 'file') { - const { resourceUrl, params: Params, headers: Header, body: Body } = data[key]; + let { url: resourceUrl, params: resourceParams, headers: resourceHeader, body: resourceBody } = data[key]; + resourceUrl = resourceUrl?.trim() || ''; + if (!resourceUrl.startsWith('http')) { + //如果开头不是http默认该url是内部url,需要加上token + resourceUrl = `${origin}${resourceUrl}`; + resourceHeader.Authorization = 'Bearer ' + token + } - if (Header['Content-Type'] === 'multipart/form-data' && Body) { + if (resourceHeader['Content-Type'] === 'multipart/form-data' && resourceBody) { //resource contentType类型 const formData = new FormData(); - Object.entries(Body).forEach(([key, value]) => { + Object.entries(resourceBody).forEach(([key, value]) => { formData.append(key, value); }); config.data = formData; } else { - config.data = Body; + config.data = resourceBody; } - const stream = await downloadToStream(resourceUrl, Header, Params, Body); + const stream = await downloadToStream(resourceUrl, resourceHeader, resourceParams, resourceBody); formData.append('file', stream); headers = { ...formData.getHeaders() }; diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/instructions/CreateInstruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/instructions/CreateInstruction.ts index 2be1af186..b8802dbb8 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/instructions/CreateInstruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/instructions/CreateInstruction.ts @@ -66,18 +66,18 @@ export class CreateInstruction extends Instruction { throw new Error('Invalid data URL format'); } } else if (parseRes) { - const { resourceUrl, params, headers, body } = parseRes; + const { url: resourceUrl, params: resourceParams, headers: resourceHeaders, body: resourceBody } = parseRes; config.url = resourceUrl; - config.params = params; - config.headers = headers; - if (headers['content-type'] === 'multipart/form-data') { + config.params = resourceParams; + config.headers = resourceHeaders; + if (resourceHeaders['content-type'] === 'multipart/form-data') { const formData = new FormData(); - Object.entries(body).forEach(([key, value]) => { + Object.entries(resourceBody).forEach(([key, value]) => { formData.append(key, value); }); config.data = formData; } else { - config.data = body; + config.data = resourceBody; } const response = await axios(config); const contentType = response.headers['content-type']; diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/instructions/UpdateInstruction.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/instructions/UpdateInstruction.ts index fd804d3b2..feb8eb2cc 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/server/instructions/UpdateInstruction.ts +++ b/packages/plugins/@tachybase/plugin-workflow/src/server/instructions/UpdateInstruction.ts @@ -68,18 +68,20 @@ export class UpdateInstruction extends Instruction { throw new Error('Invalid data URL format'); } } else if (parseRes) { - const { resourceUrl, params, headers, body } = parseRes; + const { url: resourceUrl, params: resourceParams, headers: resourceHeaders, body: resourceBody } = parseRes; config.url = resourceUrl; - config.params = params; - config.headers = headers; - if (headers['content-type'] === 'multipart/form-data') { + config.params = resourceParams; + config.headers = resourceHeaders; + if (resourceHeaders['content-type'] === 'multipart/form-data') { const formData = new FormData(); - Object.entries(body).forEach(([key, value]) => { + Object.entries(resourceBody).forEach(([key, value]) => { + formData.append(key, value); }); config.data = formData; } else { - config.data = body; + config.data = resourceBody; + } const response = await axios(config); const contentType = response.headers['content-type'];