avances en plantillas
This commit is contained in:
parent
0f84beacf1
commit
da0530d79b
2062 changed files with 598814 additions and 22 deletions
34
storage/public/dist/libs/plyr/tasks/utils/publish.js
vendored
Normal file
34
storage/public/dist/libs/plyr/tasks/utils/publish.js
vendored
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { PutObjectCommand } from '@aws-sdk/client-s3';
|
||||
import mime from 'mime';
|
||||
import through from 'through2';
|
||||
|
||||
export function publish(client, bucket, headers = {}) {
|
||||
return through.obj(async function (file, _, callback) {
|
||||
if (!file.isBuffer()) return callback(null, file);
|
||||
|
||||
// Use the relative path as the key
|
||||
const key = file.relative.replace(/\\/g, '/'); // Ensure forward slashes for S3 keys
|
||||
|
||||
// Determine the MIME type of the file
|
||||
const contentType = mime.getType(file.path) || 'application/octet-stream';
|
||||
|
||||
try {
|
||||
await client.send(
|
||||
new PutObjectCommand({
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
Body: file.contents,
|
||||
ContentType: contentType, // Set the MIME type
|
||||
CacheControl: headers['Cache-Control'], // Use provided Cache-Control header
|
||||
}),
|
||||
);
|
||||
|
||||
console.warn(`Uploaded: ${key} (Content-Type: ${contentType})`);
|
||||
this.push(file);
|
||||
callback();
|
||||
}
|
||||
catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue