feat: Convert all app files to JS

This commit is contained in:
Faruk AYDIN
2024-01-05 17:44:21 +01:00
parent b95478b635
commit 43dba351c3
1030 changed files with 5114 additions and 6436 deletions

View File

@@ -0,0 +1,3 @@
import removeImageBackground from './remove-image-background/index.js';
export default [removeImageBackground];

View File

@@ -1,3 +0,0 @@
import removeImageBackground from './remove-image-background';
export default [removeImageBackground];

View File

@@ -1,49 +1,50 @@
import defineAction from '../../../../helpers/define-action';
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Remove image background',
key: 'removeImageBackground',
description:
'Removes the background of an image.',
description: 'Removes the background of an image.',
arguments: [
{
label: 'Image file',
key: 'imageFileB64',
type: 'string' as const,
type: 'string',
required: true,
variables: true,
description: 'Provide a JPG or PNG file in Base64 format, up to 12 MB (see remove.bg/supported-images)',
description:
'Provide a JPG or PNG file in Base64 format, up to 12 MB (see remove.bg/supported-images)',
},
{
label: 'Size',
key: 'size',
type: 'dropdown' as const,
type: 'dropdown',
required: true,
value: 'auto',
options: [
{ label: 'Auto', value: 'auto' },
{ label: 'Preview (up to 0.25 megapixels)', value: 'preview' },
{ label: 'Full (up to 10 megapixels)', value: 'full' },
]
],
},
{
label: 'Background color',
key: 'bgColor',
type: 'string' as const,
description: 'Adds a solid color background. Can be a hex color code (e.g. 81d4fa, fff) or a color name (e.g. green)',
type: 'string',
description:
'Adds a solid color background. Can be a hex color code (e.g. 81d4fa, fff) or a color name (e.g. green)',
required: false,
},
{
label: 'Background image URL',
key: 'bgImageUrl',
type: 'string' as const,
type: 'string',
description: 'Adds a background image from a URL.',
required: false,
},
{
label: 'Output image format',
key: 'outputFormat',
type: 'dropdown' as const,
type: 'dropdown',
description: 'Note: Use PNG to preserve transparency',
required: true,
value: 'auto',
@@ -51,32 +52,32 @@ export default defineAction({
{ label: 'Auto', value: 'auto' },
{ label: 'PNG', value: 'png' },
{ label: 'JPG', value: 'jpg' },
{ label: 'ZIP', value: 'zip' }
]
}
{ label: 'ZIP', value: 'zip' },
],
},
],
async run($) {
const imageFileB64 = $.step.parameters.imageFileB64 as string;
const size = $.step.parameters.size as string;
const bgColor = $.step.parameters.bgColor as string;
const bgImageUrl = $.step.parameters.bgImageUrl as string;
const outputFormat = $.step.parameters.outputFormat as string;
const imageFileB64 = $.step.parameters.imageFileB64;
const size = $.step.parameters.size;
const bgColor = $.step.parameters.bgColor;
const bgImageUrl = $.step.parameters.bgImageUrl;
const outputFormat = $.step.parameters.outputFormat;
const body = JSON.stringify({
image_file_b64: imageFileB64,
size: size,
bg_color: bgColor,
bg_image_url: bgImageUrl,
format: outputFormat
format: outputFormat,
});
const response = await $.http.post('/removebg', body, {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Accept: 'application/json',
},
});
$.setActionItem({ raw: response.data });
}
},
});

View File

@@ -1,12 +1,12 @@
import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified';
import verifyCredentials from './verify-credentials.js';
import isStillVerified from './is-still-verified.js';
export default {
fields: [
{
key: 'screenName',
label: 'Screen Name',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,
@@ -18,7 +18,7 @@ export default {
{
key: 'apiKey',
label: 'API Key',
type: 'string' as const,
type: 'string',
required: true,
readOnly: false,
value: null,

View File

@@ -0,0 +1,8 @@
import verifyCredentials from './verify-credentials.js';
const isStillVerified = async ($) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -1,9 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import verifyCredentials from './verify-credentials';
const isStillVerified = async ($: IGlobalVariable) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -1,6 +1,4 @@
import { IGlobalVariable } from '@automatisch/types';
const verifyCredentials = async ($: IGlobalVariable) => {
const verifyCredentials = async ($) => {
await $.http.get('/account');
await $.auth.set({

View File

@@ -0,0 +1,9 @@
const addAuthHeader = ($, requestConfig) => {
if ($.auth.data?.apiKey) {
requestConfig.headers['X-API-Key'] = `${$.auth.data.apiKey}`;
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -1,11 +0,0 @@
import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
if ($.auth.data?.apiKey) {
requestConfig.headers['X-API-Key'] = `${$.auth.data.apiKey}`;
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -1,7 +1,7 @@
import defineApp from '../../helpers/define-app';
import addAuthHeader from './common/add-auth-header';
import auth from './auth';
import actions from './actions';
import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js';
import actions from './actions/index.js';
export default defineApp({
name: 'Remove.bg',