forked from activepieces/activepieces
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add png rendering action to the Metabase piece
- Loading branch information
1 parent
45daf4e
commit 1ffcdcb
Showing
6 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"name": "@activepieces/piece-metabase", | ||
"version": "0.1.2" | ||
"version": "0.1.3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/pieces/community/metabase/src/lib/actions/get-png-rendering.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { createAction, Property } from '@activepieces/pieces-framework'; | ||
import { metabaseAuth } from '../..'; | ||
import { queryMetabaseApi } from '../common'; | ||
import { HttpMethod } from '@activepieces/pieces-common'; | ||
|
||
export const getQuestionPngPreview = createAction({ | ||
name: 'getQuestionPngPreview', | ||
auth: metabaseAuth, | ||
requireAuth: true, | ||
displayName: 'Get Question PNG Preview', | ||
description: | ||
'Get PNG preview rendering (low resolution) of a Metabase card/question.', | ||
props: { | ||
questionId: Property.ShortText({ | ||
displayName: 'Metabase question ID', | ||
required: true, | ||
}), | ||
}, | ||
async run({ auth, propsValue, files }) { | ||
const questionId = propsValue.questionId.split('-')[0]; | ||
|
||
const response = await queryMetabaseApi( | ||
{ | ||
endpoint: `pulse/preview_card_png/${questionId}`, | ||
method: HttpMethod.GET, | ||
headers: { | ||
Accept: 'image/png', | ||
}, | ||
responseType: 'arraybuffer', | ||
}, | ||
auth | ||
); | ||
|
||
if (response.error) { | ||
throw new Error(response.error); | ||
} | ||
|
||
const fileUrl = await files.write({ | ||
fileName: `metabase_question_${questionId}.png`, | ||
data: Buffer.from(response, 'base64'), | ||
}); | ||
|
||
return { | ||
fileName: `metabase_question_${questionId}.png`, | ||
file: fileUrl, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters