Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite97e687

Browse files
committed
Create CodeApi and separate the API methods
1 parentf78f262 commite97e687

16 files changed

+512
-530
lines changed

‎src/agentMetadataHelper.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
AgentMetadataEvent,
55
AgentMetadataEventSchemaArray,
66
errToStr,
7-
}from"./api-helper";
8-
import{CoderWebSocketClient}from"./websocket/webSocketClient";
7+
}from"./api/api-helper";
8+
import{CodeApi}from"./api/codeApi";
99

1010
exporttypeAgentMetadataWatcher={
1111
onChange:vscode.EventEmitter<null>["event"];
@@ -20,9 +20,9 @@ export type AgentMetadataWatcher = {
2020
*/
2121
exportfunctioncreateAgentMetadataWatcher(
2222
agentId:WorkspaceAgent["id"],
23-
webSocketClient:CoderWebSocketClient,
23+
client:CodeApi,
2424
):AgentMetadataWatcher{
25-
constsocket=webSocketClient.watchAgentMetadata(agentId);
25+
constsocket=client.watchAgentMetadata(agentId);
2626

2727
letdisposed=false;
2828
constonChange=newvscode.EventEmitter<null>();

‎src/api.ts‎

Lines changed: 0 additions & 285 deletions
This file was deleted.

‎src/api-helper.ts‎renamed to ‎src/api/api-helper.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import {
77
import{ErrorEvent}from"eventsource";
88
import{z}from"zod";
99

10+
/**
11+
* Convert various error types to readable strings
12+
*/
1013
exportfunctionerrToStr(
1114
error:unknown,
1215
def:string="No error message provided",
@@ -27,6 +30,13 @@ export function errToStr(
2730
returndef;
2831
}
2932

33+
/**
34+
* Create workspace owner/name identifier
35+
*/
36+
exportfunctioncreateWorkspaceIdentifier(workspace:Workspace):string{
37+
return`${workspace.owner_name}/${workspace.name}`;
38+
}
39+
3040
exportfunctionextractAllAgents(
3141
workspaces:readonlyWorkspace[],
3242
):WorkspaceAgent[]{

‎src/api/auth.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
importfsfrom"fs";
2+
import{ProxyAgent}from"proxy-agent";
3+
import{typeWorkspaceConfiguration}from"vscode";
4+
import{getProxyForUrl}from"../proxy";
5+
import{expandPath}from"../util";
6+
7+
/**
8+
* Return whether the API will need a token for authorization.
9+
* If mTLS is in use (as specified by the cert or key files being set) then
10+
* token authorization is disabled. Otherwise, it is enabled.
11+
*/
12+
exportfunctionneedToken(cfg:WorkspaceConfiguration):boolean{
13+
constcertFile=expandPath(
14+
String(cfg.get("coder.tlsCertFile")??"").trim(),
15+
);
16+
constkeyFile=expandPath(String(cfg.get("coder.tlsKeyFile")??"").trim());
17+
return!certFile&&!keyFile;
18+
}
19+
20+
/**
21+
* Create a new HTTP agent based on the current VS Code settings.
22+
* Configures proxy, TLS certificates, and security options.
23+
*/
24+
exportfunctioncreateHttpAgent(cfg:WorkspaceConfiguration):ProxyAgent{
25+
constinsecure=Boolean(cfg.get("coder.insecure"));
26+
constcertFile=expandPath(
27+
String(cfg.get("coder.tlsCertFile")??"").trim(),
28+
);
29+
constkeyFile=expandPath(String(cfg.get("coder.tlsKeyFile")??"").trim());
30+
constcaFile=expandPath(String(cfg.get("coder.tlsCaFile")??"").trim());
31+
constaltHost=expandPath(String(cfg.get("coder.tlsAltHost")??"").trim());
32+
33+
returnnewProxyAgent({
34+
// Called each time a request is made.
35+
getProxyForUrl:(url:string)=>{
36+
returngetProxyForUrl(
37+
url,
38+
cfg.get("http.proxy"),
39+
cfg.get("coder.proxyBypass"),
40+
);
41+
},
42+
cert:certFile==="" ?undefined :fs.readFileSync(certFile),
43+
key:keyFile==="" ?undefined :fs.readFileSync(keyFile),
44+
ca:caFile==="" ?undefined :fs.readFileSync(caFile),
45+
servername:altHost==="" ?undefined :altHost,
46+
// rejectUnauthorized defaults to true, so we need to explicitly set it to
47+
// false if we want to allow self-signed certificates.
48+
rejectUnauthorized:!insecure,
49+
});
50+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp