feat: Convert all app files to JS
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
|
||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
||||
export default async function generateAuthUrl($) {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
|
||||
const callbackUrl = oauthRedirectUrlField.value;
|
@@ -1,13 +1,13 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import generateAuthUrl from './generate-auth-url.js';
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import isStillVerified from './is-still-verified.js';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'oAuthRedirectUrl',
|
||||
label: 'OAuth Redirect URL',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: true,
|
||||
value: '{WEB_APP_URL}/app/flickr/connections/add',
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
{
|
||||
key: 'consumerKey',
|
||||
label: 'Consumer Key',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -32,7 +32,7 @@ export default {
|
||||
{
|
||||
key: 'consumerSecret',
|
||||
label: 'Consumer Secret',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -1,6 +1,4 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
const isStillVerified = async ($) => {
|
||||
const params = {
|
||||
method: 'flickr.test.login',
|
||||
format: 'json',
|
@@ -1,7 +1,6 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const verifyCredentials = async ($) => {
|
||||
const response = await $.http.post(
|
||||
`/oauth/access_token?oauth_verifier=${$.auth.data.oauth_verifier}&oauth_token=${$.auth.data.accessToken}`,
|
||||
null
|
@@ -1,22 +1,14 @@
|
||||
import { Token } from 'oauth-1.0a';
|
||||
import { IJSONObject, TBeforeRequest } from '@automatisch/types';
|
||||
import oauthClient from './oauth-client';
|
||||
import oauthClient from './oauth-client.js';
|
||||
|
||||
type RequestDataType = {
|
||||
url: string;
|
||||
method: string;
|
||||
data?: IJSONObject;
|
||||
};
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
const { url, method, data, params } = requestConfig;
|
||||
|
||||
const token: Token = {
|
||||
key: $.auth.data?.accessToken as string,
|
||||
secret: $.auth.data?.accessSecret as string,
|
||||
const token = {
|
||||
key: $.auth.data?.accessToken,
|
||||
secret: $.auth.data?.accessSecret,
|
||||
};
|
||||
|
||||
const requestData: RequestDataType = {
|
||||
const requestData = {
|
||||
url: `${requestConfig.baseURL}${url}`,
|
||||
method,
|
||||
};
|
@@ -1,11 +1,10 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import crypto from 'crypto';
|
||||
import OAuth from 'oauth-1.0a';
|
||||
|
||||
const oauthClient = ($: IGlobalVariable) => {
|
||||
const oauthClient = ($) => {
|
||||
const consumerData = {
|
||||
key: $.auth.data.consumerKey as string,
|
||||
secret: $.auth.data.consumerSecret as string,
|
||||
key: $.auth.data.consumerKey,
|
||||
secret: $.auth.data.consumerSecret,
|
||||
};
|
||||
|
||||
return new OAuth({
|
3
packages/backend/src/apps/flickr/dynamic-data/index.js
Normal file
3
packages/backend/src/apps/flickr/dynamic-data/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import listAlbums from './list-albums/index.js';
|
||||
|
||||
export default [listAlbums];
|
@@ -1,3 +0,0 @@
|
||||
import listAlbums from './list-albums';
|
||||
|
||||
export default [listAlbums];
|
@@ -1,22 +1,8 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
type TResponse = {
|
||||
data: IJSONObject[];
|
||||
error?: IJSONObject;
|
||||
};
|
||||
|
||||
type TPhotoset = {
|
||||
id: string;
|
||||
title: {
|
||||
_content: string;
|
||||
};
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'List albums',
|
||||
key: 'listAlbums',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 500,
|
||||
@@ -25,9 +11,10 @@ export default {
|
||||
format: 'json',
|
||||
nojsoncallback: 1,
|
||||
};
|
||||
|
||||
let response = await $.http.get('/rest', { params });
|
||||
|
||||
const aggregatedResponse: TResponse = {
|
||||
const aggregatedResponse = {
|
||||
data: [...response.data.photosets.photoset],
|
||||
};
|
||||
|
||||
@@ -42,14 +29,12 @@ export default {
|
||||
aggregatedResponse.data.push(...response.data.photosets.photoset);
|
||||
}
|
||||
|
||||
aggregatedResponse.data = aggregatedResponse.data.map(
|
||||
(photoset: TPhotoset) => {
|
||||
return {
|
||||
value: photoset.id,
|
||||
name: photoset.title._content,
|
||||
} as IJSONObject;
|
||||
}
|
||||
);
|
||||
aggregatedResponse.data = aggregatedResponse.data.map((photoset) => {
|
||||
return {
|
||||
value: photoset.id,
|
||||
name: photoset.title._content,
|
||||
};
|
||||
});
|
||||
|
||||
return aggregatedResponse;
|
||||
},
|
@@ -1,8 +1,8 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
import triggers from './triggers';
|
||||
import dynamicData from './dynamic-data';
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Flickr',
|
6
packages/backend/src/apps/flickr/triggers/index.js
Normal file
6
packages/backend/src/apps/flickr/triggers/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import newAlbums from './new-albums/index.js';
|
||||
import newFavoritePhotos from './new-favorite-photos/index.js';
|
||||
import newPhotos from './new-photos/index.js';
|
||||
import newPhotosInAlbums from './new-photos-in-album/index.js';
|
||||
|
||||
export default [newAlbums, newFavoritePhotos, newPhotos, newPhotosInAlbums];
|
@@ -1,6 +0,0 @@
|
||||
import newAlbums from './new-albums';
|
||||
import newFavoritePhotos from './new-favorite-photos';
|
||||
import newPhotos from './new-photos';
|
||||
import newPhotosInAlbums from './new-photos-in-album';
|
||||
|
||||
export default [newAlbums, newFavoritePhotos, newPhotos, newPhotosInAlbums];
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newAlbums from './new-albums';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import newAlbums from './new-albums.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New albums',
|
@@ -1,5 +1,3 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const extraFields = [
|
||||
'license',
|
||||
'date_upload',
|
||||
@@ -22,7 +20,7 @@ const extraFields = [
|
||||
'url_o',
|
||||
].join(',');
|
||||
|
||||
const newAlbums = async ($: IGlobalVariable) => {
|
||||
const newAlbums = async ($) => {
|
||||
let page = 1;
|
||||
let pages = 1;
|
||||
|
||||
@@ -45,7 +43,7 @@ const newAlbums = async ($: IGlobalVariable) => {
|
||||
$.pushTriggerItem({
|
||||
raw: photoset,
|
||||
meta: {
|
||||
internalId: photoset.id as string,
|
||||
internalId: photoset.id,
|
||||
},
|
||||
});
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newFavoritePhotos from './new-favorite-photos';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import newFavoritePhotos from './new-favorite-photos.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New favorite photos',
|
@@ -1,5 +1,3 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const extraFields = [
|
||||
'description',
|
||||
'license',
|
||||
@@ -28,7 +26,7 @@ const extraFields = [
|
||||
'url_o',
|
||||
].join(',');
|
||||
|
||||
const newPhotos = async ($: IGlobalVariable) => {
|
||||
const newPhotos = async ($) => {
|
||||
let page = 1;
|
||||
let pages = 1;
|
||||
|
||||
@@ -51,7 +49,7 @@ const newPhotos = async ($: IGlobalVariable) => {
|
||||
$.pushTriggerItem({
|
||||
raw: photo,
|
||||
meta: {
|
||||
internalId: photo.date_faved as string,
|
||||
internalId: photo.date_faved,
|
||||
},
|
||||
});
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newPhotosInAlbum from './new-photos-in-album';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import newPhotosInAlbum from './new-photos-in-album.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New photos in album',
|
||||
@@ -10,7 +10,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Album',
|
||||
key: 'album',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
variables: false,
|
||||
source: {
|
@@ -1,5 +1,3 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const extraFields = [
|
||||
'license',
|
||||
'date_upload',
|
||||
@@ -22,7 +20,7 @@ const extraFields = [
|
||||
'url_o',
|
||||
].join(',');
|
||||
|
||||
const newPhotosInAlbum = async ($: IGlobalVariable) => {
|
||||
const newPhotosInAlbum = async ($) => {
|
||||
let page = 1;
|
||||
let pages = 1;
|
||||
|
||||
@@ -32,7 +30,7 @@ const newPhotosInAlbum = async ($: IGlobalVariable) => {
|
||||
per_page: 11,
|
||||
user_id: $.auth.data.userId,
|
||||
extras: extraFields,
|
||||
photoset_id: $.step.parameters.album as string,
|
||||
photoset_id: $.step.parameters.album,
|
||||
method: 'flickr.photosets.getPhotos',
|
||||
format: 'json',
|
||||
nojsoncallback: 1,
|
||||
@@ -46,7 +44,7 @@ const newPhotosInAlbum = async ($: IGlobalVariable) => {
|
||||
$.pushTriggerItem({
|
||||
raw: photo,
|
||||
meta: {
|
||||
internalId: photo.id as string,
|
||||
internalId: photo.id,
|
||||
},
|
||||
});
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newPhotos from './new-photos';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import newPhotos from './new-photos.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New photos',
|
@@ -1,5 +1,3 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const extraFields = [
|
||||
'description',
|
||||
'license',
|
||||
@@ -28,7 +26,7 @@ const extraFields = [
|
||||
'url_o',
|
||||
].join(',');
|
||||
|
||||
const newPhotos = async ($: IGlobalVariable) => {
|
||||
const newPhotos = async ($) => {
|
||||
let page = 1;
|
||||
let pages = 1;
|
||||
|
||||
@@ -51,7 +49,7 @@ const newPhotos = async ($: IGlobalVariable) => {
|
||||
$.pushTriggerItem({
|
||||
raw: photo,
|
||||
meta: {
|
||||
internalId: photo.id as string,
|
||||
internalId: photo.id,
|
||||
},
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user