diff --git a/src/commands/snapshot.ts b/src/commands/snapshot.ts index 30b1c3ad..4d0a6cb6 100644 --- a/src/commands/snapshot.ts +++ b/src/commands/snapshot.ts @@ -6,6 +6,7 @@ import { createSnapshotMissionControl, deleteSnapshotMissionControl, downloadSnapshotMissionControl, + listSnapshotMissionControl, restoreSnapshotMissionControl, uploadSnapshotMissionControl } from '../services/modules/snapshot/snapshot.mission-control.services'; @@ -13,6 +14,7 @@ import { createSnapshotOrbiter, deleteSnapshotOrbiter, downloadSnapshotOrbiter, + listSnapshotOrbiter, restoreSnapshotOrbiter, uploadSnapshotOrbiter } from '../services/modules/snapshot/snapshot.orbiter.services'; @@ -20,6 +22,7 @@ import { createSnapshotSatellite, deleteSnapshotSatellite, downloadSnapshotSatellite, + listSnapshotSatellite, restoreSnapshotSatellite, uploadSnapshotSatellite } from '../services/modules/snapshot/snapshot.satellite.services'; @@ -44,6 +47,14 @@ export const snapshot = async (args?: string[]) => { orbiterFn: restoreSnapshotOrbiter }); break; + case 'list': + await executeSnapshotFn({ + args, + satelliteFn: listSnapshotSatellite, + missionControlFn: listSnapshotMissionControl, + orbiterFn: listSnapshotOrbiter + }); + break; case 'delete': await executeSnapshotFn({ args, diff --git a/src/help/snapshot.help.ts b/src/help/snapshot.help.ts index 6e57624d..d21ed036 100644 --- a/src/help/snapshot.help.ts +++ b/src/help/snapshot.help.ts @@ -15,6 +15,7 @@ Subcommands: ${magenta('create')} Create a snapshot of your current state. ${magenta('delete')} Delete an existing snapshot. ${magenta('download')} Download a snapshot to offline files. + ${magenta('list')} List the existing snapshot. ${magenta('upload')} ${SNAPSHOT_UPLOAD_DESCRIPTION} ${magenta('restore')} Restore a previously created snapshot. diff --git a/src/services/modules/snapshot/snapshot.mission-control.services.ts b/src/services/modules/snapshot/snapshot.mission-control.services.ts index 36b64417..b0743e31 100644 --- a/src/services/modules/snapshot/snapshot.mission-control.services.ts +++ b/src/services/modules/snapshot/snapshot.mission-control.services.ts @@ -6,6 +6,7 @@ import { createSnapshot, deleteSnapshot, downloadSnapshot, + listSnapshot, restoreSnapshot, uploadSnapshot } from './snapshot.services'; @@ -22,6 +23,12 @@ export const restoreSnapshotMissionControl = async () => { }); }; +export const listSnapshotMissionControl = async () => { + await executeSnapshotFn({ + fn: listSnapshot + }); +}; + export const deleteSnapshotMissionControl = async () => { await executeSnapshotFn({ fn: deleteSnapshot diff --git a/src/services/modules/snapshot/snapshot.orbiter.services.ts b/src/services/modules/snapshot/snapshot.orbiter.services.ts index d2bb6c17..dd8cd73c 100644 --- a/src/services/modules/snapshot/snapshot.orbiter.services.ts +++ b/src/services/modules/snapshot/snapshot.orbiter.services.ts @@ -4,6 +4,7 @@ import { createSnapshot, deleteSnapshot, downloadSnapshot, + listSnapshot, restoreSnapshot, uploadSnapshot } from './snapshot.services'; @@ -20,6 +21,12 @@ export const restoreSnapshotOrbiter = async () => { }); }; +export const listSnapshotOrbiter = async () => { + await executeSnapshotFn({ + fn: listSnapshot + }); +}; + export const deleteSnapshotOrbiter = async () => { await executeSnapshotFn({ fn: deleteSnapshot diff --git a/src/services/modules/snapshot/snapshot.satellite.services.ts b/src/services/modules/snapshot/snapshot.satellite.services.ts index 53af5658..6896ec46 100644 --- a/src/services/modules/snapshot/snapshot.satellite.services.ts +++ b/src/services/modules/snapshot/snapshot.satellite.services.ts @@ -7,6 +7,7 @@ import { createSnapshot, deleteSnapshot, downloadSnapshot, + listSnapshot, restoreSnapshot, uploadSnapshot } from './snapshot.services'; @@ -23,6 +24,12 @@ export const restoreSnapshotSatellite = async () => { }); }; +export const listSnapshotSatellite = async () => { + await executeSnapshotFn({ + fn: listSnapshot + }); +}; + export const deleteSnapshotSatellite = async () => { await executeSnapshotFn({ fn: deleteSnapshot diff --git a/src/services/modules/snapshot/snapshot.services.ts b/src/services/modules/snapshot/snapshot.services.ts index 71871083..80cf166a 100644 --- a/src/services/modules/snapshot/snapshot.services.ts +++ b/src/services/modules/snapshot/snapshot.services.ts @@ -67,6 +67,26 @@ export const restoreSnapshot = async ({ }); }; +export const listSnapshot = async ({ + canisterId: cId, + segment +}: { + canisterId: string; + segment: AssetKey; +}) => { + const canisterId = Principal.fromText(cId); + + const result = await loadSnapshotAndAssertExist({canisterId, segment}); + + if (result.result === 'not_found') { + return; + } + + const {snapshotId: existingSnapshotId} = result; + + console.log(`🪣 Snapshot found: 0x${encodeSnapshotId(existingSnapshotId)}`); +}; + export const deleteSnapshot = async ({ canisterId: cId, segment