-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
228 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import { EnvoyVariableSpec } from '@interval/envoy' | ||
|
||
const vars: EnvoyVariableSpec[] = ['DEMO_API_KEY'] | ||
const vars: EnvoyVariableSpec[] = [ | ||
'DEMO_API_KEY', | ||
{ name: 'AWS_KEY_ID', isRequired: false }, | ||
{ name: 'AWS_KEY_SECRET', isRequired: false }, | ||
{ name: 'AWS_S3_IO_BUCKET', isRequired: false }, | ||
{ name: 'AWS_REGION', isRequired: false }, | ||
] | ||
|
||
export default vars |
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
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ import { | |
} from './selectFromTable' | ||
import unauthorized from './unauthorized' | ||
import './ghostHost' | ||
import { generateS3Urls } from '../utils/upload' | ||
|
||
const actionLinks: IntervalActionHandler = async () => { | ||
await io.group([ | ||
|
@@ -127,6 +128,70 @@ const interval = new Interval({ | |
logLevel: 'debug', | ||
endpoint: 'ws://localhost:3000/websocket', | ||
actions: { | ||
disabled_inputs: async io => { | ||
await io.group([ | ||
io.display.heading('Here are a bunch of disabled inputs'), | ||
io.input.text('Text input', { | ||
disabled: true, | ||
placeholder: 'Text goes here', | ||
}), | ||
io.experimental.datetime('Date & time', { disabled: true }), | ||
io.input.boolean('Boolean input', { disabled: true }), | ||
io.select.single('Select something', { | ||
options: [1, 2, 3], | ||
disabled: true, | ||
}), | ||
io.input.number('Number input', { | ||
disabled: true, | ||
}), | ||
io.input.email('Email input', { disabled: true }), | ||
io.input.richText('Rich text input', { disabled: true }), | ||
io.search('Search for a user', { | ||
disabled: true, | ||
renderResult: user => ({ | ||
label: user.name, | ||
description: user.email, | ||
}), | ||
onSearch: async query => { | ||
return [ | ||
{ | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
}, | ||
] | ||
}, | ||
}), | ||
io.select.multiple('Select multiple of something', { | ||
options: [1, 2, 3], | ||
disabled: true, | ||
}), | ||
io.select.table('Select from table', { | ||
data: [ | ||
{ | ||
album: 'Exile on Main Street', | ||
artist: 'The Rolling Stones', | ||
year: 1972, | ||
}, | ||
{ | ||
artist: 'Michael Jackson', | ||
album: 'Thriller', | ||
year: 1982, | ||
}, | ||
{ | ||
album: 'Enter the Wu-Tang (36 Chambers)', | ||
artist: 'Wu-Tang Clan', | ||
year: 1993, | ||
}, | ||
], | ||
disabled: true, | ||
}), | ||
io.experimental.date('Date input', { disabled: true }), | ||
io.experimental.time('Time input', { disabled: true }), | ||
io.experimental.input.file('File input', { disabled: true }), | ||
]) | ||
|
||
return 'Done!' | ||
}, | ||
'long-return-string': async io => { | ||
return { | ||
date: new Date(), | ||
|
@@ -312,7 +377,7 @@ const interval = new Interval({ | |
}, | ||
dates: async io => { | ||
const [date, time, datetime] = await io.group([ | ||
io.experimental.date('Enter a date', { | ||
io.input.date('Enter a date', { | ||
min: { | ||
year: 2020, | ||
month: 1, | ||
|
@@ -324,7 +389,7 @@ const interval = new Interval({ | |
day: 30, | ||
}, | ||
}), | ||
io.experimental.time('Enter a time', { | ||
io.input.time('Enter a time', { | ||
min: { | ||
hour: 8, | ||
minute: 30, | ||
|
@@ -334,7 +399,7 @@ const interval = new Interval({ | |
minute: 0, | ||
}, | ||
}), | ||
io.experimental.datetime('Enter a datetime', { | ||
io.input.datetime('Enter a datetime', { | ||
defaultValue: new Date(), | ||
min: new Date(), | ||
}), | ||
|
@@ -676,10 +741,27 @@ const interval = new Interval({ | |
|
||
return { message: 'OK, notified!' } | ||
}, | ||
upload: async io => { | ||
upload: async (io, ctx) => { | ||
const customDestinationFile = await io.experimental.input.file( | ||
'Upload an image!', | ||
{ | ||
helpText: 'Will be uploaded to the custom destination.', | ||
allowedExtensions: ['.gif', '.jpg', '.jpeg', '.png'], | ||
generatePresignedUrls: async ({ name }) => { | ||
const urlSafeName = name.replace(/ /g, '-') | ||
const path = `custom-endpoint/${new Date().getTime()}-${urlSafeName}` | ||
|
||
return generateS3Urls(path) | ||
}, | ||
} | ||
) | ||
|
||
console.log(await customDestinationFile.url()) | ||
|
||
const file = await io.experimental.input.file('Upload an image!', { | ||
helpText: 'Can be any image, or a CSV (?).', | ||
allowedExtensions: ['.gif', '.jpg', '.jpeg', 'csv'], | ||
helpText: | ||
'Will be uploaded to Interval and expire after the action finishes running.', | ||
allowedExtensions: ['.gif', '.jpg', '.jpeg', '.png'], | ||
}) | ||
|
||
console.log(file) | ||
|
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,41 @@ | ||
import { | ||
AWS_REGION, | ||
AWS_KEY_ID, | ||
AWS_KEY_SECRET, | ||
AWS_S3_IO_BUCKET, | ||
} from '../../env' | ||
import { | ||
GetObjectCommand, | ||
PutObjectCommand, | ||
S3Client, | ||
} from '@aws-sdk/client-s3' | ||
import { getSignedUrl } from '@aws-sdk/s3-request-presigner' | ||
import * as urlParser from '@aws-sdk/url-parser' | ||
|
||
export async function generateS3Urls(key: string) { | ||
if (!AWS_KEY_ID || !AWS_KEY_SECRET || !AWS_S3_IO_BUCKET) { | ||
throw new Error('Missing AWS credentials') | ||
} | ||
|
||
const s3Client = new S3Client({ | ||
region: AWS_REGION ?? 'us-west-1', | ||
credentials: { | ||
accessKeyId: AWS_KEY_ID, | ||
secretAccessKey: AWS_KEY_SECRET, | ||
}, | ||
}) | ||
|
||
const command = new PutObjectCommand({ | ||
Bucket: AWS_S3_IO_BUCKET, | ||
Key: key, | ||
}) | ||
|
||
const uploadUrl = await getSignedUrl(s3Client, command, { | ||
expiresIn: 3600, // 1 hour | ||
}) | ||
|
||
const url = new URL(uploadUrl) | ||
const downloadUrl = url.origin + url.pathname | ||
|
||
return { uploadUrl, downloadUrl } | ||
} |
Oops, something went wrong.