From 6c1b932d5d2f77ec9e7a08c4f0237d1149a73c0d Mon Sep 17 00:00:00 2001 From: Srivishnu Karthik B Date: Thu, 30 Jul 2026 11:40:44 +0530 Subject: [PATCH 1/3] Add export route for snippets in JSON format Added a route to export all snippets as a downloadable JSON file, converting ObjectId and datetime objects for JSON compatibility. --- app/routes.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index 9ffbaa8..24b9541 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,8 +1,9 @@ from datetime import datetime, UTC from math import ceil +import json from bson import ObjectId -from flask import Blueprint, render_template, request, redirect, url_for, flash +from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify from app.db import snippets_collection from app.forms import SnippetForm @@ -136,3 +137,25 @@ def edit_snippet(id): form.tags.data = ", ".join(snippet.get("tags", [])) return render_template("edit.html", form=form, snippet=snippet) + + +@main.route("/export") +def export_snippets(): + """Export all snippets as downloadable JSON file""" + # Get all snippets from database + snippets = list(snippets_collection.find()) + + # Convert ObjectId to string for JSON compatibility + for snippet in snippets: + snippet["_id"] = str(snippet["_id"]) + # Convert datetime objects to ISO format strings + if "created_at" in snippet: + snippet["created_at"] = snippet["created_at"].isoformat() + if "updated_at" in snippet: + snippet["updated_at"] = snippet["updated_at"].isoformat() + + # Return JSON with download headers + return jsonify(snippets), 200, { + "Content-Disposition": "attachment; filename=stash_snip_backup.json", + "Content-Type": "application/json" + } From 818d552d5a32503e4ac94fdd180c007f2372639f Mon Sep 17 00:00:00 2001 From: Srivishnu Karthik B Date: Thu, 30 Jul 2026 11:42:59 +0530 Subject: [PATCH 2/3] Add export section styles to style.css --- app/static/style.css | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/static/style.css b/app/static/style.css index 6d75d30..809b879 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -501,3 +501,34 @@ main { max-width: 1000px; margin: 0 auto; padding: 2rem 1.5rem; } border-color: var(--amber); color: var(--amber); } + +.export-section { + margin: 20px 0; + display: flex; + justify-content: flex-start; +} + +.export-btn { + display: inline-flex; + align-items: center; + gap: 8px; + padding: 10px 16px; + background-color: #4CAF50; + color: white; + text-decoration: none; + border-radius: 4px; + font-size: 14px; + font-weight: 500; + transition: background-color 0.3s ease; + border: none; + cursor: pointer; +} + +.export-btn:hover { + background-color: #45a049; +} + +.export-btn svg { + width: 16px; + height: 16px; +} From 7f524831844fff0dd94db3980e051aba5f863497 Mon Sep 17 00:00:00 2001 From: Srivishnu Karthik B Date: Thu, 30 Jul 2026 11:44:24 +0530 Subject: [PATCH 3/3] Add export section for downloading snippets as JSON Added export section with JSON download functionality. --- app/templates/index.html | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/templates/index.html b/app/templates/index.html index 92146b6..efeb2dd 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -6,6 +6,17 @@

My Snips

{{ total_snippets }} snippet{{ 's' if total_snippets != 1 else '' }} found

+ +