Skip to content

Commit

Permalink
Merge pull request #179 from ensdomains/mdt/high-res-rasterization
Browse files Browse the repository at this point in the history
update rasterization endpoint to accept resolution query paremeter
  • Loading branch information
mdtanrikulu authored Jul 30, 2024
2 parents 15c2420 + b5f77fc commit 4d114cb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 61 deletions.
21 changes: 21 additions & 0 deletions src/assets/doc_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@
},
"type": "string",
"description": "Labelhash(v1) /Namehash(v2) of your ENS name.\n\nMore: https://docs.ens.domains/contract-api-reference/name-processing#hashing-names"
},
{
"name": "res",
"in": "query",
"required": false,
"schema": {
"$ref": "#/components/schemas/res"
},
"type": "string",
"description": "Resolution option for the rasterization. Available options: low (default) | high"
}
],
"responses": {
Expand Down Expand Up @@ -405,6 +415,10 @@
"type": "string",
"example": "Token ID of NFT"
},
"res": {
"type": "string",
"example": "Resolution query parameter for rasterization"
},
"reference_url": {
"type": "string",
"example": "Marketplace URL of NFT"
Expand Down Expand Up @@ -526,6 +540,13 @@
"name": "tokenId"
}
},
"res": {
"type": "string",
"example": "high",
"xml": {
"name": "res"
}
},
"networkName": {
"description": "Name of the chain to query for.",
"type": "string",
Expand Down
64 changes: 6 additions & 58 deletions src/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/controller/ensRasterize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export async function ensRasterize(req: Request, res: Response) {
// #swagger.parameters['{}'] = { name: 'contractAddress', description: 'Contract address which stores the NFT indicated by the tokenId', schema: { $ref: '#/definitions/contractAddress' } }
// #swagger.parameters['tokenId'] = { type: 'string', description: 'Labelhash(v1) /Namehash(v2) of your ENS name.\n\nMore: https://docs.ens.domains/contract-api-reference/name-processing#hashing-names', schema: { $ref: '#/definitions/tokenId' } }
const { contractAddress, networkName, tokenId } = req.params;
// limit resolution param to static options
const resolution = req.query.res === 'high' ? 'high' : 'low';
try {
const raster = await rasterize(contractAddress, networkName, tokenId);
const raster = await rasterize(contractAddress, networkName, tokenId, resolution);
const base64 = raster.replace('data:image/png;base64,', '');
const buffer = Buffer.from(base64, 'base64');
/* #swagger.responses[200] = {
Expand Down
7 changes: 5 additions & 2 deletions src/service/rasterize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import { GoogleAuth } from 'google-auth-library';
const auth = new GoogleAuth();
const grRasterize = 'https://us-central1-ens-metadata-service.cloudfunctions.net/rasterize'

type Resolution = 'low' | 'high';

export function rasterize(
contractAddress: string,
networkName: string,
tokenId: string
tokenId: string,
resolution: Resolution
): Promise<string> {
return new Promise(async (resolve, reject) => {
const client = await auth.getIdTokenClient(grRasterize);
client
.request({
url: grRasterize,
url: `${grRasterize}?res=${resolution}`,
method: 'POST',
responseType: 'arraybuffer',
data: {
Expand Down

0 comments on commit 4d114cb

Please sign in to comment.