mirror of
https://github.com/LamGC/quickly-conf-sshd.git
synced 2025-04-29 22:27:32 +00:00
修复了 Worker 脚本中的问题。
This commit is contained in:
parent
de1f094a3e
commit
2ddcf7c6ba
@ -5,7 +5,7 @@ const githubInstSshProjectName = "quickly-conf-sshd";
|
|||||||
const baseUrl = `https://${githubUserName.toLowerCase()}.github.io/${githubInstSshProjectName}/`;
|
const baseUrl = `https://${githubUserName.toLowerCase()}.github.io/${githubInstSshProjectName}/`;
|
||||||
const installScriptUrl = `${baseUrl}/conf-sshd.sh`;
|
const installScriptUrl = `${baseUrl}/conf-sshd.sh`;
|
||||||
// 如果出现 Github 无法使用的情况, 可以修改 sshKeyUrl 来变更位置.
|
// 如果出现 Github 无法使用的情况, 可以修改 sshKeyUrl 来变更位置.
|
||||||
const sshKeyUrl = `https://github.com/${githubUserName}.keys`;
|
const sshKeyUrls = [`https://github.com/${githubUserName}.keys`];
|
||||||
// 建议在此设置备用的 SSH 公钥, 以防 Github 无法使用.
|
// 建议在此设置备用的 SSH 公钥, 以防 Github 无法使用.
|
||||||
const backupSshKeys = ``;
|
const backupSshKeys = ``;
|
||||||
|
|
||||||
@ -17,9 +17,19 @@ export default {
|
|||||||
async fetch(request, env) {
|
async fetch(request, env) {
|
||||||
const { pathname } = new URL(request.url);
|
const { pathname } = new URL(request.url);
|
||||||
if (pathname === "/ssh.keys") {
|
if (pathname === "/ssh.keys") {
|
||||||
let response = await fetch(new Request(sshKeyUrl));
|
for (let url of sshKeyUrls) {
|
||||||
if (response.ok) {
|
let response = await fetch(new Request(url));
|
||||||
return new Response(response.text(), {
|
if (response.ok) {
|
||||||
|
let keys = await response.text()
|
||||||
|
return new Response(keys, {
|
||||||
|
headers: {
|
||||||
|
"content-type": "text/plain; charset=utf-8"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (backupSshKeys.length > 0) {
|
||||||
|
return new Response(backupSshKeys, {
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "text/plain; charset=utf-8"
|
"content-type": "text/plain; charset=utf-8"
|
||||||
}
|
}
|
||||||
@ -35,14 +45,24 @@ export default {
|
|||||||
}
|
}
|
||||||
} else if (pathname === "/") {
|
} else if (pathname === "/") {
|
||||||
const userAgent = getUserAgent(request);
|
const userAgent = getUserAgent(request);
|
||||||
if (userAgent.match(/curl|libcurl/) !== null) {
|
if (userAgent != null && userAgent.match(/curl|libcurl/) !== null) {
|
||||||
return new Response("", {
|
let scriptResp = await fetch(new Request(installScriptUrl));
|
||||||
status: 301,
|
if (scriptResp.ok) {
|
||||||
statusText: "Redirect",
|
let scriptContent = await scriptResp.text();
|
||||||
headers: {
|
return new Response(scriptContent, {
|
||||||
"Location": installScriptUrl
|
headers: {
|
||||||
}
|
"content-type": "text/plain; charset=utf-8"
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return new Response("Failed to get install script.", {
|
||||||
|
status: 500,
|
||||||
|
statusText: "Failed to get install script",
|
||||||
|
headers: {
|
||||||
|
"content-type": "text/plain; charset=utf-8"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return new Response("", {
|
return new Response("", {
|
||||||
status: 301,
|
status: 301,
|
||||||
|
Loading…
Reference in New Issue
Block a user