Fix init script (#6105)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-07-19 20:02:04 +05:00 committed by GitHub
parent b92ec6b9fc
commit 5816a0dedd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
}