Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions apps/backend/app/api/routes/bookmarks/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class BookmarkOut(BookmarkBase):
id: str
createdAt: int
updatedAt: int
created_by: str


class BookmarkFolderBase(BaseModel):
Expand Down Expand Up @@ -101,14 +100,13 @@ class BookmarkFolderExpanded(BaseModel):
class BookmarkFolderOut(BookmarkFolderBase):
id: str
createdAt: int
created_by: str


class BookmarkImportBody(BaseModel):
"""Same shape as ``exportBookmarksToJSON`` / ``parseBookmarkJSON`` output."""

bookmarks: list[dict] = Field(default_factory=list)
folders: list[dict] = Field(default_factory=list)
bookmarks: list[BookmarkCreate] = Field(default_factory=list)
folders: list[BookmarkFolderCreate] = Field(default_factory=list)


class BookmarkSnapshotOut(BaseModel):
Expand Down
74 changes: 24 additions & 50 deletions apps/backend/app/api/routes/bookmarks/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def _bookmark_doc_to_out(doc: dict[str, Any]) -> BookmarkOut:
folderId=doc.get("folderId"),
createdAt=int(doc.get("createdAt", 0)),
updatedAt=int(doc.get("updatedAt", 0)),
created_by=doc.get("created_by", ""),
)


Expand All @@ -47,7 +46,6 @@ def _folder_doc_to_out(doc: dict[str, Any]) -> BookmarkFolderOut:
icon=doc.get("icon"),
isExpanded=doc.get("isExpanded"),
createdAt=int(doc.get("createdAt", 0)),
created_by=doc.get("created_by", ""),
)


Expand Down Expand Up @@ -137,63 +135,39 @@ async def delete_bookmark(uid: str, bookmark_id: str) -> None:


async def import_bookmarks(uid: str, body: BookmarkImportBody) -> dict[str, int]:
folder_count = 0
bookmark_count = 0
folder_ops: list[ReplaceOne] = []
bookmark_ops: list[ReplaceOne] = []
try:
for raw in body.folders:
row = dict(raw)
row.pop("created_by", None)
fid = row.pop("id", None) or row.pop("_id", None)
if not fid:
fid = new_id()
for folder in body.folders:
fid = str(folder.id or new_id())
doc = {
"_id": str(fid),
"_id": fid,
"created_by": uid,
"name": row.get("name", "Untitled"),
"parentId": row.get("parentId"),
"color": row.get("color"),
"icon": row.get("icon"),
"isExpanded": row.get("isExpanded", False),
"createdAt": int(row.get("createdAt", create_timestamp())),
"name": folder.name,
"parentId": folder.parentId,
"color": folder.color,
"icon": folder.icon,
"isExpanded": folder.isExpanded or False,
"createdAt": create_timestamp(),
}
folder_ops.append(
ReplaceOne(
{"_id": doc["_id"], "created_by": uid},
doc,
upsert=True,
)
)
folder_count += 1

for raw in body.bookmarks:
row = dict(raw)
row.pop("created_by", None)
bid = row.pop("id", None) or row.pop("_id", None)
if not bid:
bid = new_id()
folder_ops.append(ReplaceOne({"_id": fid, "created_by": uid}, doc, upsert=True))

for bookmark in body.bookmarks:
bid = str(bookmark.id or new_id())
ts = create_timestamp()
doc = {
"_id": str(bid),
"_id": bid,
"created_by": uid,
"title": row.get("title", ""),
"url": row.get("url", ""),
"description": row.get("description"),
"favicon": row.get("favicon"),
"tags": list(row.get("tags") or []),
"folderId": row.get("folderId"),
"createdAt": int(row.get("createdAt", ts)),
"updatedAt": int(row.get("updatedAt", ts)),
"title": bookmark.title,
"url": bookmark.url,
"description": bookmark.description,
"favicon": bookmark.favicon,
"tags": list(bookmark.tags),
"folderId": bookmark.folderId,
"createdAt": ts,
"updatedAt": ts,
}
bookmark_ops.append(
ReplaceOne(
{"_id": doc["_id"], "created_by": uid},
doc,
upsert=True,
)
)
bookmark_count += 1
bookmark_ops.append(ReplaceOne({"_id": bid, "created_by": uid}, doc, upsert=True))

if folder_ops:
await db_manager.bulk_write(FOLDERS, folder_ops, ordered=False)
Expand All @@ -203,7 +177,7 @@ async def import_bookmarks(uid: str, body: BookmarkImportBody) -> dict[str, int]
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to import bookmarks."
) from exc
return {"foldersUpserted": folder_count, "bookmarksUpserted": bookmark_count}
return {"foldersUpserted": len(folder_ops), "bookmarksUpserted": len(bookmark_ops)}


async def clear_all_bookmarks(uid: str) -> dict[str, int]:
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/af.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Vouers",
"tagsHeading": "Merkers",
"tagsMore": "+{count} meer",
"tagsShowLess": "Show less",
"searchPlaceholder": "Soek jou boekmerke...",
"import": "Invoer",
"export": "Uitvoer",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "المجلدات",
"tagsHeading": "الوسوم",
"tagsMore": "+{count} أخرى",
"tagsShowLess": "Show less",
"searchPlaceholder": "ابحث في الإشارات المرجعية...",
"import": "استيراد",
"export": "تصدير",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Carpetes",
"tagsHeading": "Etiquetes",
"tagsMore": "+{count} més",
"tagsShowLess": "Show less",
"searchPlaceholder": "Cerca marcadors...",
"import": "Importa",
"export": "Exporta",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Složky",
"tagsHeading": "Štítky",
"tagsMore": "+{count} dalších",
"tagsShowLess": "Show less",
"searchPlaceholder": "Hledat v záložkách...",
"import": "Import",
"export": "Export",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Mapper",
"tagsHeading": "Tags",
"tagsMore": "+{count} mere",
"tagsShowLess": "Show less",
"searchPlaceholder": "Søg i dine bogmærker...",
"import": "Importere",
"export": "Eksportere",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Ordner",
"tagsHeading": "Tags",
"tagsMore": "+{count} weitere",
"tagsShowLess": "Show less",
"searchPlaceholder": "Lesezeichen suchen...",
"import": "Importieren",
"export": "Exportieren",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Φάκελοι",
"tagsHeading": "Ετικέτες",
"tagsMore": "+{count} ακόμη",
"tagsShowLess": "Show less",
"searchPlaceholder": "Αναζήτηση στους σελιδοδείκτες σας...",
"import": "Εισαγωγή",
"export": "Εξαγωγή",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@
"foldersHeading": "Folders",
"tagsHeading": "Tags",
"tagsMore": "+{count} more",
"tagsShowLess": "Show less",
"searchPlaceholder": "Search your bookmarks...",
"import": "Import",
"export": "Export",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Carpetas",
"tagsHeading": "Etiquetas",
"tagsMore": "+{count} más",
"tagsShowLess": "Show less",
"searchPlaceholder": "Buscar en tus marcadores...",
"import": "Importar",
"export": "Exportar",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "پوشه ها",
"tagsHeading": "برچسب ها",
"tagsMore": "+{count} بیشتر",
"tagsShowLess": "Show less",
"searchPlaceholder": "بوک مارک های خود را جستجو کنید...",
"import": "واردات",
"export": "صادرات",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Dossiers",
"tagsHeading": "Étiquettes",
"tagsMore": "+{count} de plus",
"tagsShowLess": "Show less",
"searchPlaceholder": "Rechercher des signets…",
"import": "Importer",
"export": "Exporter",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Folder",
"tagsHeading": "Tag",
"tagsMore": "+{count} lagi",
"tagsShowLess": "Show less",
"searchPlaceholder": "Cari bookmark Anda...",
"import": "Impor",
"export": "Ekspor",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Cartelle",
"tagsHeading": "Tag",
"tagsMore": "+{count} altro",
"tagsShowLess": "Show less",
"searchPlaceholder": "Cerca nei tuoi segnalibri...",
"import": "Importare",
"export": "Esportare",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "フォルダー",
"tagsHeading": "タグ",
"tagsMore": "+{count}件",
"tagsShowLess": "Show less",
"searchPlaceholder": "ブックマークを検索...",
"import": "インポート",
"export": "エクスポート",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "폴더",
"tagsHeading": "태그",
"tagsMore": "+{count}개 더",
"tagsShowLess": "Show less",
"searchPlaceholder": "북마크 검색...",
"import": "가져오기",
"export": "내보내기",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/ms.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Folder",
"tagsHeading": "Tag",
"tagsMore": "+{count} lagi",
"tagsShowLess": "Show less",
"searchPlaceholder": "Cari penanda halaman anda...",
"import": "Import",
"export": "Eksport",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Mapper",
"tagsHeading": "Etiketter",
"tagsMore": "+{count} flere",
"tagsShowLess": "Show less",
"searchPlaceholder": "Søk i bokmerkene dine...",
"import": "Importer",
"export": "Eksporter",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Mappen",
"tagsHeading": "Tags",
"tagsMore": "+{count} meer",
"tagsShowLess": "Show less",
"searchPlaceholder": "Zoek je bladwijzers...",
"import": "Importeren",
"export": "Exporteren",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Folders",
"tagsHeading": "Tags",
"tagsMore": "+{count} more",
"tagsShowLess": "Show less",
"searchPlaceholder": "Search your bookmarks...",
"import": "Import",
"export": "Export",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Pastas",
"tagsHeading": "Tags",
"tagsMore": "+{count} mais",
"tagsShowLess": "Show less",
"searchPlaceholder": "Buscar favoritos...",
"import": "Importar",
"export": "Exportar",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Pastas",
"tagsHeading": "Etiquetas",
"tagsMore": "+{count} mais",
"tagsShowLess": "Show less",
"searchPlaceholder": "Pesquisar marcadores...",
"import": "Importar",
"export": "Exportar",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Папки",
"tagsHeading": "Теги",
"tagsMore": "+{count} ещё",
"tagsShowLess": "Show less",
"searchPlaceholder": "Поиск закладок...",
"import": "Импорт",
"export": "Экспорт",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Mappar",
"tagsHeading": "Taggar",
"tagsMore": "+{count} fler",
"tagsShowLess": "Show less",
"searchPlaceholder": "Sök bland dina bokmärken...",
"import": "Importera",
"export": "Exportera",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Klasörler",
"tagsHeading": "Etiketler",
"tagsMore": "+{count} daha",
"tagsShowLess": "Show less",
"searchPlaceholder": "Yer imlerinizde arayın...",
"import": "İçe Aktar",
"export": "Dışa Aktar",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Теки",
"tagsHeading": "Теги",
"tagsMore": "+{count} ще",
"tagsShowLess": "Show less",
"searchPlaceholder": "Пошук закладок...",
"import": "Імпорт",
"export": "Експорт",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "Thư mục",
"tagsHeading": "Nhãn",
"tagsMore": "+{count} thêm",
"tagsShowLess": "Show less",
"searchPlaceholder": "Tìm kiếm dấu trang...",
"import": "Nhập",
"export": "Xuất",
Expand Down
1 change: 1 addition & 0 deletions apps/web/messages/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@
"foldersHeading": "文件夹",
"tagsHeading": "标签",
"tagsMore": "另外 {count} 个",
"tagsShowLess": "Show less",
"searchPlaceholder": "搜索书签…",
"import": "导入",
"export": "导出",
Expand Down
Loading