initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
venv/
|
||||
desktop.ini
|
||||
static/
|
||||
46
PLANNING.md
Normal file
46
PLANNING.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Project Planning and Code Guidelines
|
||||
|
||||
## General Code Guidelines
|
||||
|
||||
* **Modular Design:** Use Object-Oriented Programming (OOP) where possible to separate concerns and promote code reuse.
|
||||
* **File Size Limit:** No single Python file should exceed **600 lines** to improve readability and maintainability.
|
||||
* **Commenting:**
|
||||
|
||||
* Use clear, concise comments to explain complex logic.
|
||||
* Include function and class docstrings where appropriate.
|
||||
* Use in-line comments sparingly and only when the logic is not immediately obvious.
|
||||
* **Code Structure:**
|
||||
|
||||
* Follow the Model-View-Controller (MVC) pattern where applicable.
|
||||
* Group related classes and functions into separate modules for clarity.
|
||||
* **Error Handling:** Implement robust error handling with meaningful messages and fallback behavior where possible.
|
||||
* **Readability:**
|
||||
|
||||
* Use meaningful variable and function names.
|
||||
* Avoid deeply nested loops and conditionals where possible.
|
||||
|
||||
## API Design Guidelines
|
||||
|
||||
* **RESTful Endpoints:** Use RESTful conventions for all API endpoints.
|
||||
* **Status Codes:** Return appropriate HTTP status codes (e.g., 200 for success, 404 for not found, 500 for server error).
|
||||
* **Error Responses:** Provide consistent and descriptive error messages.
|
||||
* **Data Validation:** Validate all incoming data to prevent unexpected behavior and security issues.
|
||||
|
||||
## File Organization
|
||||
|
||||
* **Static Files:** Store images in the `static/images/` directory.
|
||||
* **Product Data:** Store product metadata in `products.json`.
|
||||
* **Configuration Files:** Use a dedicated `config/` directory for environment-specific settings.
|
||||
|
||||
## Security Guidelines
|
||||
|
||||
* **No Hardcoded Credentials:** Avoid hardcoding sensitive information like passwords or API keys.
|
||||
* **Input Sanitization:** Validate and sanitize all user input to prevent injection attacks.
|
||||
* **Minimal Permissions:** Run the application with the least required privileges.
|
||||
|
||||
## Future Considerations
|
||||
|
||||
* **Scalability:** Plan for the potential migration to a database if the product catalog grows.
|
||||
* **API Rate Limiting:** Consider adding rate limiting for public APIs.
|
||||
* **Monitoring and Logging:** Implement basic logging for audit trails and error diagnosis.
|
||||
* **Deployment Automation:** Use Docker or other containerization for easy deployment and scaling.
|
||||
63
README.md
Normal file
63
README.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Flask AR API Demo
|
||||
|
||||
This project is a simple Flask API for demonstrating AR content retrieval for barcode scanning applications. It simulates the Knox Capture API for AR overlays and includes endpoints for managing product attributes, including text and image URLs.
|
||||
|
||||
## Features
|
||||
|
||||
* **Login Endpoint (`/login`)**
|
||||
|
||||
* Simulates a simple login with a 200 response (no authentication required for demo purposes).
|
||||
* **Content Fields Endpoint (`/arcontentfields`)**
|
||||
|
||||
* Returns a list of available attributes (e.g., item ID, price, image URI).
|
||||
* \*\*AR Info Endpoint (`/arinfo`)
|
||||
|
||||
* Returns product details for a given barcode, including image URLs.
|
||||
* \*\*Static Image Server (`/images/<filename>`)
|
||||
|
||||
* Serves image files from the `static/images/` directory.
|
||||
|
||||
## Setup
|
||||
|
||||
1. **Clone the Repository:**
|
||||
|
||||
```bash
|
||||
git clone <repository_url>
|
||||
cd <repository_folder>
|
||||
```
|
||||
|
||||
2. **Create the Static Directory:**
|
||||
|
||||
```bash
|
||||
mkdir -p static/images
|
||||
```
|
||||
|
||||
3. **Add Sample Images:**
|
||||
|
||||
* Place sample product images in the `static/images/` directory.
|
||||
* Ensure the filenames match the item IDs used in the app (e.g., `123456.png`, `789012.png`).
|
||||
|
||||
4. **Install Dependencies:**
|
||||
|
||||
```bash
|
||||
pip install flask
|
||||
```
|
||||
|
||||
5. **Run the Server:**
|
||||
|
||||
```bash
|
||||
python app.py
|
||||
```
|
||||
|
||||
6. **Test the Endpoints:**
|
||||
|
||||
* Login: `GET http://localhost:5555/login`
|
||||
* Content Fields: `GET http://localhost:5555/arcontentfields`
|
||||
* AR Info (Example): `GET http://localhost:5555/arinfo?barcode=123456`
|
||||
* Image File (Example): `GET http://localhost:5555/images/123456.png`
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
* Add a basic admin UI for adding and managing products.
|
||||
* Store product data in a JSON file for persistence.
|
||||
* Add image upload capabilities through the admin UI.
|
||||
33
TASK.md
Normal file
33
TASK.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# Task List - Flask AR API Demo
|
||||
|
||||
## Phase 1: Basic Admin UI
|
||||
|
||||
* [ ] Create a simple admin UI (no authentication required for demo purposes).
|
||||
* [ ] Allow adding, updating, and deleting products.
|
||||
* [ ] Store all product data in a `products.json` file for persistence.
|
||||
* [ ] Store images in the `static/images/` directory.
|
||||
* [ ] Implement basic form validation for product fields (ID, price, image).
|
||||
* [ ] Add a file upload feature for product images.
|
||||
|
||||
## Phase 2: API Improvements
|
||||
|
||||
* [ ] Update the `/arinfo` endpoint to read from `products.json` instead of the in-memory dictionary.
|
||||
* [ ] Add support for updating product attributes via the API.
|
||||
* [ ] Implement error handling and input validation.
|
||||
* [ ] Optimize image loading for better performance.
|
||||
|
||||
## Phase 3: UI Enhancements
|
||||
|
||||
* [ ] Add a responsive design for mobile and tablet support.
|
||||
* [ ] Include image previews in the admin UI.
|
||||
* [ ] Add sorting and search capabilities for the product list.
|
||||
|
||||
## Future Ideas
|
||||
|
||||
* [ ] Write basic unit tests for the API.
|
||||
* [ ] Dockerize the application for easier deployment.
|
||||
* [ ] Add a basic CI/CD pipeline (e.g., GitHub Actions or GitLab CI).
|
||||
* [ ] Add user authentication for the admin UI.
|
||||
* [ ] Implement role-based access control (RBAC).
|
||||
* [ ] Add analytics for product views and updates.
|
||||
* [ ] Integrate with a database for larger product catalogs.
|
||||
51
app.py
Normal file
51
app.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from flask import Flask, jsonify, request, send_file
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['STATIC_FOLDER'] = './static'
|
||||
|
||||
# Sample in-memory data for item attributes
|
||||
ITEM_ATTRIBUTES = {
|
||||
"123456": [
|
||||
{"fieldName": "_id", "label": "Item ID", "value": "123456", "editable": "false", "fieldType": "TEXT"},
|
||||
{"fieldName": "_price", "label": "Sale Price", "value": "$49.99", "editable": "true", "fieldType": "TEXT"},
|
||||
{"fieldName": "_image", "label": "Image", "value": "/images/123456.png", "editable": "false", "fieldType": "IMAGE_URI"}
|
||||
],
|
||||
"789012": [
|
||||
{"fieldName": "_id", "label": "Item ID", "value": "789012", "editable": "false", "fieldType": "TEXT"},
|
||||
{"fieldName": "_price", "label": "Sale Price", "value": "$59.99", "editable": "true", "fieldType": "TEXT"},
|
||||
{"fieldName": "_image", "label": "Image", "value": "/images/789012.png", "editable": "false", "fieldType": "IMAGE_URI"}
|
||||
]
|
||||
}
|
||||
|
||||
@app.route('/login', methods=['GET'])
|
||||
def login():
|
||||
# Just return 200 for this example, assuming no auth needed
|
||||
return '', 200
|
||||
|
||||
@app.route('/arcontentfields', methods=['GET'])
|
||||
def get_ar_content_fields():
|
||||
# Return a fixed set of attributes
|
||||
fields = [
|
||||
{"fieldName": "_id", "label": "Item ID", "editable": "false", "fieldType": "TEXT"},
|
||||
{"fieldName": "_price", "label": "Sale Price", "editable": "true", "fieldType": "TEXT"},
|
||||
{"fieldName": "_image", "label": "Image", "editable": "false", "fieldType": "IMAGE_URI"}
|
||||
]
|
||||
return jsonify(fields), 200
|
||||
|
||||
@app.route('/arinfo', methods=['GET'])
|
||||
def get_ar_info():
|
||||
barcode = request.args.get('barcode')
|
||||
if not barcode or barcode not in ITEM_ATTRIBUTES:
|
||||
return jsonify({"error": "Item not found"}), 404
|
||||
return jsonify(ITEM_ATTRIBUTES[barcode]), 200
|
||||
|
||||
@app.route('/images/<path:filename>', methods=['GET'])
|
||||
def serve_image(filename):
|
||||
image_path = os.path.join(app.config['STATIC_FOLDER'], filename)
|
||||
if os.path.exists(image_path):
|
||||
return send_file(image_path)
|
||||
return jsonify({"error": "Image not found"}), 404
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(port=5555, host="0.0.0.0", debug=True)
|
||||
Reference in New Issue
Block a user