Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
27aebd40
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
27aebd40
编写于
7月 15, 2019
作者:
S
Sandeep Somavarapu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use fileservice for read/write marketplace machineid
上级
f3c88424
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
25 deletion
+50
-25
src/vs/code/electron-main/window.ts
src/vs/code/electron-main/window.ts
+3
-1
src/vs/platform/extensionManagement/node/extensionGalleryService.ts
...tform/extensionManagement/node/extensionGalleryService.ts
+28
-22
src/vs/platform/extensionManagement/test/node/extensionGalleryService.test.ts
...nsionManagement/test/node/extensionGalleryService.test.ts
+19
-2
未找到文件。
src/vs/code/electron-main/window.ts
浏览文件 @
27aebd40
...
...
@@ -25,6 +25,7 @@ import { resolveMarketplaceHeaders } from 'vs/platform/extensionManagement/node/
import
{
IThemeMainService
}
from
'
vs/platform/theme/electron-main/themeMainService
'
;
import
{
endsWith
}
from
'
vs/base/common/strings
'
;
import
{
RunOnceScheduler
}
from
'
vs/base/common/async
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
const
RUN_TEXTMATE_IN_WORKER
=
false
;
...
...
@@ -76,6 +77,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
config
:
IWindowCreationOptions
,
@
ILogService
private
readonly
logService
:
ILogService
,
@
IEnvironmentService
private
readonly
environmentService
:
IEnvironmentService
,
@
IFileService
private
readonly
fileService
:
IFileService
,
@
IConfigurationService
private
readonly
configurationService
:
IConfigurationService
,
@
IThemeMainService
private
readonly
themeMainService
:
IThemeMainService
,
@
IWorkspacesMainService
private
readonly
workspacesMainService
:
IWorkspacesMainService
,
...
...
@@ -307,7 +309,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
private
handleMarketplaceRequests
():
void
{
// Resolve marketplace headers
this
.
marketplaceHeadersPromise
=
resolveMarketplaceHeaders
(
this
.
environmentService
);
this
.
marketplaceHeadersPromise
=
resolveMarketplaceHeaders
(
this
.
environmentService
,
this
.
fileService
);
// Inject headers when requests are incoming
const
urls
=
[
'
https://marketplace.visualstudio.com/*
'
,
'
https://*.vsassets.io/*
'
];
...
...
src/vs/platform/extensionManagement/node/extensionGalleryService.ts
浏览文件 @
27aebd40
...
...
@@ -15,7 +15,6 @@ import pkg from 'vs/platform/product/node/package';
import
product
from
'
vs/platform/product/node/product
'
;
import
{
isEngineValid
}
from
'
vs/platform/extensions/node/extensionValidator
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
writeFileSync
,
readFile
}
from
'
vs/base/node/pfs
'
;
import
{
generateUuid
,
isUUID
}
from
'
vs/base/common/uuid
'
;
import
{
values
}
from
'
vs/base/common/map
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
...
...
@@ -24,6 +23,7 @@ import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
URI
}
from
'
vs/base/common/uri
'
;
import
{
joinPath
}
from
'
vs/base/common/resources
'
;
import
{
VSBuffer
}
from
'
vs/base/common/buffer
'
;
interface
IRawGalleryExtensionFile
{
assetType
:
string
;
...
...
@@ -343,7 +343,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
const
config
=
product
.
extensionsGallery
;
this
.
extensionsGalleryUrl
=
config
&&
config
.
serviceUrl
;
this
.
extensionsControlUrl
=
config
&&
config
.
controlUrl
;
this
.
commonHeadersPromise
=
resolveMarketplaceHeaders
(
this
.
environmentService
);
this
.
commonHeadersPromise
=
resolveMarketplaceHeaders
(
this
.
environmentService
,
this
.
fileService
);
}
private
api
(
path
=
''
):
string
{
...
...
@@ -774,24 +774,30 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
}
}
export
function
resolveMarketplaceHeaders
(
environmentService
:
IEnvironmentService
):
Promise
<
{
[
key
:
string
]:
string
;
}
>
{
const
marketplaceMachineIdFile
=
path
.
join
(
environmentService
.
userDataPath
,
'
machineid
'
);
return
readFile
(
marketplaceMachineIdFile
,
'
utf8
'
)
.
then
<
string
|
null
>
(
contents
=>
isUUID
(
contents
)
?
contents
:
null
,
()
=>
null
/* error reading ID file */
)
.
then
(
uuid
=>
{
if
(
!
uuid
)
{
uuid
=
generateUuid
();
try
{
writeFileSync
(
marketplaceMachineIdFile
,
uuid
);
}
catch
(
error
)
{
//noop
}
}
return
{
'
X-Market-Client-Id
'
:
`VSCode
${
pkg
.
version
}
`
,
'
User-Agent
'
:
`VSCode
${
pkg
.
version
}
`
,
'
X-Market-User-Id
'
:
uuid
};
});
export
async
function
resolveMarketplaceHeaders
(
environmentService
:
IEnvironmentService
,
fileService
:
IFileService
):
Promise
<
{
[
key
:
string
]:
string
;
}
>
{
const
marketplaceMachineIdFile
=
URI
.
file
(
path
.
join
(
environmentService
.
userDataPath
,
'
machineid
'
));
let
uuid
:
string
|
null
=
null
;
try
{
const
contents
=
await
fileService
.
readFile
(
marketplaceMachineIdFile
);
const
value
=
contents
.
value
.
toString
();
uuid
=
isUUID
(
value
)
?
value
:
null
;
}
catch
(
e
)
{
uuid
=
null
;
}
if
(
!
uuid
)
{
uuid
=
generateUuid
();
try
{
await
fileService
.
writeFile
(
marketplaceMachineIdFile
,
VSBuffer
.
fromString
(
uuid
));
}
catch
(
error
)
{
//noop
}
}
return
{
'
X-Market-Client-Id
'
:
`VSCode
${
pkg
.
version
}
`
,
'
User-Agent
'
:
`VSCode
${
pkg
.
version
}
`
,
'
X-Market-User-Id
'
:
uuid
};
}
\ No newline at end of file
src/vs/platform/extensionManagement/test/node/extensionGalleryService.test.ts
浏览文件 @
27aebd40
...
...
@@ -12,13 +12,29 @@ import { join } from 'vs/base/common/path';
import
{
mkdirp
,
RimRafMode
,
rimraf
}
from
'
vs/base/node/pfs
'
;
import
{
resolveMarketplaceHeaders
}
from
'
vs/platform/extensionManagement/node/extensionGalleryService
'
;
import
{
isUUID
}
from
'
vs/base/common/uuid
'
;
import
{
DisposableStore
}
from
'
vs/base/common/lifecycle
'
;
import
{
IFileService
}
from
'
vs/platform/files/common/files
'
;
import
{
FileService
}
from
'
vs/platform/files/common/fileService
'
;
import
{
NullLogService
}
from
'
vs/platform/log/common/log
'
;
import
{
DiskFileSystemProvider
}
from
'
vs/platform/files/node/diskFileSystemProvider
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
suite
(
'
Extension Gallery Service
'
,
()
=>
{
const
parentDir
=
getRandomTestPath
(
os
.
tmpdir
(),
'
vsctests
'
,
'
extensiongalleryservice
'
);
const
marketplaceHome
=
join
(
parentDir
,
'
Marketplace
'
);
let
fileService
:
IFileService
;
let
disposables
:
DisposableStore
;
setup
(
done
=>
{
disposables
=
new
DisposableStore
();
fileService
=
new
FileService
(
new
NullLogService
());
disposables
.
add
(
fileService
);
const
diskFileSystemProvider
=
new
DiskFileSystemProvider
(
new
NullLogService
());
disposables
.
add
(
diskFileSystemProvider
);
fileService
.
registerProvider
(
Schemas
.
file
,
diskFileSystemProvider
);
// Delete any existing backups completely and then re-create it.
rimraf
(
marketplaceHome
,
RimRafMode
.
MOVE
).
then
(()
=>
{
mkdirp
(
marketplaceHome
).
then
(()
=>
{
...
...
@@ -28,6 +44,7 @@ suite('Extension Gallery Service', () => {
});
teardown
(
done
=>
{
disposables
.
clear
();
rimraf
(
marketplaceHome
,
RimRafMode
.
MOVE
).
then
(
done
,
done
);
});
...
...
@@ -35,10 +52,10 @@ suite('Extension Gallery Service', () => {
const
args
=
[
'
--user-data-dir
'
,
marketplaceHome
];
const
environmentService
=
new
EnvironmentService
(
parseArgs
(
args
),
process
.
execPath
);
return
resolveMarketplaceHeaders
(
environmentService
).
then
(
headers
=>
{
return
resolveMarketplaceHeaders
(
environmentService
,
fileService
).
then
(
headers
=>
{
assert
.
ok
(
isUUID
(
headers
[
'
X-Market-User-Id
'
]));
return
resolveMarketplaceHeaders
(
environmentService
).
then
(
headers2
=>
{
return
resolveMarketplaceHeaders
(
environmentService
,
fileService
).
then
(
headers2
=>
{
assert
.
equal
(
headers
[
'
X-Market-User-Id
'
],
headers2
[
'
X-Market-User-Id
'
]);
});
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录