Skip to content

Commit 070bb68

Browse files
committed
fix get server spec for working offline
1 parent ce4b29f commit 070bb68

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/common/download/index.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ import { createProgress } from "../utils/progress";
99
import { formatBytes } from "../utils/formatBytes";
1010
import { checkFileOrFolderExists, getChecksum, getSaveFolder } from "./utils";
1111
import Logger from "../logger";
12-
import { TypeModel } from "../server";
12+
import type { TypeModel } from "../server";
1313
import { configuration } from "../utils/configuration";
14+
import { state } from "../utils/state";
1415

1516
interface ResourceInfo {
1617
url: string;
1718
checksum: string;
1819
}
1920

20-
interface Spec {
21+
export interface Spec {
2122
linux: {
2223
"x86-64": {
2324
cpu: ResourceInfo;
@@ -84,17 +85,26 @@ const downloadFileWithProgress = async (
8485
const getServerInfo = async (): Promise<ResourceInfo | null> => {
8586
const osplatform = os.platform();
8687
const osmachine = os.machine();
88+
let spec: Spec | null = null;
89+
try {
90+
const response = await fetch(
91+
"https://pub-ad9e0b7360bc4259878d0f81b89c5405.r2.dev/spec.json"
92+
);
8793

88-
const response = await fetch(
89-
"https://pub-ad9e0b7360bc4259878d0f81b89c5405.r2.dev/spec.json"
90-
);
94+
if (!response.ok) {
95+
return null;
96+
}
9197

92-
if (!response.ok) {
98+
spec = (await response.json()) as Spec;
99+
await state.global.update("serverSpec", spec);
100+
} catch (error) {
101+
spec = state.global.get("serverSpec");
102+
Logger.warn(`Can not get server spec`);
103+
}
104+
if (spec === null) {
93105
return null;
94106
}
95107

96-
const spec = (await response.json()) as Spec;
97-
98108
if (osplatform === "win32") {
99109
if (osmachine === "x86_64") {
100110
const useGPUNvidia = configuration.get(

src/common/utils/state.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import * as vscode from "vscode";
2+
import type { Spec } from "../download";
23

34
const StateValues = {
45
inlineSuggestModeAuto: {
56
default: true,
67
},
8+
serverSpec: {
9+
default: null,
10+
},
711
};
812

913
interface StateValuesType extends Record<keyof typeof StateValues, any> {
1014
inlineSuggestModeAuto: {
1115
possibleValues: boolean;
1216
};
17+
serverSpec: {
18+
possibleValues: Spec | null;
19+
};
1320
}
1421
class State {
1522
state?: vscode.Memento;

0 commit comments

Comments
 (0)