-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathfunction.js
More file actions
31 lines (26 loc) · 953 Bytes
/
function.js
File metadata and controls
31 lines (26 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2020-2025 ETH Zurich and the SeBS authors. All rights reserved.
import * as fs from 'node:fs';
import * as path from 'node:path';
import { storage } from './storage';
let storage_handler = new storage();
export const handler = async function(event) {
let bucket = event.bucket.bucket;
let output_prefix = event.bucket.output;
let url = event.object.url;
let upload_key = path.basename(url);
let download_path = path.join('/tmp', upload_key);
const response = await fetch(url, {
headers: {
'User-Agent': 'SeBS/1.2 (https://github.com/spcl/serverless-benchmarks) SeBS Benchmark Suite/1.2'
}
});
const buffer = await response.arrayBuffer();
fs.writeFileSync(download_path, Buffer.from(buffer));
let [keyName, uploadPromise] = storage_handler.upload(
bucket,
path.join(output_prefix, upload_key),
download_path
);
await uploadPromise;
return {bucket: bucket, url: url, key: keyName};
};