diff --git a/server/tool/src/initializer.ts b/server/tool/src/initializer.ts index fc4b51acb3..67d914865d 100644 --- a/server/tool/src/initializer.ts +++ b/server/tool/src/initializer.ts @@ -79,7 +79,6 @@ export interface UploadStep { type: 'upload' fromUrl: string contentType: string - size?: number resultVariable?: string } @@ -142,12 +141,14 @@ export class WorkspaceInitializer { const id = uuid() const resp = await fetch(step.fromUrl) const buffer = Buffer.from(await resp.arrayBuffer()) - await this.storageAdapter.put(this.ctx, this.wsUrl, id, buffer, step.contentType, step.size) + await this.storageAdapter.put(this.ctx, this.wsUrl, id, buffer, step.contentType, buffer.length) if (step.resultVariable !== undefined) { vars[step.resultVariable] = id + vars[`${step.resultVariable}_size`] = buffer.length } } catch (error) { logger.error('Upload failed', error) + throw error } } @@ -297,7 +298,9 @@ export class WorkspaceInitializer { const matched = fieldRegexp.exec(value) if (matched === null) break const result = vars[matched[0]] - if (result !== undefined && typeof result === 'string') { + if (result === undefined || typeof result !== 'string') { + throw new Error(`Variable ${matched[0]} not found`) + } else { value = value.replaceAll(matched[0], result) fieldRegexp.lastIndex = 0 }