Skip to content

Commit

Permalink
Sending base64 images optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
bobo-k2 committed Nov 22, 2023
1 parent ee89249 commit 5e83b9b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/controllers/DappsStakingController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ export class DappsStakingController extends ControllerBase implements IControlle
*/

try {
const data = await this._firebaseService.getDapp(req.params.address, req.params.network as NetworkType);
const data = await this._firebaseService.getDapp(
req.params.address,
req.params.network as NetworkType,
req.query.forEdit as unknown as boolean,
);

if (data) {
res.json(data);
Expand Down
24 changes: 13 additions & 11 deletions src/services/FirebaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface Cache<T> {
export interface IFirebaseService {
getDappsFull(network: NetworkType): Promise<DappItem[]>;
getDapps(network: NetworkType): Promise<DappItem[]>;
getDapp(address: string, network: NetworkType): Promise<NewDappItem | undefined>;
getDapp(address: string, network: NetworkType, forEdit: boolean): Promise<NewDappItem | undefined>;
registerDapp(dapp: NewDappItem, network: NetworkType): Promise<DappItem>;
updateCache<T>(key: string, item: T): Promise<void>;
readCache<T>(key: string): Promise<Cache<T> | undefined>;
Expand Down Expand Up @@ -50,7 +50,7 @@ export class FirebaseService implements IFirebaseService {
return this.getDappsData(query);
}

public async getDapp(address: string, network: NetworkType): Promise<NewDappItem | undefined> {
public async getDapp(address: string, network: NetworkType, forEdit = false): Promise<NewDappItem | undefined> {
Guard.ThrowIfUndefined('address', address);

this.initApp();
Expand All @@ -66,15 +66,17 @@ export class FirebaseService implements IFirebaseService {
await admin.firestore().collection(collectionKey).doc(fbAddress).get()
).data() as unknown as NewDappItem;

const icon = await this.getFileInfo(dapp.iconUrl, collectionKey);
if (icon) {
dapp.iconFile = icon;
}
if (forEdit) {
const icon = await this.getFileInfo(dapp.iconUrl, collectionKey);
if (icon) {
dapp.iconFile = icon;
}

const images = dapp.imagesUrl
? await Promise.all(dapp.imagesUrl.map((x) => this.getFileInfo(x, collectionKey)))
: [];
dapp.images = images.filter((x) => x !== null) as FileInfo[];
const images = dapp.imagesUrl
? await Promise.all(dapp.imagesUrl.map((x) => this.getFileInfo(x, collectionKey)))
: [];
dapp.images = images.filter((x) => x !== null) as FileInfo[];
}

return dapp;
}
Expand Down Expand Up @@ -109,7 +111,7 @@ export class FirebaseService implements IFirebaseService {
imagesUrl: dapp.imagesUrl,
developers: dapp.developers,
description: dapp.description,
shortDescription: dapp.shortDescription,
shortDescription: dapp.shortDescription ?? '',
communities: dapp.communities,
contractType: dapp.contractType,
mainCategory: dapp.mainCategory,
Expand Down
2 changes: 1 addition & 1 deletion tests/services/FirebaseServiceMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class FirebaseServiceMock implements IFirebaseService {
throw new Error('Method not implemented.');
}

public async getDapp(address: string, network: NetworkType): Promise<NewDappItem | undefined> {
public async getDapp(address: string, network: NetworkType, forEdit = false): Promise<NewDappItem | undefined> {
throw new Error('Method not implemented.');
}

Expand Down

0 comments on commit 5e83b9b

Please sign in to comment.