mirror of
https://github.com/XFox111/TabsAsideExtension.git
synced 2026-04-22 07:58:01 +03:00
!feat: major 3.0 release candidate
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { CollectionItem } from "@/models/CollectionModels";
|
||||
import getLogger from "@/utils/getLogger";
|
||||
import { collectionStorage } from "./collectionStorage";
|
||||
import getCollectionsFromCloud from "./getCollectionsFromCloud";
|
||||
import getCollectionsFromLocal from "./getCollectionsFromLocal";
|
||||
import saveCollectionsToCloud from "./saveCollectionsToCloud";
|
||||
import saveCollectionsToLocal from "./saveCollectionsToLocal";
|
||||
|
||||
const logger = getLogger("resolveConflict");
|
||||
|
||||
export default function resolveConflict(acceptSource: "local" | "sync"): Promise<void>
|
||||
{
|
||||
if (acceptSource === "local")
|
||||
return replaceCloudWithLocal();
|
||||
|
||||
return replaceLocalWithCloud();
|
||||
}
|
||||
|
||||
async function replaceCloudWithLocal(): Promise<void>
|
||||
{
|
||||
const collections: CollectionItem[] = await getCollectionsFromLocal();
|
||||
const lastUpdated: number = await collectionStorage.localLastUpdated.getValue();
|
||||
|
||||
await saveCollectionsToCloud(collections, lastUpdated);
|
||||
}
|
||||
|
||||
async function replaceLocalWithCloud(): Promise<void>
|
||||
{
|
||||
try
|
||||
{
|
||||
const collections: CollectionItem[] = await getCollectionsFromCloud();
|
||||
const lastUpdated: number = await collectionStorage.syncLastUpdated.getValue();
|
||||
|
||||
await saveCollectionsToLocal(collections, lastUpdated);
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
logger("Failed to get cloud storage");
|
||||
console.error(ex);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user