feat: adding cloud sync

This commit is contained in:
Chubby Granny Chaser 2024-09-25 19:37:28 +01:00
parent d88e06e289
commit e64a414309
No known key found for this signature in database
33 changed files with 1352 additions and 84 deletions

View file

@ -0,0 +1,61 @@
import type { GameShop, LudusaviBackup, LudusaviFindResult } from "@types";
import cp from "node:child_process";
import { workerData } from "node:worker_threads";
const { binaryPath } = workerData;
export const findGames = ({
shop,
objectId,
}: {
shop: GameShop;
objectId: string;
}) => {
const args = ["find", "--api"];
if (shop === "steam") {
args.push("--steam-id", objectId);
}
const result = cp.execFileSync(binaryPath, args);
const games = JSON.parse(result.toString("utf-8")) as LudusaviFindResult;
return Object.keys(games.games);
};
export const backupGame = ({
title,
backupPath,
preview = false,
}: {
title: string;
backupPath: string;
preview?: boolean;
}) => {
const args = ["backup", title, "--api", "--force"];
if (preview) {
args.push("--preview");
}
if (backupPath) {
args.push("--path", backupPath);
}
const result = cp.execFileSync(binaryPath, args);
return JSON.parse(result.toString("utf-8")) as LudusaviBackup;
};
export const restoreBackup = (backupPath: string) => {
const result = cp.execFileSync(binaryPath, [
"restore",
"--path",
backupPath,
"--api",
"--force",
]);
return JSON.parse(result.toString("utf-8")) as LudusaviBackup;
};