Skip to content

Commit

Permalink
Remove DEV bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
Boldizsar Mezei committed May 19, 2024
1 parent ade2370 commit e5e26d4
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 38 deletions.
5 changes: 2 additions & 3 deletions packages/functions/src/controls/file/file.upload.control.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -32,8 +32,7 @@ export const uploadFileControl = async ({ headers, rawBody }: Context<FileUpload
fs.rmSync(workdir, { recursive: true, force: true });
(params.file as any).resume();

const idDevBucket = bucketName === Bucket.DEV;
return { url: idDevBucket ? dowloadUrl : `https://${bucket.getName()}/${destination}` };
return { url: dowloadUrl };
};

const getParams = (headers: any, rawBody: any, workdir: string) =>
Expand Down
6 changes: 0 additions & 6 deletions packages/functions/src/services/joi/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
6 changes: 1 addition & 5 deletions packages/functions/src/utils/config.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand All @@ -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);
13 changes: 3 additions & 10 deletions packages/functions/src/utils/media.utils.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/test-tangle/stamp-tangle/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down
2 changes: 1 addition & 1 deletion packages/functions/test/controls/collection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('CollectionController: ' + WEN_FUNC.createCollection, () => {
let call = testEnv.wrap<Collection>(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<Collection>(WEN_FUNC.createCollection);
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/test/controls/nft.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('Nft controll: ' + WEN_FUNC.createCollection, () => {
mockWalletReturnValue(member, nft);
await expectThrow(testEnv.wrap<Nft>(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);
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/test/controls/stamp.control.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 7 additions & 7 deletions packages/functions/test/storage/resize.img.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -24,33 +24,33 @@ 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),
);
}
});

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,
});
Expand All @@ -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),
);
}
Expand Down
1 change: 0 additions & 1 deletion packages/interfaces/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5e26d4

Please sign in to comment.