Using Firebase Functions and Firestore.
- Plasa Backend
- HTTP Method: GET
- Description: Returns a simple greeting message.
- Response:
- Success (200 OK):
"Hello!"
- Success (200 OK):
- HTTP Method: GET
- Description: Retrieves full data for a user by ID.
- Query Parameters:
id
(required): The ID of the user.
- Response:
- Success (200 OK):
{ // User full data object }
- Error (400 Bad Request):
"User ID is required"
- Error (500 Internal Server Error):
"Failed to retrieve user data"
- Success (200 OK):
- HTTP Method: GET
- Description: Sets the Instagram username for a user.
- Query Parameters:
id
(required): The ID of the user.username
(required): The Instagram username to set.
- Response:
- Success (200 OK):
{ // Updated user full data object }
- Error (400 Bad Request):
or
"User ID is required"
"Instagram username is required"
- Error (500 Internal Server Error):
"Failed to set Instagram username"
- Success (200 OK):
Note: Ensure that the id
and username
parameters are provided correctly to avoid errors.
-
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