70 lines
1.6 KiB
TypeScript
70 lines
1.6 KiB
TypeScript
import { i18n } from '../i18n'
|
|
import { sdk } from '../sdk'
|
|
import { dataDir, SPACED_CHAIN } from '../utils'
|
|
|
|
export const syncStatus = sdk.Action.withoutInput(
|
|
// id
|
|
'sync-status',
|
|
|
|
// metadata
|
|
async ({ effects }) => ({
|
|
name: i18n('Sync Status'),
|
|
description: i18n(
|
|
"Query spaced's getserverinfo RPC and report sync progress",
|
|
),
|
|
warning: null,
|
|
allowedStatuses: 'only-running',
|
|
group: null,
|
|
visibility: 'enabled',
|
|
}),
|
|
|
|
// run
|
|
async ({ effects }) => {
|
|
const res = await sdk.SubContainer.withTemp(
|
|
effects,
|
|
{ imageId: 'spaces' },
|
|
sdk.Mounts.of().mountVolume({
|
|
volumeId: 'main',
|
|
subpath: null,
|
|
mountpoint: dataDir,
|
|
readonly: false,
|
|
}),
|
|
'spaces-sync-status',
|
|
(subc) =>
|
|
subc.exec([
|
|
'/root/.cargo/bin/space-cli',
|
|
'--chain',
|
|
SPACED_CHAIN,
|
|
'--rpc-cookie',
|
|
`${dataDir}/${SPACED_CHAIN}/.cookie`,
|
|
'getserverinfo',
|
|
]),
|
|
)
|
|
|
|
if (res.exitCode !== 0) {
|
|
return {
|
|
version: '1',
|
|
title: i18n('Failure'),
|
|
message: i18n('Could not query spaced. Is the service running?'),
|
|
result: null,
|
|
}
|
|
}
|
|
|
|
const stdout = (res.stdout ?? '').toString().trim()
|
|
return {
|
|
version: '1',
|
|
title: i18n('Sync Status'),
|
|
message: stdout || i18n('spaced is fully synced.'),
|
|
result: {
|
|
type: 'single',
|
|
name: 'getserverinfo',
|
|
description: null,
|
|
value: stdout,
|
|
masked: false,
|
|
copyable: true,
|
|
qr: false,
|
|
},
|
|
}
|
|
},
|
|
)
|