UNPKG

@pkerschbaum/code-oss-file-service

Version:

VS Code ([microsoft/vscode](https://github.com/microsoft/vscode)) includes a rich "`FileService`" and "`DiskFileSystemProvider`" abstraction built on top of Node.js core modules (`fs`, `path`) and Electron's `shell` module. This package allows to use that

178 lines 7.03 kB
"use strict"; /*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); exports.FileAccess = exports.RemoteAuthorities = exports.Schemas = void 0; const platform = require("../../base/common/platform"); const uri_1 = require("../../base/common/uri"); var Schemas; (function (Schemas) { /** * A schema that is used for models that exist in memory * only and that have no correspondence on a server or such. */ Schemas.inMemory = 'inmemory'; /** * A schema that is used for setting files */ Schemas.vscode = 'vscode'; /** * A schema that is used for internal private files */ Schemas.internal = 'private'; /** * A walk-through document. */ Schemas.walkThrough = 'walkThrough'; /** * An embedded code snippet. */ Schemas.walkThroughSnippet = 'walkThroughSnippet'; Schemas.http = 'http'; Schemas.https = 'https'; Schemas.file = 'file'; Schemas.mailto = 'mailto'; Schemas.untitled = 'untitled'; Schemas.data = 'data'; Schemas.command = 'command'; Schemas.vscodeRemote = 'vscode-remote'; Schemas.vscodeRemoteResource = 'vscode-remote-resource'; Schemas.userData = 'vscode-userdata'; Schemas.vscodeCustomEditor = 'vscode-custom-editor'; Schemas.vscodeNotebook = 'vscode-notebook'; Schemas.vscodeNotebookCell = 'vscode-notebook-cell'; Schemas.vscodeNotebookCellMetadata = 'vscode-notebook-cell-metadata'; Schemas.vscodeNotebookCellOutput = 'vscode-notebook-cell-output'; Schemas.vscodeInteractive = 'vscode-interactive'; Schemas.vscodeInteractiveInput = 'vscode-interactive-input'; Schemas.vscodeSettings = 'vscode-settings'; Schemas.vscodeWorkspaceTrust = 'vscode-workspace-trust'; Schemas.vscodeTerminal = 'vscode-terminal'; /** * Scheme used internally for webviews that aren't linked to a resource (i.e. not custom editors) */ Schemas.webviewPanel = 'webview-panel'; /** * Scheme used for loading the wrapper html and script in webviews. */ Schemas.vscodeWebview = 'vscode-webview'; /** * Scheme used for extension pages */ Schemas.extension = 'extension'; /** * Scheme used as a replacement of `file` scheme to load * files with our custom protocol handler (desktop only). */ Schemas.vscodeFileResource = 'vscode-file'; /** * Scheme used for temporary resources */ Schemas.tmp = 'tmp'; /** * Scheme used vs live share */ Schemas.vsls = 'vsls'; })(Schemas = exports.Schemas || (exports.Schemas = {})); class RemoteAuthoritiesImpl { constructor() { this._hosts = Object.create(null); this._ports = Object.create(null); this._connectionTokens = Object.create(null); this._preferredWebSchema = 'http'; this._delegate = null; } setPreferredWebSchema(schema) { this._preferredWebSchema = schema; } setDelegate(delegate) { this._delegate = delegate; } set(authority, host, port) { this._hosts[authority] = host; this._ports[authority] = port; } setConnectionToken(authority, connectionToken) { this._connectionTokens[authority] = connectionToken; } rewrite(uri) { if (this._delegate) { return this._delegate(uri); } const authority = uri.authority; let host = this._hosts[authority]; if (host && host.indexOf(':') !== -1) { host = `[${host}]`; } const port = this._ports[authority]; const connectionToken = this._connectionTokens[authority]; let query = `path=${encodeURIComponent(uri.path)}`; if (typeof connectionToken === 'string') { query += `&tkn=${encodeURIComponent(connectionToken)}`; } return uri_1.URI.from({ scheme: platform.isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource, authority: `${host}:${port}`, path: `/vscode-remote-resource`, query }); } } exports.RemoteAuthorities = new RemoteAuthoritiesImpl(); class FileAccessImpl { asBrowserUri(uriOrModule, moduleIdToUrl) { const uri = this.toUri(uriOrModule, moduleIdToUrl); // Handle remote URIs via `RemoteAuthorities` if (uri.scheme === Schemas.vscodeRemote) { return exports.RemoteAuthorities.rewrite(uri); } // Convert to `vscode-file` resource.. if ( // ...only ever for `file` resources uri.scheme === Schemas.file && ( // ...and we run in native environments platform.isNative || // ...or web worker extensions on desktop (typeof platform.globals.importScripts === 'function' && platform.globals.origin === `${Schemas.vscodeFileResource}://${FileAccessImpl.FALLBACK_AUTHORITY}`))) { return uri.with({ scheme: Schemas.vscodeFileResource, // We need to provide an authority here so that it can serve // as origin for network and loading matters in chromium. // If the URI is not coming with an authority already, we // add our own authority: uri.authority || FileAccessImpl.FALLBACK_AUTHORITY, query: null, fragment: null }); } return uri; } asFileUri(uriOrModule, moduleIdToUrl) { const uri = this.toUri(uriOrModule, moduleIdToUrl); // Only convert the URI if it is `vscode-file:` scheme if (uri.scheme === Schemas.vscodeFileResource) { return uri.with({ scheme: Schemas.file, // Only preserve the `authority` if it is different from // our fallback authority. This ensures we properly preserve // Windows UNC paths that come with their own authority. authority: uri.authority !== FileAccessImpl.FALLBACK_AUTHORITY ? uri.authority : null, query: null, fragment: null }); } return uri; } toUri(uriOrModule, moduleIdToUrl) { if (uri_1.URI.isUri(uriOrModule)) { return uriOrModule; } return uri_1.URI.parse(moduleIdToUrl.toUrl(uriOrModule)); } } FileAccessImpl.FALLBACK_AUTHORITY = 'vscode-app'; exports.FileAccess = new FileAccessImpl(); //# sourceMappingURL=network.js.map