1
0
mirror of https://github.com/XFox111/TabsAsideExtension.git synced 2026-04-22 07:58:01 +03:00
Files
TabsAsideExtension/features/migration/utils/migrateCollections.ts
T
xfox111 2bd9337e63 Major 3.0 (#118)
Co-authored-by: Maison da Silva <maisonmdsgreen@hotmail.com>
2025-07-30 15:02:26 +03:00

39 lines
1.1 KiB
TypeScript

import { CollectionItem, GraphicsStorage, TabItem } from "@/models/CollectionModels";
import { LegacyCollection } from "../models/LegacyModels";
export default function migrateCollections(legacyCollections: LegacyCollection[]): [CollectionItem[], GraphicsStorage]
{
const collections: CollectionItem[] = [];
const graphics: GraphicsStorage = {};
for (let i = 0; i < legacyCollections.length; i++)
{
const legacyCollection: LegacyCollection = legacyCollections[i];
const items: TabItem[] = legacyCollection.links.map((url, index) =>
{
const title: string | undefined = legacyCollection.titles[index];
const icon: string | undefined = legacyCollection.icons?.[index];
const capture: string | undefined = legacyCollection.thumbnails?.[index];
if (!graphics[url])
graphics[url] = { icon, capture };
else
graphics[url] = { icon: graphics[url].icon ?? icon, capture: graphics[url].preview ?? capture };
return {
type: "tab",
url,
title
};
});
collections.push({
type: "collection",
timestamp: legacyCollection.timestamp,
items
});
}
return [collections, graphics];
}