Skip to content

Commit

Permalink
fix: undefined url in base64 or assets transform (#186)
Browse files Browse the repository at this point in the history
* fix: should pass url instead of image

* fix: change transform functions accept url
  • Loading branch information
MaikoTan authored Mar 21, 2024
1 parent ddcf3c4 commit d29401c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ export function apply(ctx: Context, config: Config) {
}

if (config.asset && ctx.assets) {
url = await ctx.booru.imgUrlToAssetUrl(image)
url = await ctx.booru.imgUrlToAssetUrl(url)
if (!url) {
output.unshift(<i18n path='.no-image'></i18n>)
continue
}
} else if (config.base64) {
url = await ctx.booru.imgUrlToBase64(image)
url = await ctx.booru.imgUrlToBase64(url)
if (!url) {
output.unshift(<i18n path='.no-image'></i18n>)
continue
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ class ImageService extends Service {
return undefined
}

async imgUrlToAssetUrl(image: ImageSource.Result): Promise<string> {
return await this.ctx.assets.upload(image.url, Date.now().toString()).catch(() => {
async imgUrlToAssetUrl(url: string): Promise<string> {
return await this.ctx.assets.upload(url, Date.now().toString()).catch(() => {
logger.warn('Request failed when trying to store image with assets service.')
return null
})
}

async imgUrlToBase64(image: ImageSource.Result): Promise<string> {
async imgUrlToBase64(url: string): Promise<string> {
return this.ctx
.http(image.url, { method: 'GET', responseType: 'arraybuffer' })
.http(url, { method: 'GET', responseType: 'arraybuffer' })
.then((resp) => {
return `data:${resp.headers['content-type']};base64,${Buffer.from(resp.data).toString('base64')}`
})
Expand Down

0 comments on commit d29401c

Please sign in to comment.