1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-27 20:55:25 +00:00

Feature/relative url (#307)

* resrouce relative url

* add url pathname for require.toUrl (fix webview url)

* rest resrouce relative url

* fix resource url

* ignore .vscode
This commit is contained in:
majik 2019-04-11 09:07:53 +08:00 committed by Asher
parent 3fae68bbab
commit 4b217fba00
4 changed files with 14 additions and 8 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@ dist
out
.DS_Store
release
.cache
.vscode
.cache

View File

@ -45,7 +45,8 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
},
set: (value: string): void => {
if (value) {
value = value.replace(/file:\/\//g, "/resource");
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
value = value.replace(/file:\/\//g, resourceBaseUrl);
}
oldSrc!.set!.call(img, value);
},
@ -66,7 +67,8 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
},
set: (value: string): void => {
if (value) {
value = value.replace(/file:\/\//g, "/resource");
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
value = value.replace(/file:\/\//g, resourceBaseUrl);
}
oldInnerHtml!.set!.call(style, value);
},
@ -80,7 +82,8 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
if (sheet && !overridden) {
const oldInsertRule = sheet.insertRule;
sheet.insertRule = (rule: string, index?: number): void => {
rule = rule.replace(/file:\/\//g, "/resource");
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
rule = rule.replace(/file:\/\//g, resourceBaseUrl);
oldInsertRule.call(sheet, rule, index);
};
overridden = true;
@ -145,8 +148,9 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
(view as any).send = (channel: string, ...args: any[]): void => { // tslint:disable-line no-any
if (args[0] && typeof args[0] === "object" && args[0].contents) {
// TODO
args[0].contents = (args[0].contents as string).replace(/"(file:\/\/[^"]*)"/g, (m1) => `"/resource${m1}"`);
args[0].contents = (args[0].contents as string).replace(/"vscode-resource:([^"]*)"/g, (m, m1) => `"/resource${m1}"`);
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
args[0].contents = (args[0].contents as string).replace(/"(file:\/\/[^"]*)"/g, (m1) => `"${resourceBaseUrl}${m1}"`);
args[0].contents = (args[0].contents as string).replace(/"vscode-resource:([^"]*)"/g, (m, m1) => `"${resourceBaseUrl}${m1}"`);
args[0].contents = (args[0].contents as string).replace(/style-src vscode-core-resource:/g, "style-src 'self'");
}
if (view.contentWindow) {

View File

@ -28,7 +28,8 @@ class StorageDatabase implements workspaceStorage.IStorageDatabase {
}
this.triggerFlush(WillSaveStateReason.SHUTDOWN);
navigator.sendBeacon(`/resource${this.path}`, this.content);
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
navigator.sendBeacon(`${resourceBaseUrl}/${this.path}`, this.content);
});
}

View File

@ -21,7 +21,7 @@ module.exports = (options = {}) => ({
// they are parsed as URIs and will throw errors if not fully formed.
// The !! prefix causes it to ignore other loaders (doesn't work).
search: "require\\.toUrl\\(",
replace: "location.protocol + '//' + location.host + '/' + require('!!file-loader?name=[path][name].[ext]!' + ",
replace: "location.protocol + '//' + location.host + location.pathname.replace(/\\/$/,'') + '/' + require('!!file-loader?name=[path][name].[ext]!' + ",
flags: "g",
}, {
search: "require\\.__\\$__nodeRequire",