Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

Add support to specify s3 filenames for screenshots #351

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,14 @@ export default class Chromeless<T extends any> implements Promise<T> {
selector?: string,
options?: ScreenshotOptions,
): Chromeless<string> {
if (typeof selector === 'object') {
options = selector
selector = undefined
}
// I am not sure why this code was here; it seems to be causing a bug
// where options can not be passed correctly (any options passed will be
// seen as a selector)
//
//if (typeof selector === 'object') {
// options = selector
// selector = undefined
//}
this.lastReturnPromise = this.queue.process<string>({
type: 'returnScreenshot',
selector,
Expand Down
2 changes: 1 addition & 1 deletion src/chrome/local-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export default class LocalRuntime {
const data = await screenshot(this.client, selector)

if (isS3Configured()) {
return await uploadToS3(data, 'image/png')
return await uploadToS3(data, 'image/png', options && options.s3ObjectKeyPrefixOverride)
} else {
return writeToFile(data, 'png', options && options.filePath)
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export interface PdfOptions {

export interface ScreenshotOptions {
filePath?: string
s3ObjectKeyPrefixOverride?: string //string to use as key when saving screenshots to s3
}

export type Quad = Array<number>
Expand Down
5 changes: 3 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,9 @@ export async function uploadToS3(
const s3ContentType = s3ContentTypes[contentType]
if (!s3ContentType) {
throw new Error(`Unknown S3 Content type ${contentType}`)
}
const s3Path = `${getS3ObjectKeyPrefix()}${cuid()}.${s3ContentType.extension}`
}
const s3Prefix = s3ObjectKeyPrefixOverride || `${getS3ObjectKeyPrefix()}`
const s3Path = `${s3Prefix}${cuid()}.${s3ContentType.extension}`
const s3 = new AWS.S3()
await s3
.putObject({
Expand Down