cli: get update endpoint from build

This commit is contained in:
Connor Peet 2022-09-22 12:00:39 -07:00
parent 5b24e93b35
commit 54ca489a5b
No known key found for this signature in database
GPG key ID: CF8FD2EA0DBC61BD
4 changed files with 30 additions and 5 deletions

View file

@ -6,6 +6,7 @@
".build": true,
".profile-oss": true,
"**/.DS_Store": true,
"cli/target": true,
"build/**/*.js": {
"when": "$(basename).ts"
}
@ -86,6 +87,11 @@
"editor.defaultFormatter": "vscode.typescript-language-features",
"editor.formatOnSave": true
},
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true,
"editor.insertSpaces": true
},
"typescript.tsc.autoDetect": "off",
"testing.autoRun.mode": "rerun",
"conventionalCommits.scopes": [

View file

@ -24,6 +24,7 @@ pub const LAUNCHER_ASSET_NAME: Option<&'static str> =
pub const LAUNCHER_AI_KEY: Option<&'static str> = option_env!("LAUNCHER_AI_KEY");
pub const LAUNCHER_AI_ENDPOINT: Option<&'static str> = option_env!("LAUNCHER_AI_ENDPOINT");
pub const VSCODE_CLI_UPDATE_ENDPOINT: Option<&'static str> = option_env!("LAUNCHER_AI_ENDPOINT");
pub const TUNNEL_SERVICE_USER_AGENT_ENV_VAR: &str = "TUNNEL_SERVICE_USER_AGENT";

View file

@ -8,9 +8,12 @@ use std::path::Path;
use serde::Deserialize;
use crate::{
constants::VSCODE_CLI_UPDATE_ENDPOINT,
debug, log, options, spanf,
util::{
errors::{AnyError, StatusError, UnsupportedPlatformError, WrappedError},
errors::{
AnyError, StatusError, UnsupportedPlatformError, UpdatesNotConfigured, WrappedError,
},
io::ReportCopyProgress,
},
};
@ -54,11 +57,13 @@ impl UpdateService {
quality: options::Quality,
version: &str,
) -> Result<Release, AnyError> {
let update_endpoint = VSCODE_CLI_UPDATE_ENDPOINT.ok_or(UpdatesNotConfigured())?;
let download_segment = target
.download_segment(platform)
.ok_or(UnsupportedPlatformError())?;
let download_url = format!(
"https://update.code.visualstudio.com/api/versions/{}/{}/{}",
"{}/api/versions/{}/{}/{}",
update_endpoint,
version,
download_segment,
quality_download_segment(quality),
@ -92,11 +97,13 @@ impl UpdateService {
target: TargetKind,
quality: options::Quality,
) -> Result<Release, AnyError> {
let update_endpoint = VSCODE_CLI_UPDATE_ENDPOINT.ok_or(UpdatesNotConfigured())?;
let download_segment = target
.download_segment(platform)
.ok_or(UnsupportedPlatformError())?;
let download_url = format!(
"https://update.code.visualstudio.com/api/latest/{}/{}",
"{}/api/latest/{}/{}",
update_endpoint,
download_segment,
quality_download_segment(quality),
);
@ -127,13 +134,15 @@ impl UpdateService {
&self,
release: &Release,
) -> Result<reqwest::Response, AnyError> {
let update_endpoint = VSCODE_CLI_UPDATE_ENDPOINT.ok_or(UpdatesNotConfigured())?;
let download_segment = release
.target
.download_segment(release.platform)
.ok_or(UnsupportedPlatformError())?;
let download_url = format!(
"https://update.code.visualstudio.com/commit:{}/{}/{}",
"{}/commit:{}/{}/{}",
update_endpoint,
release.commit,
download_segment,
quality_download_segment(release.quality),

View file

@ -316,6 +316,14 @@ impl std::fmt::Display for ServerHasClosed {
}
}
#[derive(Debug)]
pub struct UpdatesNotConfigured();
impl std::fmt::Display for UpdatesNotConfigured {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Update service is not configured")
}
}
#[derive(Debug)]
pub struct ServiceAlreadyRegistered();
@ -408,7 +416,8 @@ makeAnyError!(
CannotForwardControlPort,
ServerHasClosed,
ServiceAlreadyRegistered,
WindowsNeedsElevation
WindowsNeedsElevation,
UpdatesNotConfigured
);
impl From<reqwest::Error> for AnyError {