@@ -7,13 +7,33 @@ import * as tarFs from "tar-fs"
7
7
import * as zlib from "zlib"
8
8
import { HttpCode , HttpError } from "../../common/http"
9
9
import { rootPath } from "../constants"
10
- import { authenticated , replaceTemplates } from "../http"
10
+ import { authenticated , ensureAuthenticated , replaceTemplates } from "../http"
11
11
import { getMediaMime , pathToFsPath } from "../util"
12
12
13
13
export const router = Router ( )
14
14
15
15
// The commit is for caching.
16
16
router . get ( "/(:commit)(/*)?" , async ( req , res ) => {
17
+ // Used by VS Code to load extensions into the web worker.
18
+ const tar = Array . isArray ( req . query . tar ) ? req . query . tar [ 0 ] : req . query . tar
19
+ if ( typeof tar === "string" ) {
20
+ ensureAuthenticated ( req )
21
+ let stream : Readable = tarFs . pack ( pathToFsPath ( tar ) )
22
+ if ( req . headers [ "accept-encoding" ] && req . headers [ "accept-encoding" ] . includes ( "gzip" ) ) {
23
+ logger . debug ( "gzipping tar" , field ( "path" , tar ) )
24
+ const compress = zlib . createGzip ( )
25
+ stream . pipe ( compress )
26
+ stream . on ( "error" , ( error ) => compress . destroy ( error ) )
27
+ stream . on ( "close" , ( ) => compress . end ( ) )
28
+ stream = compress
29
+ res . header ( "content-encoding" , "gzip" )
30
+ }
31
+ res . set ( "Content-Type" , "application/x-tar" )
32
+ stream . on ( "close" , ( ) => res . end ( ) )
33
+ return stream . pipe ( res )
34
+ }
35
+
36
+ // If not a tar use the remainder of the path to load the resource.
17
37
if ( ! req . params [ 0 ] ) {
18
38
throw new HttpError ( "Not Found" , HttpCode . NotFound )
19
39
}
@@ -32,26 +52,6 @@ router.get("/(:commit)(/*)?", async (req, res) => {
32
52
res . header ( "Cache-Control" , "public, max-age=31536000" )
33
53
}
34
54
35
- /**
36
- * Used by VS Code to load extensions into the web worker.
37
- */
38
- const tar = Array . isArray ( req . query . tar ) ? req . query . tar [ 0 ] : req . query . tar
39
- if ( typeof tar === "string" ) {
40
- let stream : Readable = tarFs . pack ( pathToFsPath ( tar ) )
41
- if ( req . headers [ "accept-encoding" ] && req . headers [ "accept-encoding" ] . includes ( "gzip" ) ) {
42
- logger . debug ( "gzipping tar" , field ( "path" , resourcePath ) )
43
- const compress = zlib . createGzip ( )
44
- stream . pipe ( compress )
45
- stream . on ( "error" , ( error ) => compress . destroy ( error ) )
46
- stream . on ( "close" , ( ) => compress . end ( ) )
47
- stream = compress
48
- res . header ( "content-encoding" , "gzip" )
49
- }
50
- res . set ( "Content-Type" , "application/x-tar" )
51
- stream . on ( "close" , ( ) => res . end ( ) )
52
- return stream . pipe ( res )
53
- }
54
-
55
55
res . set ( "Content-Type" , getMediaMime ( resourcePath ) )
56
56
57
57
if ( resourcePath . endsWith ( "manifest.json" ) ) {
0 commit comments