Browse Source
Feature/send original MIME type in logo endpoint (#4173)
* Send original MIME type in logo endpoint
* Update changelog
pull/4175/head^2
Szymon Łągiewka
2 weeks ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
20 additions and
13 deletions
-
CHANGELOG.md
-
apps/api/src/app/logo/logo.controller.ts
-
apps/api/src/app/logo/logo.service.ts
|
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 |
|
|
|
|
|
|
|
### Changed |
|
|
|
|
|
|
|
- Improved the endpoint to fetch the logo of an asset or a platform by sending the original MIME type |
|
|
|
- Eliminated `got` in favor of using `fetch` |
|
|
|
- Changed the `REDIS_HOST` from `localhost` to `redis` in `.env.example` |
|
|
|
- Changed the _Postgres_ host from `localhost` to `postgres` in `.env.example` |
|
|
|
|
|
@ -26,12 +26,13 @@ export class LogoController { |
|
|
|
@Res() response: Response |
|
|
|
) { |
|
|
|
try { |
|
|
|
const buffer = await this.logoService.getLogoByDataSourceAndSymbol({ |
|
|
|
const { buffer, type } = |
|
|
|
await this.logoService.getLogoByDataSourceAndSymbol({ |
|
|
|
dataSource, |
|
|
|
symbol |
|
|
|
}); |
|
|
|
|
|
|
|
response.contentType('image/png'); |
|
|
|
response.contentType(type); |
|
|
|
response.send(buffer); |
|
|
|
} catch { |
|
|
|
response.status(HttpStatus.NOT_FOUND).send(); |
|
|
@ -44,9 +45,9 @@ export class LogoController { |
|
|
|
@Res() response: Response |
|
|
|
) { |
|
|
|
try { |
|
|
|
const buffer = await this.logoService.getLogoByUrl(url); |
|
|
|
const { buffer, type } = await this.logoService.getLogoByUrl(url); |
|
|
|
|
|
|
|
response.contentType('image/png'); |
|
|
|
response.contentType(type); |
|
|
|
response.send(buffer); |
|
|
|
} catch { |
|
|
|
response.status(HttpStatus.NOT_FOUND).send(); |
|
|
|
|
|
@ -38,12 +38,12 @@ export class LogoService { |
|
|
|
return this.getBuffer(assetProfile.url); |
|
|
|
} |
|
|
|
|
|
|
|
public async getLogoByUrl(aUrl: string) { |
|
|
|
public getLogoByUrl(aUrl: string) { |
|
|
|
return this.getBuffer(aUrl); |
|
|
|
} |
|
|
|
|
|
|
|
private getBuffer(aUrl: string) { |
|
|
|
return fetch( |
|
|
|
private async getBuffer(aUrl: string) { |
|
|
|
const blob = await fetch( |
|
|
|
`https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${aUrl}&size=64`, |
|
|
|
{ |
|
|
|
headers: { 'User-Agent': 'request' }, |
|
|
@ -51,8 +51,13 @@ export class LogoService { |
|
|
|
this.configurationService.get('REQUEST_TIMEOUT') |
|
|
|
) |
|
|
|
} |
|
|
|
) |
|
|
|
.then((res) => res.arrayBuffer()) |
|
|
|
.then((buffer) => Buffer.from(buffer)); |
|
|
|
).then((res) => res.blob()); |
|
|
|
|
|
|
|
return { |
|
|
|
buffer: await blob.arrayBuffer().then((arrayBuffer) => { |
|
|
|
return Buffer.from(arrayBuffer); |
|
|
|
}), |
|
|
|
type: blob.type |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|