mirror of https://git.tuxpa.in/a/code-server.git
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:
parent
3fae68bbab
commit
4b217fba00
|
@ -4,4 +4,5 @@ dist
|
||||||
out
|
out
|
||||||
.DS_Store
|
.DS_Store
|
||||||
release
|
release
|
||||||
.cache
|
.vscode
|
||||||
|
.cache
|
||||||
|
|
|
@ -45,7 +45,8 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
|
||||||
},
|
},
|
||||||
set: (value: string): void => {
|
set: (value: string): void => {
|
||||||
if (value) {
|
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);
|
oldSrc!.set!.call(img, value);
|
||||||
},
|
},
|
||||||
|
@ -66,7 +67,8 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
|
||||||
},
|
},
|
||||||
set: (value: string): void => {
|
set: (value: string): void => {
|
||||||
if (value) {
|
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);
|
oldInnerHtml!.set!.call(style, value);
|
||||||
},
|
},
|
||||||
|
@ -80,7 +82,8 @@ const newCreateElement = <K extends keyof HTMLElementTagNameMap>(tagName: K): HT
|
||||||
if (sheet && !overridden) {
|
if (sheet && !overridden) {
|
||||||
const oldInsertRule = sheet.insertRule;
|
const oldInsertRule = sheet.insertRule;
|
||||||
sheet.insertRule = (rule: string, index?: number): void => {
|
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);
|
oldInsertRule.call(sheet, rule, index);
|
||||||
};
|
};
|
||||||
overridden = true;
|
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
|
(view as any).send = (channel: string, ...args: any[]): void => { // tslint:disable-line no-any
|
||||||
if (args[0] && typeof args[0] === "object" && args[0].contents) {
|
if (args[0] && typeof args[0] === "object" && args[0].contents) {
|
||||||
// TODO
|
// TODO
|
||||||
args[0].contents = (args[0].contents as string).replace(/"(file:\/\/[^"]*)"/g, (m1) => `"/resource${m1}"`);
|
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
|
||||||
args[0].contents = (args[0].contents as string).replace(/"vscode-resource:([^"]*)"/g, (m, m1) => `"/resource${m1}"`);
|
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'");
|
args[0].contents = (args[0].contents as string).replace(/style-src vscode-core-resource:/g, "style-src 'self'");
|
||||||
}
|
}
|
||||||
if (view.contentWindow) {
|
if (view.contentWindow) {
|
||||||
|
|
|
@ -28,7 +28,8 @@ class StorageDatabase implements workspaceStorage.IStorageDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.triggerFlush(WillSaveStateReason.SHUTDOWN);
|
this.triggerFlush(WillSaveStateReason.SHUTDOWN);
|
||||||
navigator.sendBeacon(`/resource${this.path}`, this.content);
|
const resourceBaseUrl = location.pathname.replace(/\/$/, "") + "/resource";
|
||||||
|
navigator.sendBeacon(`${resourceBaseUrl}/${this.path}`, this.content);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ module.exports = (options = {}) => ({
|
||||||
// they are parsed as URIs and will throw errors if not fully formed.
|
// they are parsed as URIs and will throw errors if not fully formed.
|
||||||
// The !! prefix causes it to ignore other loaders (doesn't work).
|
// The !! prefix causes it to ignore other loaders (doesn't work).
|
||||||
search: "require\\.toUrl\\(",
|
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",
|
flags: "g",
|
||||||
}, {
|
}, {
|
||||||
search: "require\\.__\\$__nodeRequire",
|
search: "require\\.__\\$__nodeRequire",
|
||||||
|
|
Loading…
Reference in New Issue