Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup Spoke project assets #17

Merged
merged 1 commit into from
May 15, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hubs-backup-tool",
"productName": "Hubs Backup Tool",
"version": "1.0.4",
"version": "1.0.5",
"description": "Tool for backing up your assets from a Hubs instance",
"main": ".webpack/main",
"scripts": {
Expand Down
58 changes: 53 additions & 5 deletions src/api/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,64 @@ async function backupBlenderProjects(
}
}

async function processSpokeScene(
sceneUrl: string,
projectDir: string,
override: boolean
) {
const url = new URL(sceneUrl);
const fileName = url.pathname.split("/").pop();
if (fileName) {
await downloadFile({
url: sceneUrl,
outPath: path.join(projectDir, fileName),
override,
});
try {
const fileText = readFileSync(path.join(projectDir, fileName), {
encoding: "utf-8",
}) as never;
const parsed = JSON.parse(fileText);
if ("entities" in parsed) {
for (const entity in parsed["entities"]) {
const thisEntity = parsed["entities"][entity];
if ("components" in thisEntity) {
for (const component of thisEntity["components"]) {
if ("src" in component["props"]) {
const src = component["props"]["src"];
const assetUrl = new URL(src);
const assetFileName = assetUrl.pathname.split("/").pop();
await downloadFile({
url: component["props"]["src"],
outPath: path.join(projectDir, assetFileName),
override,
});
}
}
}
}
}
} catch (e) {
log.error(e);
}
}
}

async function backupScene(
api: ReticulumApi,
scene: SceneT,
projectDir: string,
override: boolean
) {
writeFileSync(
path.join(projectDir, `${scene.scene_id}.json`),
JSON.stringify(scene, null, 2),
{ encoding: "utf-8" }
);
const spokeFilePath = path.join(projectDir, `${scene.scene_id}.json`);
writeFileSync(spokeFilePath, JSON.stringify(scene, null, 2), {
encoding: "utf-8",
});

if (scene.scene_project_url) {
await processSpokeScene(scene.scene_project_url, projectDir, override);
}

const url = new URL(scene.model_url);
const fileName = url.pathname.split("/").pop();
if (fileName) {
Expand Down Expand Up @@ -253,6 +300,7 @@ async function backupSpokeProjects(
path.join(projectDir, fileName),
path.join(projectDir, `${project.name}.spoke`)
);
await processSpokeScene(project.project_url, projectDir, override);
}
}
if (project.thumbnail_url) {
Expand Down
1 change: 1 addition & 0 deletions src/api/reticulum-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface SceneT {
screenshot_url: string;
type: ReticulumAssetType;
url: string;
scene_project_url?: string;
}

export interface ProjectT {
Expand Down
Loading