diff options
author | Christian Cleberg <hello@cleberg.net> | 2025-06-04 13:24:22 -0500 |
---|---|---|
committer | Christian Cleberg <hello@cleberg.net> | 2025-06-04 13:24:22 -0500 |
commit | 8bbac67df8450b021914725a756a029667b8f585 (patch) | |
tree | 1e5f13a29e6a4542fb5976dc74b15db2e89b2a32 /server.py | |
download | crumb-8bbac67df8450b021914725a756a029667b8f585.tar.gz crumb-8bbac67df8450b021914725a756a029667b8f585.tar.bz2 crumb-8bbac67df8450b021914725a756a029667b8f585.zip |
feat: initial commit
Diffstat (limited to 'server.py')
-rw-r--r-- | server.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/server.py b/server.py new file mode 100644 index 0000000..31c0d4c --- /dev/null +++ b/server.py @@ -0,0 +1,50 @@ +from flask import Flask, request, jsonify, make_response +import os +from datetime import datetime + +app = Flask(__name__) +LOG_PATH = os.path.expanduser("~/.crumb/history.org") + +os.makedirs(os.path.dirname(LOG_PATH), exist_ok=True) + +@app.after_request +def add_cors_headers(response): + response.headers['Access-Control-Allow-Origin'] = '*' + response.headers['Access-Control-Allow-Headers'] = 'Content-Type' + return response + +@app.route('/', methods=['POST', 'OPTIONS']) +def log_visit(): + if request.method == 'OPTIONS': + return '', 204 + + data = request.json + title = data.get("title", "No Title") + url = data.get("url", "No URL") + hostname = data.get("hostname", "") + path = data.get("path", "") + query = data.get("query", "") + tab_id = data.get("tabId", "") + window_id = data.get("windowId", "") + favicon = data.get("favIconUrl", "") + timestamp = datetime.utcnow().isoformat() + + with open(LOG_PATH, "a") as f: + f.write(f"* {title}\n") + f.write(":PROPERTIES:\n") + f.write(f":URL: {url}\n") + f.write(f":TIMESTAMP: {timestamp}\n") + f.write(f":HOST: {hostname}\n") + f.write(f":PATH: {path}\n") + if query: + f.write(f":QUERY: {query}\n") + f.write(f":TAB: {tab_id}\n") + f.write(f":WINDOW: {window_id}\n") + if favicon: + f.write(f":FAVICON: {favicon}\n") + f.write(":END:\n\n") + + return '', 204 + +if __name__ == '__main__': + app.run(port=3555)
\ No newline at end of file |