|
|
|
@ -10,6 +10,9 @@ const { |
|
|
|
const { BuildSchemaErrors, InvalidColumns } = require("../../constants") |
|
|
|
const { integrations } = require("../../integrations") |
|
|
|
const { getDatasourceAndQuery } = require("./row/utils") |
|
|
|
const AWS = require("aws-sdk") |
|
|
|
const env = require("../../environment") |
|
|
|
const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1" |
|
|
|
|
|
|
|
exports.fetch = async function (ctx) { |
|
|
|
const database = new CouchDB(ctx.appId) |
|
|
|
@ -152,6 +155,35 @@ exports.query = async function (ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
exports.getSignedS3URL = async function (ctx) { |
|
|
|
const { datasourceId, bucket, key } = ctx.request.body || {} |
|
|
|
if (!datasourceId || !bucket || !key) { |
|
|
|
ctx.throw(400, "datasourceId, bucket and key must be specified") |
|
|
|
return |
|
|
|
} |
|
|
|
const database = new CouchDB(ctx.appId) |
|
|
|
const datasource = await database.get(datasourceId) |
|
|
|
if (!datasource) { |
|
|
|
ctx.throw(400, "The specified datasource could not be found") |
|
|
|
return |
|
|
|
} |
|
|
|
let signedUrl |
|
|
|
try { |
|
|
|
const s3 = new AWS.S3({ |
|
|
|
region: AWS_REGION, |
|
|
|
accessKeyId: datasource?.config?.accessKeyId, |
|
|
|
secretAccessKey: datasource?.config?.secretAccessKey, |
|
|
|
apiVersion: "2006-03-01", |
|
|
|
signatureVersion: "v4", |
|
|
|
}) |
|
|
|
const params = { Bucket: bucket, Key: key } |
|
|
|
signedUrl = s3.getSignedUrl("putObject", params) |
|
|
|
} catch (error) { |
|
|
|
ctx.throw(400, error) |
|
|
|
} |
|
|
|
ctx.body = { signedUrl } |
|
|
|
} |
|
|
|
|
|
|
|
function getErrorTables(errors, errorType) { |
|
|
|
return Object.entries(errors) |
|
|
|
.filter(entry => entry[1] === errorType) |
|
|
|
|