@opensumi/ide-express-file-server 2.21.14-rc-1673439983.0 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/file-server.contribution.js.map +1 -1
- package/lib/browser/index.js.map +1 -1
- package/lib/node/express-file-server.contribution.js.map +1 -1
- package/lib/node/index.js.map +1 -1
- package/package.json +10 -9
- package/src/browser/file-server.contribution.ts +32 -0
- package/src/browser/index.ts +9 -0
- package/src/common/index.ts +20 -0
- package/src/index.ts +1 -0
- package/src/node/express-file-server.contribution.ts +59 -0
- package/src/node/index.ts +9 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-server.contribution.js","sourceRoot":"","sources":["../../src/browser/file-server.contribution.ts"],"names":[],"mappings":";;;;AAAA,qCAAyC;AACzC,iEAA6E;AAC7E,mGAGqE;AAErE,sCAAgD;
|
|
1
|
+
{"version":3,"file":"file-server.contribution.js","sourceRoot":"","sources":["../../src/browser/file-server.contribution.ts"],"names":[],"mappings":";;;;AAAA,qCAAyC;AACzC,iEAA6E;AAC7E,mGAGqE;AAErE,sCAAgD;AAGzC,IAAM,6BAA6B,GAAnC,MAAM,6BAA6B;IAIxC,sBAAsB,CAAC,OAA8B;QACnD,OAAO,CAAC,8BAA8B,CAAC;YACrC,MAAM,EAAE,0BAAO,CAAC,IAAI;YACpB,qBAAqB,EAAE,CAAC,GAAQ,EAAE,EAAE;gBAClC,iBAAiB;gBACjB,qCAAqC;gBACrC,MAAM,SAAS,GAAG,IAAI,sBAAG,CAAC,IAAI,CAAC,SAAS,CAAC,iBAAiB,IAAI,4BAAmB,CAAC,CAAC;gBACnF;;;mBAGG;gBACH,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACzD,OAAO,SAAS,CAAC,OAAO,CAAC,SAAS,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YACxF,CAAC;YACD,KAAK,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,iBAAiB,IAAI,4BAAmB,CAAC;SACjE,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AApBC;IAAC,IAAA,cAAS,EAAC,4BAAS,CAAC;;gEACA;AAFV,6BAA6B;IADzC,IAAA,yBAAM,EAAC,8CAA0B,CAAC;GACtB,6BAA6B,CAqBzC;AArBY,sEAA6B"}
|
package/lib/browser/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAoD;AACpD,iEAA2D;AAE3D,yEAA2E;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAoD;AACpD,iEAA2D;AAE3D,yEAA2E;AAGpE,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,gCAAa;IAAnD;;QACL,cAAS,GAAe,CAAC,wDAA6B,CAAC,CAAC;IAC1D,CAAC;CAAA,CAAA;AAFY,uBAAuB;IADnC,IAAA,eAAU,GAAE;GACA,uBAAuB,CAEnC;AAFY,0DAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express-file-server.contribution.js","sourceRoot":"","sources":["../../src/node/express-file-server.contribution.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AACpB,wDAAwB;AAExB,kEAA8B;AAE9B,qCAAyC;AACzC,2DAAoG;AAEpG,sCAAuC;
|
|
1
|
+
{"version":3,"file":"express-file-server.contribution.js","sourceRoot":"","sources":["../../src/node/express-file-server.contribution.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AACpB,wDAAwB;AAExB,kEAA8B;AAE9B,qCAAyC;AACzC,2DAAoG;AAEpG,sCAAuC;AAGhC,IAAM,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AAG,YAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;aAC1C;iBAAM;gBACL,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;aAClB;QACH,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF,CAAA;AA9CC;IAAC,IAAA,cAAS,EAAC,yBAAS,CAAC;;gEACQ;AAFlB,6BAA6B;IADzC,IAAA,sBAAM,EAAC,qCAAqB,CAAC;GACjB,6BAA6B,CA+CzC;AA/CY,sEAA6B"}
|
package/lib/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAoD;AACpD,2DAAqD;AAErD,yFAAmF;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAoD;AACpD,2DAAqD;AAErD,yFAAmF;AAG5E,IAAM,uBAAuB,GAA7B,MAAM,uBAAwB,SAAQ,0BAAU;IAAhD;;QACL,cAAS,GAAe,CAAC,gEAA6B,CAAC,CAAC;IAC1D,CAAC;CAAA,CAAA;AAFY,uBAAuB;IADnC,IAAA,eAAU,GAAE;GACA,uBAAuB,CAEnC;AAFY,0DAAuB"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-express-file-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"files": [
|
|
5
|
-
"lib"
|
|
5
|
+
"lib",
|
|
6
|
+
"src"
|
|
6
7
|
],
|
|
7
8
|
"license": "MIT",
|
|
8
9
|
"main": "lib/index.js",
|
|
9
10
|
"typings": "lib/index.d.ts",
|
|
10
11
|
"scripts": {
|
|
11
|
-
"prepublishOnly": "
|
|
12
|
+
"prepublishOnly": "yarn run build",
|
|
12
13
|
"build": "tsc --build ../../configs/ts/references/tsconfig.express-file-server.json"
|
|
13
14
|
},
|
|
14
15
|
"repository": {
|
|
@@ -16,16 +17,16 @@
|
|
|
16
17
|
"url": "git@github.com:opensumi/core.git"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@opensumi/ide-core-common": "2.
|
|
20
|
-
"@opensumi/ide-core-node": "2.
|
|
21
|
-
"@opensumi/ide-static-resource": "2.
|
|
20
|
+
"@opensumi/ide-core-common": "2.22.0",
|
|
21
|
+
"@opensumi/ide-core-node": "2.22.0",
|
|
22
|
+
"@opensumi/ide-static-resource": "2.22.0",
|
|
22
23
|
"koa-mount": "^4.0.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@opensumi/ide-core-browser": "2.
|
|
26
|
-
"@opensumi/ide-dev-tool": "
|
|
26
|
+
"@opensumi/ide-core-browser": "2.22.0",
|
|
27
|
+
"@opensumi/ide-dev-tool": "1.3.1",
|
|
27
28
|
"@types/koa-mount": "^4.0.1",
|
|
28
29
|
"superagent": "^5.1.0"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "927717e1c60f9cf5f01622fd51085b318a175eeb"
|
|
31
32
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Autowired } from '@opensumi/di';
|
|
2
|
+
import { Domain, URI, AppConfig, Schemes } from '@opensumi/ide-core-browser';
|
|
3
|
+
import {
|
|
4
|
+
StaticResourceContribution,
|
|
5
|
+
StaticResourceService,
|
|
6
|
+
} from '@opensumi/ide-static-resource/lib/browser/static.definition';
|
|
7
|
+
|
|
8
|
+
import { EXPRESS_SERVER_PATH } from '../common';
|
|
9
|
+
|
|
10
|
+
@Domain(StaticResourceContribution)
|
|
11
|
+
export class ExpressFileServerContribution implements StaticResourceContribution {
|
|
12
|
+
@Autowired(AppConfig)
|
|
13
|
+
appConfig: AppConfig;
|
|
14
|
+
|
|
15
|
+
registerStaticResolver(service: StaticResourceService): void {
|
|
16
|
+
service.registerStaticResourceProvider({
|
|
17
|
+
scheme: Schemes.file,
|
|
18
|
+
resolveStaticResource: (uri: URI) => {
|
|
19
|
+
// file 协议统一走静态服务
|
|
20
|
+
// http://${HOST}:8000/assets/${path}
|
|
21
|
+
const assetsUri = new URI(this.appConfig.staticServicePath || EXPRESS_SERVER_PATH);
|
|
22
|
+
/**
|
|
23
|
+
* uri.path 在 Windows 下会被解析为 /c:/Path/to/file
|
|
24
|
+
* fsPath C:\\Path\\to\\file
|
|
25
|
+
*/
|
|
26
|
+
const [resourceUrl, query] = uri.codeUri.path.split('?');
|
|
27
|
+
return assetsUri.resolve(`assets${decodeURIComponent(resourceUrl)}`).withQuery(query);
|
|
28
|
+
},
|
|
29
|
+
roots: [this.appConfig.staticServicePath || EXPRESS_SERVER_PATH],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Provider, Injectable } from '@opensumi/di';
|
|
2
|
+
import { BrowserModule } from '@opensumi/ide-core-browser';
|
|
3
|
+
|
|
4
|
+
import { ExpressFileServerContribution } from './file-server.contribution';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class ExpressFileServerModule extends BrowserModule {
|
|
8
|
+
providers: Provider[] = [ExpressFileServerContribution];
|
|
9
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const EXPRESS_SERVER_PORT = 8000;
|
|
2
|
+
export const EXPRESS_SERVER_PATH = process.env.STATIC_SERVER_PATH || `http://127.0.0.1:${EXPRESS_SERVER_PORT}/`;
|
|
3
|
+
// 静态服务资源白名单
|
|
4
|
+
export const ALLOW_MIME = {
|
|
5
|
+
gif: 'image/gif',
|
|
6
|
+
jpg: 'image/jpeg',
|
|
7
|
+
png: 'image/png',
|
|
8
|
+
webp: 'image/webp',
|
|
9
|
+
svg: 'image/svg+xml',
|
|
10
|
+
ttf: 'font/ttf',
|
|
11
|
+
eot: 'font/eot',
|
|
12
|
+
otf: 'font/otf',
|
|
13
|
+
woff: 'font/woff',
|
|
14
|
+
woff2: 'font/woff2',
|
|
15
|
+
js: 'application/javascript',
|
|
16
|
+
css: 'text/css',
|
|
17
|
+
mp4: 'video/mp4',
|
|
18
|
+
ogg: 'video/ogg',
|
|
19
|
+
webm: 'video/webm',
|
|
20
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './common';
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import mount from 'koa-mount';
|
|
5
|
+
|
|
6
|
+
import { Autowired } from '@opensumi/di';
|
|
7
|
+
import { ServerAppContribution, Domain, IServerApp, AppConfig, URI } from '@opensumi/ide-core-node';
|
|
8
|
+
|
|
9
|
+
import { ALLOW_MIME } from '../common';
|
|
10
|
+
|
|
11
|
+
@Domain(ServerAppContribution)
|
|
12
|
+
export class ExpressFileServerContribution implements ServerAppContribution {
|
|
13
|
+
@Autowired(AppConfig)
|
|
14
|
+
private appConfig: AppConfig;
|
|
15
|
+
|
|
16
|
+
getWhiteList() {
|
|
17
|
+
return [
|
|
18
|
+
// 插件市场安装目录
|
|
19
|
+
this.appConfig.marketplace.extensionDir,
|
|
20
|
+
...(this.appConfig.staticAllowPath || []),
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
initialize(app: IServerApp) {
|
|
25
|
+
app.use(
|
|
26
|
+
mount('/assets', async (ctx) => {
|
|
27
|
+
const uriPath = decodeURI(ctx.path.replace(/^\/assets/, ''));
|
|
28
|
+
if (!uriPath) {
|
|
29
|
+
ctx.status = 404;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const filePath = URI.parse(`file://${uriPath}`).codeUri.fsPath;
|
|
34
|
+
const whitelist = this.getWhiteList();
|
|
35
|
+
const contentType = ALLOW_MIME[path.extname(filePath).slice(1)];
|
|
36
|
+
if (
|
|
37
|
+
/**
|
|
38
|
+
* 地址在白名单内
|
|
39
|
+
* Windows 下 C:\\Path\\to\\file 会被转换成 c:\\Path\\to\\file
|
|
40
|
+
*/
|
|
41
|
+
whitelist.some(
|
|
42
|
+
(whitelistPath) => whitelistPath && filePath.toLowerCase().startsWith(whitelistPath.toLowerCase()),
|
|
43
|
+
) &&
|
|
44
|
+
// 在允许的 contentType
|
|
45
|
+
contentType
|
|
46
|
+
) {
|
|
47
|
+
ctx.set('Content-Type', contentType);
|
|
48
|
+
if (this.appConfig.staticAllowOrigin) {
|
|
49
|
+
ctx.set('Access-Control-Allow-Origin', this.appConfig.staticAllowOrigin);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
ctx.body = fs.createReadStream(filePath);
|
|
53
|
+
} else {
|
|
54
|
+
ctx.status = 403;
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Provider, Injectable } from '@opensumi/di';
|
|
2
|
+
import { NodeModule } from '@opensumi/ide-core-node';
|
|
3
|
+
|
|
4
|
+
import { ExpressFileServerContribution } from './express-file-server.contribution';
|
|
5
|
+
|
|
6
|
+
@Injectable()
|
|
7
|
+
export class ExpressFileServerModule extends NodeModule {
|
|
8
|
+
providers: Provider[] = [ExpressFileServerContribution];
|
|
9
|
+
}
|