Spaces:
Sleeping
Sleeping
Commit
·
ae703ff
1
Parent(s):
b4578a2
added optional active user header (some people needs this)
Browse files
README.md
CHANGED
|
@@ -20,6 +20,7 @@ The application requires the following environment variables to be set:
|
|
| 20 |
* `NOTION_COOKIE`: Your Notion `token_v2` cookie value. This is used for authentication with the Notion API. You can typically find this in your browser's developer tools while logged into Notion.
|
| 21 |
* `NOTION_SPACE_ID`: The ID of your Notion workspace. You can usually find this in the URL when browsing your Notion workspace (it's the part after your domain and before the first page ID, often a UUID).
|
| 22 |
* `PROXY_AUTH_TOKEN` (Optional): The Bearer token required for authentication to access the API endpoints. If not set, it defaults to `default_token`.
|
|
|
|
| 23 |
|
| 24 |
## Running Locally (without Docker)
|
| 25 |
|
|
@@ -45,7 +46,7 @@ The application requires the following environment variables to be set:
|
|
| 45 |
This method uses the `docker-compose.yml` file for a streamlined local development setup. It automatically builds the image if needed and loads environment variables directly from your `.env` file.
|
| 46 |
|
| 47 |
1. Ensure you have Docker and Docker Compose installed.
|
| 48 |
-
2. Make sure your `.env` file exists in the project root with your `NOTION_COOKIE`, `NOTION_SPACE_ID`, and optionally `PROXY_AUTH_TOKEN`. If `PROXY_AUTH_TOKEN` is not in the `.env` file, the default `default_token` will be used.
|
| 49 |
3. Run the following command in the project root:
|
| 50 |
```bash
|
| 51 |
docker-compose up --build -d
|
|
@@ -74,6 +75,7 @@ This method involves building and running the Docker container manually, passing
|
|
| 74 |
-e NOTION_COOKIE="your_cookie_value" \
|
| 75 |
-e NOTION_SPACE_ID="your_space_id" \
|
| 76 |
-e PROXY_AUTH_TOKEN="your_token" \ # Set your desired token here
|
|
|
|
| 77 |
notion-api-bridge
|
| 78 |
```
|
| 79 |
The server will be available at `http://localhost:7860` (or whichever host port you mapped to the container's 7860). You will need to use the token provided in the `-e PROXY_AUTH_TOKEN` flag via an `Authorization: Bearer <token>` header for authentication.
|
|
@@ -88,6 +90,7 @@ This application is designed to be easily deployed as a Docker Space on Hugging
|
|
| 88 |
* `NOTION_COOKIE`: Paste your Notion `token_v2` cookie value.
|
| 89 |
* `NOTION_SPACE_ID`: Paste your Notion Space ID.
|
| 90 |
* `PROXY_AUTH_TOKEN`: Paste the desired Bearer token for API authentication (e.g., a strong, generated token). If you omit this, the default `default_token` will be used.
|
|
|
|
| 91 |
Hugging Face will securely inject these secrets as environment variables into your running container.
|
| 92 |
4. **Deployment:** Hugging Face Spaces will automatically build the Docker image from your `Dockerfile` and run the container. It detects applications running on port 7860 (as specified in the `Dockerfile` and metadata).
|
| 93 |
5. **Accessing the API:** Once the Space is running, you can access the API endpoint at the Space's public URL, providing the token via an `Authorization: Bearer <token>` header. The token must match the `PROXY_AUTH_TOKEN` secret you set (or the default `default_token`).
|
|
|
|
| 20 |
* `NOTION_COOKIE`: Your Notion `token_v2` cookie value. This is used for authentication with the Notion API. You can typically find this in your browser's developer tools while logged into Notion.
|
| 21 |
* `NOTION_SPACE_ID`: The ID of your Notion workspace. You can usually find this in the URL when browsing your Notion workspace (it's the part after your domain and before the first page ID, often a UUID).
|
| 22 |
* `PROXY_AUTH_TOKEN` (Optional): The Bearer token required for authentication to access the API endpoints. If not set, it defaults to `default_token`.
|
| 23 |
+
* `NOTION_ACTIVE_USER_HEADER` (Optional): If set, its value will be used for the `x-notion-active-user-header` in requests sent to the Notion API. If not set or empty, the header is omitted.
|
| 24 |
|
| 25 |
## Running Locally (without Docker)
|
| 26 |
|
|
|
|
| 46 |
This method uses the `docker-compose.yml` file for a streamlined local development setup. It automatically builds the image if needed and loads environment variables directly from your `.env` file.
|
| 47 |
|
| 48 |
1. Ensure you have Docker and Docker Compose installed.
|
| 49 |
+
2. Make sure your `.env` file exists in the project root with your `NOTION_COOKIE`, `NOTION_SPACE_ID`, and optionally `PROXY_AUTH_TOKEN` and `NOTION_ACTIVE_USER_HEADER`. If `PROXY_AUTH_TOKEN` is not in the `.env` file, the default `default_token` will be used. If `NOTION_ACTIVE_USER_HEADER` is not set or empty, the corresponding header will not be sent.
|
| 50 |
3. Run the following command in the project root:
|
| 51 |
```bash
|
| 52 |
docker-compose up --build -d
|
|
|
|
| 75 |
-e NOTION_COOKIE="your_cookie_value" \
|
| 76 |
-e NOTION_SPACE_ID="your_space_id" \
|
| 77 |
-e PROXY_AUTH_TOKEN="your_token" \ # Set your desired token here
|
| 78 |
+
# -e NOTION_ACTIVE_USER_HEADER="your_user_id" \ # Optional: Set the active user header
|
| 79 |
notion-api-bridge
|
| 80 |
```
|
| 81 |
The server will be available at `http://localhost:7860` (or whichever host port you mapped to the container's 7860). You will need to use the token provided in the `-e PROXY_AUTH_TOKEN` flag via an `Authorization: Bearer <token>` header for authentication.
|
|
|
|
| 90 |
* `NOTION_COOKIE`: Paste your Notion `token_v2` cookie value.
|
| 91 |
* `NOTION_SPACE_ID`: Paste your Notion Space ID.
|
| 92 |
* `PROXY_AUTH_TOKEN`: Paste the desired Bearer token for API authentication (e.g., a strong, generated token). If you omit this, the default `default_token` will be used.
|
| 93 |
+
* `NOTION_ACTIVE_USER_HEADER` (Optional): Paste the user ID to be sent in the `x-notion-active-user-header`. If omitted, the header will not be sent.
|
| 94 |
Hugging Face will securely inject these secrets as environment variables into your running container.
|
| 95 |
4. **Deployment:** Hugging Face Spaces will automatically build the Docker image from your `Dockerfile` and run the container. It detects applications running on port 7860 (as specified in the `Dockerfile` and metadata).
|
| 96 |
5. **Accessing the API:** Once the Space is running, you can access the API endpoint at the Space's public URL, providing the token via an `Authorization: Bearer <token>` header. The token must match the `PROXY_AUTH_TOKEN` secret you set (or the default `default_token`).
|
main.py
CHANGED
|
@@ -108,6 +108,11 @@ async def stream_notion_response(notion_request_body: NotionRequestBody):
|
|
| 108 |
'cookie': NOTION_COOKIE # Loaded from .env
|
| 109 |
}
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
chunk_id = f"chatcmpl-{uuid.uuid4()}"
|
| 112 |
created_time = int(time.time())
|
| 113 |
|
|
|
|
| 108 |
'cookie': NOTION_COOKIE # Loaded from .env
|
| 109 |
}
|
| 110 |
|
| 111 |
+
# Conditionally add the active user header
|
| 112 |
+
notion_active_user = os.getenv("NOTION_ACTIVE_USER_HEADER")
|
| 113 |
+
if notion_active_user: # Checks for None and empty string implicitly
|
| 114 |
+
headers['x-notion-active-user-header'] = notion_active_user
|
| 115 |
+
|
| 116 |
chunk_id = f"chatcmpl-{uuid.uuid4()}"
|
| 117 |
created_time = int(time.time())
|
| 118 |
|