mirror of
https://github.com/coder/code-server.git
synced 2026-05-07 04:51:59 +02:00
chore(vscode): update to 1.54.2
This commit is contained in:
@@ -9,6 +9,8 @@ import { isUNC } from 'vs/base/common/extpath';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { sep } from 'vs/base/common/path';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IHeaders } from 'vs/base/parts/request/common/request';
|
||||
import { FileOperationError, FileOperationResult, IFileService } from 'vs/platform/files/common/files';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { IRemoteConnectionData } from 'vs/platform/remote/common/remoteAuthorityResolver';
|
||||
import { IRequestService } from 'vs/platform/request/common/request';
|
||||
@@ -18,7 +20,7 @@ import { getWebviewContentMimeType } from 'vs/platform/webview/common/mimeTypes'
|
||||
export const webviewPartitionId = 'webview';
|
||||
|
||||
export namespace WebviewResourceResponse {
|
||||
export enum Type { Success, Failed, AccessDenied }
|
||||
export enum Type { Success, Failed, AccessDenied, NotModified }
|
||||
|
||||
export class StreamSuccess {
|
||||
readonly type = Type.Success;
|
||||
@@ -33,24 +35,77 @@ export namespace WebviewResourceResponse {
|
||||
export const Failed = { type: Type.Failed } as const;
|
||||
export const AccessDenied = { type: Type.AccessDenied } as const;
|
||||
|
||||
export type StreamResponse = StreamSuccess | typeof Failed | typeof AccessDenied;
|
||||
export class NotModified {
|
||||
readonly type = Type.NotModified;
|
||||
|
||||
constructor(
|
||||
public readonly mimeType: string,
|
||||
) { }
|
||||
}
|
||||
|
||||
export type StreamResponse = StreamSuccess | typeof Failed | typeof AccessDenied | NotModified;
|
||||
}
|
||||
|
||||
interface FileReader {
|
||||
readFileStream(resource: URI): Promise<{ stream: VSBufferReadableStream, etag?: string }>;
|
||||
export namespace WebviewFileReadResponse {
|
||||
export enum Type { Success, NotModified }
|
||||
|
||||
export class StreamSuccess {
|
||||
readonly type = Type.Success;
|
||||
|
||||
constructor(
|
||||
public readonly stream: VSBufferReadableStream,
|
||||
public readonly etag: string | undefined
|
||||
) { }
|
||||
}
|
||||
|
||||
export const NotModified = { type: Type.NotModified } as const;
|
||||
|
||||
export type Response = StreamSuccess | typeof NotModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a call to `IFileService.readFileStream` and converts the result to a `WebviewFileReadResponse.Response`
|
||||
*/
|
||||
export async function readFileStream(
|
||||
fileService: IFileService,
|
||||
resource: URI,
|
||||
etag: string | undefined,
|
||||
): Promise<WebviewFileReadResponse.Response> {
|
||||
try {
|
||||
const result = await fileService.readFileStream(resource, { etag });
|
||||
return new WebviewFileReadResponse.StreamSuccess(result.value, result.etag);
|
||||
} catch (e) {
|
||||
if (e instanceof FileOperationError) {
|
||||
const result = e.fileOperationResult;
|
||||
|
||||
// NotModified status is expected and can be handled gracefully
|
||||
if (result === FileOperationResult.FILE_NOT_MODIFIED_SINCE) {
|
||||
return WebviewFileReadResponse.NotModified;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise the error is unexpected. Re-throw and let caller handle it
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export interface WebviewResourceFileReader {
|
||||
readFileStream(resource: URI, etag: string | undefined): Promise<WebviewFileReadResponse.Response>;
|
||||
}
|
||||
|
||||
export async function loadLocalResource(
|
||||
requestUri: URI,
|
||||
ifNoneMatch: string | undefined,
|
||||
options: {
|
||||
extensionLocation: URI | undefined;
|
||||
roots: ReadonlyArray<URI>;
|
||||
remoteConnectionData?: IRemoteConnectionData | null;
|
||||
rewriteUri?: (uri: URI) => URI,
|
||||
},
|
||||
fileReader: FileReader,
|
||||
fileReader: WebviewResourceFileReader,
|
||||
requestService: IRequestService,
|
||||
logService: ILogService,
|
||||
token: CancellationToken,
|
||||
): Promise<WebviewResourceResponse.StreamResponse> {
|
||||
logService.debug(`loadLocalResource - being. requestUri=${requestUri}`);
|
||||
|
||||
@@ -70,20 +125,45 @@ export async function loadLocalResource(
|
||||
}
|
||||
|
||||
if (resourceToLoad.scheme === Schemas.http || resourceToLoad.scheme === Schemas.https) {
|
||||
const response = await requestService.request({ url: resourceToLoad.toString(true) }, CancellationToken.None);
|
||||
const headers: IHeaders = {};
|
||||
if (ifNoneMatch) {
|
||||
headers['If-None-Match'] = ifNoneMatch;
|
||||
}
|
||||
|
||||
const response = await requestService.request({
|
||||
url: resourceToLoad.toString(true),
|
||||
headers: headers
|
||||
}, token);
|
||||
|
||||
logService.debug(`loadLocalResource - Loaded over http(s). requestUri=${requestUri}, response=${response.res.statusCode}`);
|
||||
|
||||
if (response.res.statusCode === 200) {
|
||||
return new WebviewResourceResponse.StreamSuccess(response.stream, undefined, mime);
|
||||
switch (response.res.statusCode) {
|
||||
case 200:
|
||||
return new WebviewResourceResponse.StreamSuccess(response.stream, response.res.headers['etag'], mime);
|
||||
|
||||
case 304: // Not modified
|
||||
return new WebviewResourceResponse.NotModified(mime);
|
||||
|
||||
default:
|
||||
return WebviewResourceResponse.Failed;
|
||||
}
|
||||
return WebviewResourceResponse.Failed;
|
||||
}
|
||||
|
||||
try {
|
||||
const contents = await fileReader.readFileStream(resourceToLoad);
|
||||
const contents = await fileReader.readFileStream(resourceToLoad, ifNoneMatch);
|
||||
logService.debug(`loadLocalResource - Loaded using fileReader. requestUri=${requestUri}`);
|
||||
|
||||
return new WebviewResourceResponse.StreamSuccess(contents.stream, contents.etag, mime);
|
||||
switch (contents.type) {
|
||||
case WebviewFileReadResponse.Type.Success:
|
||||
return new WebviewResourceResponse.StreamSuccess(contents.stream, contents.etag, mime);
|
||||
|
||||
case WebviewFileReadResponse.Type.NotModified:
|
||||
return new WebviewResourceResponse.NotModified(mime);
|
||||
|
||||
default:
|
||||
logService.error(`loadLocalResource - Unknown file read response`);
|
||||
return WebviewResourceResponse.Failed;
|
||||
}
|
||||
} catch (err) {
|
||||
logService.debug(`loadLocalResource - Error using fileReader. requestUri=${requestUri}`);
|
||||
console.log(err);
|
||||
|
||||
@@ -19,6 +19,16 @@ export interface WebviewWindowId {
|
||||
readonly windowId: number;
|
||||
}
|
||||
|
||||
export type WebviewManagerDidLoadResourceResponse =
|
||||
VSBuffer
|
||||
| 'not-modified'
|
||||
| 'access-denied'
|
||||
| 'not-found';
|
||||
|
||||
export interface WebviewManagerDidLoadResourceResponseDetails {
|
||||
readonly etag?: string;
|
||||
}
|
||||
|
||||
export interface IWebviewManagerService {
|
||||
_serviceBrand: unknown;
|
||||
|
||||
@@ -26,7 +36,8 @@ export interface IWebviewManagerService {
|
||||
unregisterWebview(id: string): Promise<void>;
|
||||
updateWebviewMetadata(id: string, metadataDelta: Partial<RegisterWebviewMetadata>): Promise<void>;
|
||||
|
||||
didLoadResource(requestId: number, content: VSBuffer | undefined): void;
|
||||
/** Note: the VSBuffer must be a top level argument so that it can be serialized and deserialized properly */
|
||||
didLoadResource(requestId: number, response: WebviewManagerDidLoadResourceResponse, responseDetails?: WebviewManagerDidLoadResourceResponseDetails): void;
|
||||
|
||||
setIgnoreMenuShortcuts(id: WebviewWebContentsId | WebviewWindowId, enabled: boolean): Promise<void>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user