Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor GCS image cache upload script to typescript #232

Merged
merged 25 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 0 additions & 147 deletions config/image-cache.js

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"test:api": "npm run test -- ./tests/api/",
"test:chainhook": "npm run test -- ./tests/chainhook/",
"test:token-queue": "npm run test -- ./tests/token-queue/",
"testenv:run": "docker-compose -f docker/docker-compose.dev.postgres.yml up",
"testenv:stop": "docker-compose -f docker/docker-compose.dev.postgres.yml down -v -t 0",
"testenv:logs": "docker-compose -f docker/docker-compose.dev.postgres.yml logs -t -f",
"testenv:run": "docker compose -f docker/docker-compose.dev.postgres.yml up",
"testenv:stop": "docker compose -f docker/docker-compose.dev.postgres.yml down -v -t 0",
"testenv:logs": "docker compose -f docker/docker-compose.dev.postgres.yml logs -t -f",
"migrate": "ts-node node_modules/.bin/node-pg-migrate -j ts",
"lint:eslint": "eslint . --ext .js,.jsx,.ts,.tsx -f unix",
"lint:prettier": "prettier --check src/**/*.ts tests/**/*.ts migrations/**/*.ts",
Expand Down
7 changes: 6 additions & 1 deletion src/admin-rpc/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { Server } from 'http';
import { Type } from '@sinclair/typebox';
import { SmartContractRegEx } from '../api/schemas';
import { logger, PINO_LOGGER_CONFIG } from '@hirosystems/api-toolkit';
import { reprocessTokenImageCache } from '../token-processor/util/image-cache';
import { reprocessTokenImageCache } from '../token-processor/images/image-cache';
import { StacksNodeRpcClient } from '../token-processor/stacks-node/stacks-node-rpc-client';
import { getSmartContractSip } from '../token-processor/util/sip-validation';
import { ENV } from '../env';

export const AdminApi: FastifyPluginCallback<Record<never, never>, Server, TypeBoxTypeProvider> = (
fastify,
Expand Down Expand Up @@ -83,6 +84,10 @@ export const AdminApi: FastifyPluginCallback<Record<never, never>, Server, TypeB
},
},
async (request, reply) => {
if (!ENV.IMAGE_CACHE_PROCESSOR_ENABLED) {
await reply.code(422).send({ error: 'Image cache processor is not enabled' });
return;
}
logger.info(
`AdminRPC reprocessing image cache for ${request.body.contractId}: (${
request.body.tokenIds ?? 'all'
Expand Down
22 changes: 16 additions & 6 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ const schema = Type.Object({
* service in our token queue. Defaults to 50,000.
*/
METADATA_MAX_NFT_CONTRACT_TOKEN_COUNT: Type.Number({ default: 50_000 }),
/**
* Configure a script to handle image URLs during token metadata processing. Must be an executable
* script that accepts the URL as the first program argument and outputs a result URL to stdout.
* Example: ./config/image-cache.js
*/
METADATA_IMAGE_CACHE_PROCESSOR: Type.Optional(Type.String()),
/**
* How often will token metadata that is marked `dynamic` will be refreshed if it doesn't specify
* an explicit TTL (seconds). See SIP-019 for more information. Defaults to 86400 seconds (24
Expand Down Expand Up @@ -126,6 +120,22 @@ const schema = Type.Object({
* `https://arweave.net`.
*/
PUBLIC_GATEWAY_ARWEAVE: Type.String({ default: 'https://arweave.net' }),

/** Enables token image uploads to a Google Cloud Storage bucket. */
IMAGE_CACHE_PROCESSOR_ENABLED: Type.Boolean({ default: false }),
/** Width to resize images into while preserving aspect ratio. */
IMAGE_CACHE_RESIZE_WIDTH: Type.Integer({ default: 300 }),
/** Google Cloud Storage bucket name. Example: 'assets.dev.hiro.so' */
IMAGE_CACHE_GCS_BUCKET_NAME: Type.Optional(Type.String()),
/** Path for object storage inside the bucket. Example: 'token-metadata-api/mainnet/' */
IMAGE_CACHE_GCS_OBJECT_NAME_PREFIX: Type.Optional(Type.String()),
/**
* Base path for URLs that will be returned to the API for storage. Example:
* 'https://assets.dev.hiro.so/token-metadata-api/mainnet/'
*/
IMAGE_CACHE_CDN_BASE_PATH: Type.Optional(Type.String()),
/** Max payload size accepted when downloading remote images. */
IMAGE_CACHE_MAX_BYTE_SIZE: Type.Optional(Type.Integer()),
});
type Env = Static<typeof schema>;

Expand Down
Loading
Loading