Skip to content

Commit

Permalink
R2 replacement by MinIO
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkucherenko committed Sep 28, 2024
1 parent 29a5fd2 commit 3a82fb9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ JWT_SECRET="random string for your JWT secret, make it long"
##
## Cloudflare is currently required to save things like social media avatars for accounts.
CLOUDFLARE_ACCOUNT_ID="QhcMSXQyPuMCRpSQcSYdEuTYgHeCXHbu"
#CLOUDFLARE_ENDPOINT=`https://${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com` # uncomment to override the default endpoint
CLOUDFLARE_ACCESS_KEY="dcfCMSuFEeCNfvByUureMZEfxWJmDqZe"
CLOUDFLARE_SECRET_ACCESS_KEY="zTTMXBmtyLPwHEdpACGHgDgzRTNpTJewiNriLnUS"
CLOUDFLARE_BUCKETNAME="postiz"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { makeId } from '@gitroom/nestjs-libraries/services/make.is';
import { OAuth2Client } from 'google-auth-library/build/src/auth/oauth2client';
import { google } from 'googleapis';

const firstNotEmpty = (...args: string[]) => args.find((arg) => arg) ?? '';
const firstNotEmpty = (...args: (string|undefined)[]) => args.find((arg) => arg !== undefined && arg !== '') ?? '';

const clientAndYoutube = () => {
const options = {
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ services:
- 6379:6379
networks:
- postiz-network
postiz-minio:
image: quay.io/minio/minio
container_name: postiz-minio
command: server /data --console-address ":9001"
ports:
- '9000:9000'
- '9001:9001'
networks:
- postiz-network
volumes:
- minio:/data
environment:
- MINIO_ROOT_USER=postiz-minio
- MINIO_ROOT_PASSWORD=postiz-minio-pwd

postiz-pg-admin:
image: dpage/pgadmin4
container_name: postiz-pg-admin
Expand All @@ -47,6 +62,8 @@ services:

volumes:
redisinsight:
minio:
driver: local
postgres-volume:
external: false

Expand Down
6 changes: 4 additions & 2 deletions libraries/nestjs-libraries/src/upload/r2.uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { Request, Response } from 'express';

const { CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_ACCESS_KEY, CLOUDFLARE_SECRET_ACCESS_KEY, CLOUDFLARE_BUCKETNAME, CLOUDFLARE_BUCKET_URL } =
const { CLOUDFLARE_ENDPOINT, CLOUDFLARE_ACCOUNT_ID, CLOUDFLARE_ACCESS_KEY, CLOUDFLARE_SECRET_ACCESS_KEY, CLOUDFLARE_BUCKETNAME, CLOUDFLARE_BUCKET_URL } =
process.env;

const firstNotEmpty = (...args: (string|undefined)[]) => args.find((arg) => arg !== undefined && arg !== '') ?? '';

const R2 = new S3Client({
region: 'auto',
endpoint: `https://${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`,
endpoint: firstNotEmpty(CLOUDFLARE_ENDPOINT, `https://${CLOUDFLARE_ACCOUNT_ID}.r2.cloudflarestorage.com`),
credentials: {
accessKeyId: CLOUDFLARE_ACCESS_KEY!,
secretAccessKey: CLOUDFLARE_SECRET_ACCESS_KEY!,
Expand Down

0 comments on commit 3a82fb9

Please sign in to comment.