@teamkeel/functions-runtime 0.395.1 → 0.395.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamkeel/functions-runtime",
3
- "version": "0.395.1",
3
+ "version": "0.395.2",
4
4
  "description": "Internal package used by @teamkeel/sdk",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -21,6 +21,7 @@
21
21
  "dependencies": {
22
22
  "@aws-sdk/client-s3": "^3.637.0",
23
23
  "@aws-sdk/credential-providers": "^3.637.0",
24
+ "@aws-sdk/s3-request-presigner": "^3.637.0",
24
25
  "@neondatabase/serverless": "^0.9.4",
25
26
  "@opentelemetry/api": "^1.7.0",
26
27
  "@opentelemetry/exporter-trace-otlp-proto": "^0.46.0",
package/src/File.js CHANGED
@@ -4,6 +4,7 @@ const {
4
4
  GetObjectCommand,
5
5
  } = require("@aws-sdk/client-s3");
6
6
  const { fromEnv } = require("@aws-sdk/credential-providers");
7
+ const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
7
8
  const { createDatabaseClient } = require("./database");
8
9
  const { DatabaseError } = require("./errors");
9
10
  const KSUID = require("ksuid");
@@ -157,6 +158,30 @@ class File extends InlineFile {
157
158
  return this;
158
159
  }
159
160
 
161
+ async getPresignedUrl() {
162
+ if (isS3Storage()) {
163
+ const s3Client = new S3Client({
164
+ credentials: fromEnv(),
165
+ region: process.env.KEEL_REGION,
166
+ });
167
+
168
+ const command = new GetObjectCommand({
169
+ Bucket: process.env.KEEL_FILES_BUCKET_NAME,
170
+ Key: "files/" + this.key(),
171
+ });
172
+
173
+ const url = await getSignedUrl(s3Client, command, { expiresIn: 60 * 24 });
174
+
175
+ return new URL(url);
176
+ } else {
177
+ const contents = await this.read();
178
+ const dataurl = `data:${this.contentType};name=${
179
+ this.filename
180
+ };base64,${contents.toString("base64")}`;
181
+ return new URL(dataurl);
182
+ }
183
+ }
184
+
160
185
  toDbRecord() {
161
186
  return {
162
187
  key: this.key,
package/src/index.d.ts CHANGED
@@ -176,6 +176,9 @@ export declare class File extends InlineFile {
176
176
  get key(): string;
177
177
  // Gets size of the file's contents in bytes
178
178
  get isPublic(): boolean;
179
+ // Generates a presigned download URL
180
+ getPresignedUrl(): Promise<URL>;
181
+ // Creates a new instance from the database record
179
182
  static fromDbRecord(input: FileDbRecord): File;
180
183
  // Persists the file
181
184
  toDbRecord(): FileDbRecord;