Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Prepare for the better update system in 0.1.0 #122

Merged
merged 5 commits into from
Jun 18, 2022
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
71 changes: 69 additions & 2 deletions logic/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,74 @@ export type App = {
/** Automatically added */
compatible: boolean;
};

export type MetadataV4 = {
/**
* The category for the app
*/
category: string;
/**
* The app's default password. Can also be $APP_SEED for a random password
*/
defaultPassword?: string | undefined;
developers: Record<string, string>;
/**
* A list of promo images for the apps
*/
gallery?: string[] | undefined;
/**
* The name of the app
*/
name: string;
/**
* The path the "Open" link on the dashboard should lead to
*/
path?: string | undefined;
/**
* Permissions the app requires
*/
permissions?: Array<string | string[]>;
/**
* App repository name -> repo URL
*/
repo: Record<string, string>;
/**
* A support link for the app
*/
support: string;
/**
* A short tagline for the app
*/
tagline: string;
/**
* True if the app only works over Tor
*/
torOnly?: boolean;
/**
* A list of containers to update automatically (still validated by the Citadel team)
*/
updateContainers?: string[] | undefined;
/**
* The version of the app
*/
version: string;
/** Automatically added */
hiddenService?: string;
/** Automatically added */
installed?: boolean;
/** Automatically added */
compatible: boolean;
};

export type AppQuery = {
installed?: boolean;
compatible?: boolean;
};

export async function get(query: AppQuery, jwt: string): Promise<App[]> {
export async function get(
query: AppQuery,
jwt: string,
): Promise<Array<App | MetadataV4>> {
let apps = await diskLogic.readAppRegistry();
const lightningImplementation = await lightningService.getImplementation(jwt);
// Do all hidden service lookups concurrently
Expand Down Expand Up @@ -91,7 +154,11 @@ export async function get(query: AppQuery, jwt: string): Promise<App[]> {
if (query.installed === true) {
const userFile = await diskLogic.readUserFile();
const installedApps = userFile.installedApps ?? [];
apps = apps.filter((app: App) => installedApps.includes(app.id));
apps = apps.filter((app) => installedApps.includes(app.id));
}

if (query.compatible === true) {
apps = apps.filter((app) => app.compatible);
}

return apps;
Expand Down
23 changes: 17 additions & 6 deletions logic/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {encode, UrlVersion} from '@runcitadel/lndconnect';
import socksProxyAgentPkg from 'socks-proxy-agent';

import type {
versionFile,
updateStatus,
debugStatus,
backupStatus,
Expand Down Expand Up @@ -43,7 +42,15 @@ export type SystemStatus = {
highMemoryUsage: boolean;
};

export async function getInfo(): Promise<versionFile> {
export type VersionFile = {
version: string;
name: string;
requires: string;
notes: string;
isQuickUpdate?: boolean;
};

export async function getInfo(): Promise<VersionFile> {
try {
const info = await diskLogic.readVersionFile();
return info;
Expand Down Expand Up @@ -116,14 +123,14 @@ export async function getBitcoinRpcConnectionDetails(): Promise<RpcConnectionDet
}
}

export async function getAvailableUpdate(): Promise<versionFile | string> {
export async function getAvailableUpdate(): Promise<VersionFile | string> {
try {
const current = await diskLogic.readVersionFile();
const currentVersion = current.version;

// 'tag' should be the default Git branch
let tag = constants.GITHUB_BRANCH;
let data: versionFile | undefined;
let data: VersionFile | undefined;
let isNewVersionAvailable = true;
let isCompatibleWithCurrentVersion = false;

Expand All @@ -135,7 +142,7 @@ export async function getAvailableUpdate(): Promise<versionFile | string> {
// eslint-disable-next-line no-await-in-loop
const latestVersionInfo = await nodeFetch(infoUrl, {agent});
// eslint-disable-next-line no-await-in-loop
data = (await latestVersionInfo.json()) as versionFile;
data = (await latestVersionInfo.json()) as VersionFile;

const latestVersion = data.version;
const requiresVersionRange = data.requires;
Expand Down Expand Up @@ -423,5 +430,9 @@ export async function requestReboot(): Promise<systemStatus> {
}

export async function setUpdateChannel(channel: string): Promise<void> {
return runCommand(`set-update-channel ${channel}`);
return runCommand(`trigger set-update-channel ${channel}`);
}

export async function startQuickUpdate(): Promise<void> {
return runCommand(`trigger quick-update`);
}
6 changes: 6 additions & 0 deletions routes/v2/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ router.post('/update', auth.jwt, async (ctx, next) => {
await next();
});

router.post('/quick-update', auth.jwt, async (ctx, next) => {
await systemLogic.startQuickUpdate();
ctx.body = {};
await next();
});

router.get('/backup-status', auth.jwt, async (ctx, next) => {
ctx.body = await systemLogic.getBackupStatus();
await next();
Expand Down