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