Skip to content

Commit

Permalink
feat: add png rendering action to the Metabase piece
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin-mourtialon committed Feb 4, 2025
1 parent 45daf4e commit 68c9df2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/metabase/package.json
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"
}
5 changes: 3 additions & 2 deletions packages/pieces/community/metabase/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Property,
} from '@activepieces/pieces-framework';
import { getQuestion } from './lib/actions/get-question';
import { getQuestionPngPreview } from './lib/actions/get-png-rendering';
import { queryMetabaseApi } from './lib/common';
import { HttpMethod } from '@activepieces/pieces-common';

Expand Down Expand Up @@ -50,7 +51,7 @@ export const metabase = createPiece({
auth: metabaseAuth,
minimumSupportedRelease: '0.30.0',
logoUrl: 'https://cdn.activepieces.com/pieces/metabase.png',
authors: ['AdamSelene', 'abuaboud'],
actions: [getQuestion],
authors: ['AdamSelene', 'abuaboud', 'valentin-mourtialon'],
actions: [getQuestion, getQuestionPngPreview],
triggers: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import { metabaseAuth } from '../..';

export const getQuestionPngPreview = createAction({
name: 'getQuestionPngPreview',
auth: metabaseAuth,
requireAuth: true,
displayName: 'Get Question PNG Preview',
description: 'Get PNG rendering 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 fetch(
`${auth.baseUrl}/api/pulse/preview_card_png/${questionId}`,
{
method: 'GET',
headers: {
Accept: 'image/png',
'X-API-KEY': auth.apiKey as string,
},
}
);

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

const arrayBuffer = await response.arrayBuffer();

const fileUrl = await files.write({
fileName: `metabase_question_${questionId}.png`,
data: Buffer.from(arrayBuffer),
});

return {
fileName: `metabase_question_${questionId}.png`,
url: fileUrl,
};
},
});

0 comments on commit 68c9df2

Please sign in to comment.