Using Firebase Functions and Firestore.
-
HTTP Method: GET
-
Description: Generates signatures for follower data, handling both real Instagram usernames and generating fake data when needed.
-
Authentication: Required (assumed, as it's a Firebase Function)
-
Query Parameters:
userAddress
(required): Ethereum address of the userinstagramUsername
(optional): Instagram username of the follower
-
Response:
- Success (200 OK):
[ { "spaceName": "string", "signature": "string", "followerSince": number, "deadline": number, "isReal": boolean, "instagramUsername": "string" }, // ... (one object for each space) ]
- Error (400 Bad Request):
or
"Missing or invalid userAddress"
"Invalid instagramUsername"
- Success (200 OK):
-
Example Usage:
const userAddress = '0x1234567890123456789012345678901234567890' const instagramUsername = 'example_user' // Optional const url = new URL('https://your-firebase-function-url/signatures') url.searchParams.append('userAddress', userAddress) if (instagramUsername) { url.searchParams.append('instagramUsername', instagramUsername) } const response = await fetch(url.toString()) const data = await response.json() console.log(data)
Note: If instagramUsername
is not provided, the function will generate a single random follower username for all spaces. The isReal
field indicates whether the follower data is real (true) or generated (false).
-
Description: Stores information about followers for each followed Instagram account. The collection name is the Instagram username of the followed account.
-
Document Structure:
{ "username": "string", "follower_since": "number (timestamp)" }
-
Document ID: The document ID is the follower's Instagram username.
-
Usage Examples:
// Reading follower data const followedAccount = 'example_account' const followerUsername = 'follower_user' const docRef = db.collection(followedAccount).doc(followerUsername) const doc = await docRef.get() if (doc.exists) { console.log('Follower data:', doc.data()) } else { console.log('Follower not found') } // Writing follower data (should be done through Firebase Functions) const followedAccount = 'example_account' const followerUsername = 'new_follower' const followerData = { username: followerUsername, follower_since: firebase.firestore.FieldValue.serverTimestamp() } await db.collection(followedAccount).doc(followerUsername).set(followerData)
- Description: This script reads follower data from a single JSON file and adds it to Firestore.
- Usage:
- Set the required environment variables in a
.env
file:FOLLOWERS_COLLECTION_TO_PUSH
: The Firestore collection to push data toSERVICE_ACCOUNT_PATH
: Path to the Firebase service account JSON fileFOLLOWERS_DATA_PATH
: Path to the JSON file containing follower data
- Run the script using
ts-node push-followers-json.ts
- Set the required environment variables in a
- Key Features:
- Processes followers in batches of 100 for efficient Firestore writes
- Handles large datasets by committing in batches
- Logs progress and any errors encountered
- Description: This script processes multiple JSON files containing follower data and adds them to Firestore.
- Usage:
- Set the required environment variables in a
.env
file:FOLLOWERS_COLLECTION_TO_PUSH
: The Firestore collection to push data toSERVICE_ACCOUNT_PATH
: Path to the Firebase service account JSON fileFOLLOWERS_FOLDER_NAME
: Name of the folder containing follower JSON files
- Run the script using
ts-node push-followers-json-multifile.ts
- Set the required environment variables in a
- Key Features:
- Processes multiple JSON files in a specified folder
- Handles followers in batches of 500 for efficient Firestore writes
- Skips reserved usernames (starting and ending with
__
) - Provides detailed logging, including total followers added and skipped for each file and grand totals
- Description: This script reads follower data from a CSV file and adds it to Firestore.
- Usage:
- Set the required environment variables in a
.env
file:FOLLOWERS_COLLECTION_TO_PUSH
: The Firestore collection to push data toSERVICE_ACCOUNT_PATH
: Path to the Firebase service account JSON fileCSV_FILE_PATH
: Path to the CSV file containing follower data
- Run the script using
ts-node push-followers-csv.ts
- Set the required environment variables in a
- Key Features:
- Processes followers from a CSV file
- Handles followers in batches of 100 for efficient Firestore writes
- Uses a fixed timestamp for all followers (currently set to '2024-06-12')
- Provides progress logging, including total records uploaded
- Description: This script reads and logs all documents from a specified Firestore collection.
- Usage:
- Set the required environment variables in a
.env
file:COLLECTION_TO_READ
: The Firestore collection to read fromSERVICE_ACCOUNT_PATH
: Path to the Firebase service account JSON file
- Run the script using
ts-node read-collection.ts
- Set the required environment variables in a
- Key Features:
- Reads all documents from the specified collection
- Logs document IDs and data
- Useful for verifying data after running the push scripts