also upload protobufs to r2

This commit is contained in:
adueck 2023-12-18 17:22:00 +04:00
parent d0d2773871
commit 72691403cd
8 changed files with 4109 additions and 1464 deletions

View File

@ -9,7 +9,7 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@lingdocs/inflect": "7.0.3",
"@lingdocs/inflect": "7.0.7",
"base64url": "^3.0.1",
"bcryptjs": "^2.4.3",
"connect-redis": "^6.0.0",
@ -126,9 +126,9 @@
}
},
"node_modules/@lingdocs/inflect": {
"version": "7.0.3",
"resolved": "https://npm.lingdocs.com/@lingdocs/inflect/-/inflect-7.0.3.tgz",
"integrity": "sha512-Ia4upjGHRUf6zuJ626V4g1AcaQQ5uKm8aHRn5qWYw1xEfBtSPHTvLd8Y6TXUjglv7HZ8udUXoP2LIGPWlD2aYA==",
"version": "7.0.7",
"resolved": "https://npm.lingdocs.com/@lingdocs/inflect/-/inflect-7.0.7.tgz",
"integrity": "sha512-I47qXKBqFNR1mRK5z5vKhd1hJrrdrKy0A0z1p+eCB8SFB1Np65rcalWIzJLH52JPoahCmTi8TxaBM85kV2j5lQ==",
"dependencies": {
"fp-ts": "^2.16.0",
"pbf": "^3.2.1",
@ -3109,9 +3109,9 @@
}
},
"@lingdocs/inflect": {
"version": "7.0.3",
"resolved": "https://npm.lingdocs.com/@lingdocs/inflect/-/inflect-7.0.3.tgz",
"integrity": "sha512-Ia4upjGHRUf6zuJ626V4g1AcaQQ5uKm8aHRn5qWYw1xEfBtSPHTvLd8Y6TXUjglv7HZ8udUXoP2LIGPWlD2aYA==",
"version": "7.0.7",
"resolved": "https://npm.lingdocs.com/@lingdocs/inflect/-/inflect-7.0.7.tgz",
"integrity": "sha512-I47qXKBqFNR1mRK5z5vKhd1hJrrdrKy0A0z1p+eCB8SFB1Np65rcalWIzJLH52JPoahCmTi8TxaBM85kV2j5lQ==",
"requires": {
"fp-ts": "^2.16.0",
"pbf": "^3.2.1",

View File

@ -12,7 +12,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@lingdocs/inflect": "7.0.3",
"@lingdocs/inflect": "7.0.7",
"base64url": "^3.0.1",
"bcryptjs": "^2.4.3",
"connect-redis": "^6.0.0",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -14,8 +14,9 @@
},
"main": "lib/functions/src/index.js",
"dependencies": {
"@aws-sdk/client-s3": "^3.474.0",
"@google-cloud/storage": "^5.8.1",
"@lingdocs/inflect": "7.0.3",
"@lingdocs/inflect": "7.0.7",
"@types/cors": "^2.8.10",
"@types/google-spreadsheet": "^3.0.2",
"@types/react": "^18.0.21",

View File

@ -14,6 +14,16 @@ import {
import { getWordList } from "./word-list-maker";
import { PublishDictionaryResponse } from "../../website/src/types/functions-types";
import { Storage } from "@google-cloud/storage";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
const s3Client = new S3Client({
region: "auto",
endpoint: functions.config().r2.endpoint,
credentials: {
accessKeyId: functions.config().r2.access_key_id,
secretAccessKey: functions.config().r2.secret_access_key,
},
});
const storage = new Storage({
projectId: "lingdocs",
});
@ -221,20 +231,41 @@ function checkForErrors(
async function upload(content: Buffer | string, filename: string) {
const isBuffer = typeof content !== "string";
const file = storage.bucket(bucketName).file(filename);
// upload to Google Cloud Storage (will be deprecated / removed)
const metadata = {
contentType: isBuffer
? "application/octet-stream"
: filename.endsWith(".json")
? "application/json"
: filename.endsWith(".xml")
? "application/xml"
: "text/plain; charset=UTF-8",
cacheControl: "no-cache",
};
await file.save(content, {
gzip: isBuffer ? false : true,
predefinedAcl: "publicRead",
metadata: {
contentType: isBuffer
? "application/octet-stream"
: filename.endsWith(".json")
? "application/json"
: filename.endsWith(".xml")
? "application/xml"
: "text/plain; charset=UTF-8",
cacheControl: "no-cache",
},
metadata,
});
// upload to r2 (new destination)
const Metadata = {
"Content-Type": isBuffer
? "application/octet-stream"
: filename.endsWith(".json")
? "application/json"
: filename.endsWith(".xml")
? "application/xml"
: "text/plain; charset=UTF-8",
"Cache-Control": "no-cache",
};
// TODO: GZIP FILES
const putObjectCommand = new PutObjectCommand({
Bucket: functions.config().r2.bucket_name,
Key: `dictionary/${filename}`,
Body: content,
Metadata,
});
await s3Client.send(putObjectCommand);
}
// async function uploadHunspellToStorage(wordlist: {

View File

@ -7,7 +7,7 @@
"private": true,
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.2",
"@lingdocs/ps-react": "7.0.3",
"@lingdocs/ps-react": "7.0.7",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",

View File

@ -2349,10 +2349,10 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"
"@lingdocs/ps-react@7.0.3":
version "7.0.3"
resolved "https://npm.lingdocs.com/@lingdocs/ps-react/-/ps-react-7.0.3.tgz#9962fca6a7eeec1d9eec7938ca5fbf2c8634c228"
integrity sha512-/ASFFGudbqjEaZQ5OSHAwCQaZSdnPPInWv30rLR6ytLA+lS2udXLQHXkW+3ArUQ1UFBQlK1AC2+1tKNxvD2IrQ==
"@lingdocs/ps-react@7.0.7":
version "7.0.7"
resolved "https://npm.lingdocs.com/@lingdocs/ps-react/-/ps-react-7.0.7.tgz#030d7b614027d944b4228cbeac67bffec206a1ff"
integrity sha512-H/md+cDteBPry8wrI0uvhQIdGz97BqwPollj3c8NANc7ryUGNS7wbwRA20ayGn7AaiwpERhu/1+VzW4YEqM8vw==
dependencies:
"@formkit/auto-animate" "^1.0.0-beta.3"
classnames "^2.2.6"