@opensumi/ide-express-file-server 2.21.7-rc-1670246007.0 → 2.21.7
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/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-express-file-server",
|
|
3
|
-
"version": "2.21.7
|
|
3
|
+
"version": "2.21.7",
|
|
4
4
|
"files": [
|
|
5
|
-
"lib"
|
|
6
|
-
"src"
|
|
5
|
+
"lib"
|
|
7
6
|
],
|
|
8
7
|
"license": "MIT",
|
|
9
8
|
"main": "lib/index.js",
|
|
@@ -17,16 +16,16 @@
|
|
|
17
16
|
"url": "git@github.com:opensumi/core.git"
|
|
18
17
|
},
|
|
19
18
|
"dependencies": {
|
|
20
|
-
"@opensumi/ide-core-common": "2.21.7
|
|
21
|
-
"@opensumi/ide-core-node": "2.21.7
|
|
22
|
-
"@opensumi/ide-static-resource": "2.21.7
|
|
19
|
+
"@opensumi/ide-core-common": "2.21.7",
|
|
20
|
+
"@opensumi/ide-core-node": "2.21.7",
|
|
21
|
+
"@opensumi/ide-static-resource": "2.21.7",
|
|
23
22
|
"koa-mount": "^4.0.0"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
|
-
"@opensumi/ide-core-browser": "2.21.7
|
|
25
|
+
"@opensumi/ide-core-browser": "2.21.7",
|
|
27
26
|
"@opensumi/ide-dev-tool": "^1.3.1",
|
|
28
27
|
"@types/koa-mount": "^4.0.1",
|
|
29
28
|
"superagent": "^5.1.0"
|
|
30
29
|
},
|
|
31
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "e62bfa7480f5e6c387183797c11171e30727103e"
|
|
32
31
|
}
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|
package/src/browser/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|
package/src/common/index.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './common';
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
}
|
package/src/node/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|