Try uploading to Bunny
This commit is contained in:
1 parent
009cb52246
commit
74966a23f6
4 files changed
+110
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import pMap from 'p-map';
|
||||
import { readdir, lstat } from 'node:fs/promises';
|
||||
import { createReadStream } from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
const config = {
|
||||
endpoint: process.env.BUNNY_STORAGE_ENDPOINT,
|
||||
password: process.env.BUNNY_STORAGE_PASSWORD,
|
||||
bucket: process.env.BUNNY_STORAGE_BUCKET
|
||||
};
|
||||
|
||||
const files = await readdir('./_site', { recursive: true });
|
||||
|
||||
|
||||
await pMap(files, async (file) => {
|
||||
const filePath = path.join('./_site', file);
|
||||
const stat = await lstat(filePath);
|
||||
if (stat.isDirectory()) return;
|
||||
|
||||
const url = `https://${config.endpoint}/${config.bucket}/${file}`;
|
||||
console.log(`Uploading ${filePath} to ${url}`);
|
||||
|
||||
const readStream = createReadStream(filePath);
|
||||
|
||||
await fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
accessKey: config.password,
|
||||
},
|
||||
body: readStream,
|
||||
duplex: 'half'
|
||||
});
|
||||
}, { concurrency: 50 });
|
||||
Reference in new issue
Block a user