Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const serviceAccountKey: string = process.env.MDC_GCLOUD_SERVICE_ACCOUNT_KEY || '';
const branchName = process.env.MDC_BRANCH_NAME;
const commitHash = process.env.MDC_COMMIT_HASH;
const goldenFilePath = './test/screenshot/golden.json';
const bucketName = 'screenshot-uploads';
const defaultMetadata = {
commit: commitHash,
branch: branchName,
};
const NO_MATCH_DIRECTORY = 'no_match';
let storage: Storage|null = null;
let bucket: Storage.Bucket|null = null;
if (serviceAccountKey) {
storage = new Storage({
credentials: JSON.parse(serviceAccountKey),
});
bucket = storage.bucket(bucketName);
}
export default class Screenshot {
urlPath_: string;
/**
* @param {string} urlPath The URL path to test
*/
constructor(urlPath: string) {
/** @private {string} */
this.urlPath_ = urlPath;
// TODO allow clients to specify capture-chrome options, like viewport size
}
constructor(options) {
super(options);
const gcs = gcStorage(options.connection);
this.bucket = gcs.bucket(options.bucket);
options.getPath = options.getPath || function(file) {
return file._id;
};
this.getPath = function(file) {
if (file.GoogleStorage) {
return file.GoogleStorage.path;
}
// Compatibility
// TODO: Migration
if (file.googleCloudStorage) {
return file.googleCloudStorage.path + file._id;
}
};
constructor(config) {
this[scope] = {
client: gcs(config).bucket(config.bucket),
}
}
constructor(uploadDir) {
this.uploadDir = uploadDir;
const storage = new Storage({
credentials,
});
this.bucket = storage.bucket(bucketName);
}
connect() {
if (this.isConnected) {
return;
}
this.client = gcs(
merge(
this.storageOptions,
{
promise: Promise,
}
)
);
this.isConnected = true;
}