-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NFT Metadata Crawler] Rename crate to remove parser (#14815)
* remove * refavtor * refactor configs * refactor * lint
- Loading branch information
1 parent
9271edf
commit d17389a
Showing
38 changed files
with
206 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...em/nft-metadata-crawler-parser/Cargo.toml → ecosystem/nft-metadata-crawler/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
ecosystem/nft-metadata-crawler/src/asset_uploader/config.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Required account data and auth keys for Cloudflare | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct AssetUploaderConfig { | ||
/// Cloudflare API key | ||
pub cloudflare_auth_key: String, | ||
/// Cloudflare Account ID provided at the images home page used to authenticate requests | ||
pub cloudflare_account_id: String, | ||
/// Cloudflare Account Hash provided at the images home page used for generating the CDN image URLs | ||
pub cloudflare_account_hash: String, | ||
/// Cloudflare Image Delivery URL prefix provided at the images home page used for generating the CDN image URLs | ||
pub cloudflare_image_delivery_prefix: String, | ||
/// In addition to on the fly transformations, Cloudflare images can be returned in preset variants. This is the default variant used with the saved CDN image URLs. | ||
pub cloudflare_default_variant: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::{ | ||
asset_uploader::{config::AssetUploaderConfig, AssetUploaderContext}, | ||
parser::{config::ParserConfig, ParserContext}, | ||
utils::database::{establish_connection_pool, run_migrations}, | ||
}; | ||
use aptos_indexer_grpc_server_framework::RunnableConfig; | ||
use axum::Router; | ||
use diesel::{ | ||
r2d2::{ConnectionManager, Pool}, | ||
PgConnection, | ||
}; | ||
use enum_dispatch::enum_dispatch; | ||
use serde::{Deserialize, Serialize}; | ||
use tokio::net::TcpListener; | ||
use tracing::info; | ||
|
||
/// Trait for building a router for axum | ||
#[enum_dispatch] | ||
pub trait Server: Send + Sync { | ||
fn build_router(&self) -> Router; | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
#[serde(tag = "type")] | ||
pub enum ServerConfig { | ||
Parser(ParserConfig), | ||
AssetUploader(AssetUploaderConfig), | ||
} | ||
|
||
/// Structs to hold config from YAML | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct NFTMetadataCrawlerConfig { | ||
pub database_url: String, | ||
pub server_port: u16, | ||
pub server_config: ServerConfig, | ||
} | ||
|
||
#[derive(Clone)] | ||
#[enum_dispatch(Server)] | ||
pub enum ServerContext { | ||
Parser(ParserContext), | ||
AssetUploader(AssetUploaderContext), | ||
} | ||
|
||
impl ServerConfig { | ||
pub async fn build_context( | ||
&self, | ||
pool: Pool<ConnectionManager<PgConnection>>, | ||
) -> ServerContext { | ||
match self { | ||
ServerConfig::Parser(parser_config) => { | ||
ServerContext::Parser(ParserContext::new(parser_config.clone(), pool).await) | ||
}, | ||
ServerConfig::AssetUploader(asset_uploader_config) => ServerContext::AssetUploader( | ||
AssetUploaderContext::new(asset_uploader_config.clone(), pool), | ||
), | ||
} | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl RunnableConfig for NFTMetadataCrawlerConfig { | ||
/// Main driver function that establishes a connection to Pubsub and parses the Pubsub entries in parallel | ||
async fn run(&self) -> anyhow::Result<()> { | ||
info!("[NFT Metadata Crawler] Starting with config: {:?}", self); | ||
|
||
info!("[NFT Metadata Crawler] Connecting to database"); | ||
let pool = establish_connection_pool(&self.database_url); | ||
info!("[NFT Metadata Crawler] Database connection successful"); | ||
|
||
info!("[NFT Metadata Crawler] Running migrations"); | ||
run_migrations(&pool); | ||
info!("[NFT Metadata Crawler] Finished migrations"); | ||
|
||
// Create request context | ||
let context = self.server_config.build_context(pool).await; | ||
let listener = TcpListener::bind(format!("0.0.0.0:{}", self.server_port)).await?; | ||
axum::serve(listener, context.build_router()).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn get_server_name(&self) -> String { | ||
match &self.server_config { | ||
ServerConfig::Parser(_) => "parser".to_string(), | ||
ServerConfig::AssetUploader(_) => "asset_uploader".to_string(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.