代码之家  ›  专栏  ›  技术社区  ›  SeaBass

旁路病毒扫描谷歌驱动器链接,并得到确认ID

  •  0
  • SeaBass  · 技术社区  · 6 年前

    this thread

    function fixGoogleDriveURL(url) {
      if (url.indexOf('drive.google.com') !== -1) {
        var DocIDfull = url;
        var DocIDstart = DocIDfull.indexOf('open?id=');
        if (DocIDstart == -1) {
          // invalid
          return url;
        }
        var DocID = DocIDfull.slice(DocIDstart+8);
        url = 'https://drive.google.com/uc?export=download&id=' + DocID;
        var xhr = new XMLHttpRequest();
        xhr.onload = function () {
          if (xhr.readyState === xhr.DONE) {
            if (xhr.status === 200) {
              var token = xhr.responseText.match("/confirm=([0-9A-Za-z]+)&/");
              window.location.replace(url + '&confirm=' + token[1]);
              // should I add url += '&confirm=' + token[1] here instead of window.location?
            }
          }
        };
        xhr.open("GET", url);
        xhr.send();
      }
      return url;
    }
    console.log(fixGoogleDriveURL('https://drive.google.com/open?id=1C25uoL6nIqqNhex3wm8VwODsO2q2pXBt') + "\n<-- should output:\nhttps://drive.google.com/uc?export=download&id=1C25uoL6nIqqNhex3wm8VwODsO2q2pXBt&confirm=XXXXX");
    1 回复  |  直到 6 年前
        1
  •  1
  •   Mastacheata    6 年前

    Google不明确允许使用客户端JavaScript刮取GDrive,因此Ajax调用/XHR失败。

    绕过这一限制的唯一方法是在中间使用一个代理,它将转发Google的网站代码,但添加适当的访问控制Allow Origin头。 http://multiverso.me/AllOrigins/ https://corsproxy.github.io/

    AllOrigins站点有一些用于jQuery的示例代码,但基本上它们是通过URI编码您要访问的URL并将该字符串附加到站点的代理URL来工作的。 下面是freecocodecamp.org的一篇文章,概述了如何使用这些服务(跳到 Don’t Let CORS Stop You! 部分。