Skip to content

Commit

Permalink
🔨 rename R2 settings to generic names
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Jul 31, 2024
1 parent a126120 commit 2829093
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
6 changes: 3 additions & 3 deletions .env.devcontainer
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ GDOCS_CLIENT_ID=''
GDOCS_BASIC_ARTICLE_TEMPLATE_URL=''
GDOCS_SHARED_DRIVE_ID=''

IMAGE_HOSTING_R2_ENDPOINT=''
R2_ENDPOINT=''
IMAGE_HOSTING_R2_CDN_URL=''
IMAGE_HOSTING_R2_BUCKET_PATH=''
IMAGE_HOSTING_R2_ACCESS_KEY_ID=''
IMAGE_HOSTING_R2_SECRET_ACCESS_KEY=''
R2_ACCESS_KEY_ID=''
R2_SECRET_ACCESS_KEY=''
6 changes: 3 additions & 3 deletions .env.example-full
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ GDOCS_BASIC_ARTICLE_TEMPLATE_URL=
GDOCS_SHARED_DRIVE_ID=
GDOCS_DONATE_FAQS_DOCUMENT_ID= # optional

IMAGE_HOSTING_R2_ENDPOINT= # optional
R2_ENDPOINT= # optional
IMAGE_HOSTING_R2_CDN_URL=
IMAGE_HOSTING_R2_BUCKET_PATH=
IMAGE_HOSTING_R2_ACCESS_KEY_ID= # optional
IMAGE_HOSTING_R2_SECRET_ACCESS_KEY= # optional
R2_ACCESS_KEY_ID= # optional
R2_SECRET_ACCESS_KEY= # optional

OPENAI_API_KEY=

Expand Down
16 changes: 8 additions & 8 deletions db/model/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import {
} from "@ourworldindata/utils"
import { OwidGoogleAuth } from "../OwidGoogleAuth.js"
import {
IMAGE_HOSTING_R2_ENDPOINT,
IMAGE_HOSTING_R2_ACCESS_KEY_ID,
IMAGE_HOSTING_R2_SECRET_ACCESS_KEY,
IMAGE_HOSTING_R2_REGION,
R2_ENDPOINT,
R2_ACCESS_KEY_ID,
R2_SECRET_ACCESS_KEY,
R2_REGION,
IMAGE_HOSTING_R2_BUCKET_PATH,
GDOCS_CLIENT_EMAIL,
GDOCS_SHARED_DRIVE_ID,
Expand Down Expand Up @@ -139,12 +139,12 @@ class ImageStore {
export const imageStore = new ImageStore()

export const s3Client = new S3Client({
endpoint: IMAGE_HOSTING_R2_ENDPOINT,
endpoint: R2_ENDPOINT,
forcePathStyle: false,
region: IMAGE_HOSTING_R2_REGION,
region: R2_REGION,
credentials: {
accessKeyId: IMAGE_HOSTING_R2_ACCESS_KEY_ID,
secretAccessKey: IMAGE_HOSTING_R2_SECRET_ACCESS_KEY,
accessKeyId: R2_ACCESS_KEY_ID,
secretAccessKey: R2_SECRET_ACCESS_KEY,
},
})

Expand Down
18 changes: 8 additions & 10 deletions settings/serverSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,20 @@ export const IMAGE_HOSTING_R2_BUCKET_SUBFOLDER_PATH: string =
IMAGE_HOSTING_R2_BUCKET_PATH.indexOf("/") + 1
)
// extract R2 credentials from rclone config as defaults
export const IMAGE_HOSTING_R2_ENDPOINT: string =
serverSettings.IMAGE_HOSTING_R2_ENDPOINT ||
export const R2_ENDPOINT: string =
serverSettings.R2_ENDPOINT ||
rcloneConfig["owid-r2"]?.endpoint ||
"https://078fcdfed9955087315dd86792e71a7e.r2.cloudflarestorage.com"
export const IMAGE_HOSTING_R2_ACCESS_KEY_ID: string =
serverSettings.IMAGE_HOSTING_R2_ACCESS_KEY_ID ||
export const R2_ACCESS_KEY_ID: string =
serverSettings.R2_ACCESS_KEY_ID ||
rcloneConfig["owid-r2"]?.access_key_id ||
""
export const IMAGE_HOSTING_R2_SECRET_ACCESS_KEY: string =
serverSettings.IMAGE_HOSTING_R2_SECRET_ACCESS_KEY ||
export const R2_SECRET_ACCESS_KEY: string =
serverSettings.R2_SECRET_ACCESS_KEY ||
rcloneConfig["owid-r2"]?.secret_access_key ||
""
export const IMAGE_HOSTING_R2_REGION: string =
serverSettings.IMAGE_HOSTING_R2_REGION ||
rcloneConfig["owid-r2"]?.region ||
"auto"
export const R2_REGION: string =
serverSettings.R2_REGION || rcloneConfig["owid-r2"]?.region || "auto"

export const DATA_API_URL: string = clientSettings.DATA_API_URL

Expand Down
8 changes: 3 additions & 5 deletions site/gdocs/components/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
import cx from "classnames"
import { LIGHTBOX_IMAGE_CLASS } from "../../Lightbox.js"
import {
IMAGE_HOSTING_R2_BUCKET_SUBFOLDER_PATH,
IMAGE_HOSTING_R2_CDN_URL,
R2_BUCKET_SUBFOLDER_PATH,

Check failure on line 12 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / testcheck

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_BUCKET_SUBFOLDER_PATH'.

Check failure on line 12 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / testdbcheck

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_BUCKET_SUBFOLDER_PATH'.

Check failure on line 12 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / bundlewatch

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_BUCKET_SUBFOLDER_PATH'.

Check failure on line 12 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / bundlewatch

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_BUCKET_SUBFOLDER_PATH'.

Check failure on line 12 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / testcheck

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_BUCKET_SUBFOLDER_PATH'.

Check failure on line 12 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / testdbcheck

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_BUCKET_SUBFOLDER_PATH'.
R2_CDN_URL,

Check failure on line 13 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / testcheck

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_CDN_URL'.

Check failure on line 13 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / testdbcheck

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_CDN_URL'.

Check failure on line 13 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / bundlewatch

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_CDN_URL'.

Check failure on line 13 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / bundlewatch

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_CDN_URL'.

Check failure on line 13 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / testcheck

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_CDN_URL'.

Check failure on line 13 in site/gdocs/components/Image.tsx

View workflow job for this annotation

GitHub Actions / testdbcheck

Module '"../../../settings/clientSettings.js"' has no exported member 'R2_CDN_URL'.
} from "../../../settings/clientSettings.js"
import { DocumentContext } from "../OwidGdoc.js"
import { Container } from "./ArticleBlock.js"
Expand Down Expand Up @@ -115,9 +115,7 @@ export default function Image(props: {

if (isPreviewing) {
const makePreviewUrl = (f: string) =>
`${IMAGE_HOSTING_R2_CDN_URL}/${IMAGE_HOSTING_R2_BUCKET_SUBFOLDER_PATH}/${encodeURIComponent(
f
)}`
`${R2_CDN_URL}/${R2_BUCKET_SUBFOLDER_PATH}/${encodeURIComponent(f)}`

const PreviewSource = (props: { i?: ImageMetadata; sm?: boolean }) => {
const { i, sm } = props
Expand Down

0 comments on commit 2829093

Please sign in to comment.