From e5e26d4624fe63c779d262b3228b37d20d89c8fb Mon Sep 17 00:00:00 2001 From: Boldizsar Mezei Date: Sun, 19 May 2024 13:04:28 +0200 Subject: [PATCH] Remove DEV bucket --- .../src/controls/file/file.upload.control.ts | 5 ++--- packages/functions/src/services/joi/common.ts | 6 ------ packages/functions/src/utils/config.utils.ts | 6 +----- packages/functions/src/utils/media.utils.ts | 13 +++---------- .../functions/test-tangle/stamp-tangle/Helper.ts | 2 +- .../stamp-tangle/stamp-tangle_5.spec.ts | 2 +- .../deposit-withraw-nft_9.spec.ts | 2 +- .../functions/test/controls/collection.spec.ts | 2 +- packages/functions/test/controls/nft.spec.ts | 2 +- .../functions/test/controls/stamp.control.spec.ts | 2 +- packages/functions/test/storage/resize.img.spec.ts | 14 +++++++------- packages/interfaces/src/config.ts | 1 - 12 files changed, 19 insertions(+), 38 deletions(-) diff --git a/packages/functions/src/controls/file/file.upload.control.ts b/packages/functions/src/controls/file/file.upload.control.ts index a8f1ce1b1..e8ed65bbe 100644 --- a/packages/functions/src/controls/file/file.upload.control.ts +++ b/packages/functions/src/controls/file/file.upload.control.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { storage } from '@buildcore/database'; -import { Bucket, FileUploadRequest, WenError, generateRandomFileName } from '@buildcore/interfaces'; +import { FileUploadRequest, WenError, generateRandomFileName } from '@buildcore/interfaces'; import busboy from 'busboy'; import fs from 'fs'; import jwt from 'jsonwebtoken'; @@ -32,8 +32,7 @@ export const uploadFileControl = async ({ headers, rawBody }: Context diff --git a/packages/functions/src/services/joi/common.ts b/packages/functions/src/services/joi/common.ts index 788d6d0ed..2afba6d38 100644 --- a/packages/functions/src/services/joi/common.ts +++ b/packages/functions/src/services/joi/common.ts @@ -33,15 +33,9 @@ export const isStorageUrl = (url: string | undefined) => export const BUCKET_BASE_URLS = { [Bucket.PROD]: 'https://' + Bucket.PROD + '/', [Bucket.TEST]: 'https://' + Bucket.TEST + '/', - [Bucket.DEV]: `https://storage.googleapis.com/download/storage/v1/b/${Bucket.DEV}/o/`, }; const startsWithBaseUrl = (url: string) => { - if (isDevEnv()) { - return ( - url.startsWith(BUCKET_BASE_URLS[Bucket.DEV]) || url.startsWith(BUCKET_BASE_URLS[Bucket.TEST]) - ); - } if (isProdEnv()) { return url.startsWith(BUCKET_BASE_URLS[Bucket.PROD]); } diff --git a/packages/functions/src/utils/config.utils.ts b/packages/functions/src/utils/config.utils.ts index 04d5cb41b..2a760004b 100644 --- a/packages/functions/src/utils/config.utils.ts +++ b/packages/functions/src/utils/config.utils.ts @@ -55,7 +55,7 @@ export const getBucket = () => { if (isTestEnv()) { return Bucket.TEST; } - return Bucket.DEV; + throw new Error(`Invalid env ${process.env.ENVIRONMENT}`); }; export const getJwtSecretKey = () => process.env.JWT_SECRET!; @@ -65,10 +65,6 @@ export const getCustomTokenLifetime = (func: WEN_FUNC) => CUSTOM_TOKEN_MAX_LIFET export const algoliaAppId = () => process.env.ALGOLIA_APPID!; export const algoliaKey = () => process.env.ALGOLIA_KEY!; -export const xpTokenId = () => process.env.XPTOKEN_ID!; -export const xpTokenUid = () => process.env.XPTOKEN_UID!; -export const xpTokenGuardianId = () => process.env.XPTOKEN_GUARDIANID!; - export const getStampRoyaltyAddress = (network: Network) => STAMP_ROYALTY_ADDRESS[network]; export const getDefaultNetwork = () => (isProdEnv() ? Network.IOTA : Network.ATOI); diff --git a/packages/functions/src/utils/media.utils.ts b/packages/functions/src/utils/media.utils.ts index 62b5b3e59..bb1990c48 100644 --- a/packages/functions/src/utils/media.utils.ts +++ b/packages/functions/src/utils/media.utils.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { IBucket, storage } from '@buildcore/database'; import { - Bucket, COL, IMAGE_CACHE_AGE, IPFS_GATEWAY, @@ -33,13 +32,11 @@ export const migrateUriToSotrage = async ( fs.mkdirSync(workdir); const { fileName, contentType } = await downloadMedia(workdir, url, allowAnyType); const destination = `${owner}/${uid}/${fileName}`; - const response = await bucket.upload(path.join(workdir, fileName), destination, { + await bucket.upload(path.join(workdir, fileName), destination, { contentType, cacheControl: `public,max-age=${IMAGE_CACHE_AGE}`, }); - const buildcoreUrl = - bucket.getName() === Bucket.DEV ? response : `https://${bucket.getName()}/${destination}`; - return buildcoreUrl; + return `https://${bucket.getName()}/${destination}`; } catch (error: any) { logger.error('migrateUriToSotrage - error', col, uid, error); throw error.code && error.key ? error : WenError.ipfs_retrieve; @@ -90,12 +87,8 @@ export const uriToUrl = (uri: string) => { export const getRandomBuildcoreUrl = (owner: string, uid: string, extension: string) => { const bucket = storage().bucket(getBucket()); const baseUrl = BUCKET_BASE_URLS[bucket.getName()]; - - const isDev = bucket.getName() === Bucket.DEV; const destination = `${owner}/${uid}/${generateRandomFileName()}.${extension}`; - const url = `${baseUrl}${isDev ? encodeURIComponent(destination) : destination}`; - - return isDev ? url + '?alt=media' : url; + return `${baseUrl}${destination}`; }; export const downloadFile = async (url: string, workDir: string, fileName: string) => { diff --git a/packages/functions/test-tangle/stamp-tangle/Helper.ts b/packages/functions/test-tangle/stamp-tangle/Helper.ts index a62de7f2a..0601c1456 100644 --- a/packages/functions/test-tangle/stamp-tangle/Helper.ts +++ b/packages/functions/test-tangle/stamp-tangle/Helper.ts @@ -33,7 +33,7 @@ export class Helper { }; public beforeEach = async () => { - const bucket = storage().bucket(Bucket.DEV); + const bucket = storage().bucket(Bucket.TEST); const destination = `nft/${getRandomEthAddress()}/image.jpeg`; this.dowloadUrl = await bucket.upload('./test/puppy.jpeg', destination, { contentType: 'image/jpeg', diff --git a/packages/functions/test-tangle/stamp-tangle/stamp-tangle_5.spec.ts b/packages/functions/test-tangle/stamp-tangle/stamp-tangle_5.spec.ts index 50d9e9dfb..9852903eb 100644 --- a/packages/functions/test-tangle/stamp-tangle/stamp-tangle_5.spec.ts +++ b/packages/functions/test-tangle/stamp-tangle/stamp-tangle_5.spec.ts @@ -13,7 +13,7 @@ describe('Stamp tangle test', () => { beforeEach(helper.beforeEach); it('Should create and mint stamp with zip file', async () => { - const bucket = storage().bucket(Bucket.DEV); + const bucket = storage().bucket(Bucket.TEST); const destination = 'nft/test/image.zip'; const dowloadUrl = await bucket.upload('./test/puppy.zip', destination, { contentType: 'application/zip', diff --git a/packages/functions/test-tangle/withdraw-deposit-nft/deposit-withraw-nft_9.spec.ts b/packages/functions/test-tangle/withdraw-deposit-nft/deposit-withraw-nft_9.spec.ts index b8c4a08bc..bf0444bad 100644 --- a/packages/functions/test-tangle/withdraw-deposit-nft/deposit-withraw-nft_9.spec.ts +++ b/packages/functions/test-tangle/withdraw-deposit-nft/deposit-withraw-nft_9.spec.ts @@ -43,7 +43,7 @@ describe('Collection minting', () => { const validateStorageFileCount = (owner: string, uid: string) => wait(async () => { - const bucket = storage().bucket(Bucket.DEV); + const bucket = storage().bucket(Bucket.TEST); return (await bucket.getFilesCount(`${owner}/${uid}`)) > 0; }); diff --git a/packages/functions/test/controls/collection.spec.ts b/packages/functions/test/controls/collection.spec.ts index a922f2dca..64264561a 100644 --- a/packages/functions/test/controls/collection.spec.ts +++ b/packages/functions/test/controls/collection.spec.ts @@ -96,7 +96,7 @@ describe('CollectionController: ' + WEN_FUNC.createCollection, () => { let call = testEnv.wrap(WEN_FUNC.createCollection); await expectThrow(call, WenError.invalid_params.key); mockWalletReturnValue(member, { - media: `https://storage.googleapis.com/download/storage/v1/b/${Bucket.DEV}/o`, + media: `https://storage.googleapis.com/download/storage/v1/b/${Bucket.TEST}/o`, ...dummyCollection(space, 0.6), }); call = testEnv.wrap(WEN_FUNC.createCollection); diff --git a/packages/functions/test/controls/nft.spec.ts b/packages/functions/test/controls/nft.spec.ts index bef82bf08..d964059dc 100644 --- a/packages/functions/test/controls/nft.spec.ts +++ b/packages/functions/test/controls/nft.spec.ts @@ -66,7 +66,7 @@ describe('Nft controll: ' + WEN_FUNC.createCollection, () => { mockWalletReturnValue(member, nft); await expectThrow(testEnv.wrap(WEN_FUNC.createNft), WenError.invalid_params.key); nft = { - media: `https://storage.googleapis.com/download/storage/v1/b/${Bucket.DEV}/o`, + media: `https://storage.googleapis.com/download/storage/v1/b/${Bucket.TEST}/o`, ...dummyNft(collection.uid), }; mockWalletReturnValue(member, nft); diff --git a/packages/functions/test/controls/stamp.control.spec.ts b/packages/functions/test/controls/stamp.control.spec.ts index 59d8ef170..649479966 100644 --- a/packages/functions/test/controls/stamp.control.spec.ts +++ b/packages/functions/test/controls/stamp.control.spec.ts @@ -21,7 +21,7 @@ describe('Stamp control', () => { let dowloadUrl: string; beforeEach(async () => { - const bucket = storage().bucket(Bucket.DEV); + const bucket = storage().bucket(Bucket.TEST); const destination = `nft/${wallet.getRandomEthAddress()}/image.jpeg`; dowloadUrl = await bucket.upload('./test/puppy.jpeg', destination, { contentType: 'image/jpeg', diff --git a/packages/functions/test/storage/resize.img.spec.ts b/packages/functions/test/storage/resize.img.spec.ts index 00fcc0495..2e48b8a85 100644 --- a/packages/functions/test/storage/resize.img.spec.ts +++ b/packages/functions/test/storage/resize.img.spec.ts @@ -9,7 +9,7 @@ const triggerResizer = async (name: string, contentType: string) => { try { await axios.post( 'http://localhost:8080/' + WEN_STORAGE_TRIGGER.onUploadFinalized, - { name, bucket: Bucket.DEV, contentType, metadata: {} }, + { name, bucket: Bucket.TEST, contentType, metadata: {} }, { headers: { 'Content-Type': 'application/json' } }, ); } catch (err) { @@ -24,14 +24,14 @@ describe('Resize img test', () => { const extensions = Object.values(ImageWidth) .map((size) => `_jpeg_${size}X${size}.webp`) .concat('.jpeg'); - const bucket = storage().bucket(Bucket.DEV); + const bucket = storage().bucket(Bucket.TEST); await bucket.upload('./test/puppy.jpeg', name + '.jpeg', { contentType: 'image/jpeg' }); await triggerResizer(name + '.jpeg', 'image/jpeg'); for (const extension of extensions) { await wait( async () => await storage() - .bucket(Bucket.DEV) + .bucket(Bucket.TEST) .exists(name + extension), ); } @@ -39,18 +39,18 @@ describe('Resize img test', () => { it('Should create video preview', async () => { const id = getRandomEthAddress(); - const bucket = storage().bucket(Bucket.DEV); + const bucket = storage().bucket(Bucket.TEST); const destination = `nft/test/${id}.mov`; await bucket.upload('./test/nft_video.mov', destination, { contentType: 'video/quicktime' }); await triggerResizer(destination, 'video/quicktime'); await wait( - async () => await storage().bucket(Bucket.DEV).exists(`nft/test/${id}_mov_preview.webp`), + async () => await storage().bucket(Bucket.TEST).exists(`nft/test/${id}_mov_preview.webp`), ); }); it.each(['png', 'jpeg'])('Should not override', async (extension: string) => { const name = 'nft/test/image'; - const bucket = storage().bucket(Bucket.DEV); + const bucket = storage().bucket(Bucket.TEST); await bucket.upload('./test/puppy.jpeg', 'nft/test/image.' + extension, { contentType: 'image/' + extension, }); @@ -67,7 +67,7 @@ const verifyImagesExist = async (name: string, extensions: string[]) => { await wait( async () => await storage() - .bucket(Bucket.DEV) + .bucket(Bucket.TEST) .exists(name + extension), ); } diff --git a/packages/interfaces/src/config.ts b/packages/interfaces/src/config.ts index 1d08f83c1..1469977c2 100644 --- a/packages/interfaces/src/config.ts +++ b/packages/interfaces/src/config.ts @@ -176,7 +176,6 @@ export const STAKE_REWARD_TEST_CRON_INTERVAL_CONFIG = 'every 5 minutes'; export enum Bucket { PROD = 'images.soonaverse.com', TEST = 'images-wen.soonaverse.com', - DEV = 'soonaverse-dev-custom-bucket', } // key - WEN_FUNC