with gzip for r2
This commit is contained in:
parent
72691403cd
commit
8cb1d8f043
|
@ -15,6 +15,7 @@ import { getWordList } from "./word-list-maker";
|
||||||
import { PublishDictionaryResponse } from "../../website/src/types/functions-types";
|
import { PublishDictionaryResponse } from "../../website/src/types/functions-types";
|
||||||
import { Storage } from "@google-cloud/storage";
|
import { Storage } from "@google-cloud/storage";
|
||||||
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
||||||
|
import zlib from "zlib";
|
||||||
const s3Client = new S3Client({
|
const s3Client = new S3Client({
|
||||||
region: "auto",
|
region: "auto",
|
||||||
endpoint: functions.config().r2.endpoint,
|
endpoint: functions.config().r2.endpoint,
|
||||||
|
@ -258,14 +259,29 @@ async function upload(content: Buffer | string, filename: string) {
|
||||||
: "text/plain; charset=UTF-8",
|
: "text/plain; charset=UTF-8",
|
||||||
"Cache-Control": "no-cache",
|
"Cache-Control": "no-cache",
|
||||||
};
|
};
|
||||||
// TODO: GZIP FILES
|
if (isBuffer) {
|
||||||
const putObjectCommand = new PutObjectCommand({
|
const putObjectCommand = new PutObjectCommand({
|
||||||
Bucket: functions.config().r2.bucket_name,
|
Bucket: functions.config().r2.bucket_name,
|
||||||
Key: `dictionary/${filename}`,
|
Key: `dictionary/${filename}`,
|
||||||
Body: content,
|
Body: content,
|
||||||
Metadata,
|
Metadata,
|
||||||
});
|
});
|
||||||
await s3Client.send(putObjectCommand);
|
await s3Client.send(putObjectCommand);
|
||||||
|
} else {
|
||||||
|
zlib.gzip(content, (err, buffer) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
const putObjectCommand = new PutObjectCommand({
|
||||||
|
Bucket: functions.config().r2.bucket_name,
|
||||||
|
Key: `dictionary/${filename}`,
|
||||||
|
Metadata,
|
||||||
|
Body: buffer,
|
||||||
|
ContentEncoding: "gzip",
|
||||||
|
});
|
||||||
|
s3Client.send(putObjectCommand);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// async function uploadHunspellToStorage(wordlist: {
|
// async function uploadHunspellToStorage(wordlist: {
|
||||||
|
|
Loading…
Reference in New Issue