text: // Generated by IcedCoffeeScript 108.0.11
  (function() {
    var BaseScraper, FacebookScraper, constants, decode_sig, iced, make_ids, url, v_codes, __iced_k, __iced_k_noop,
      __hasProp = {}.hasOwnProperty,
      __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
  
    iced = require('iced-runtime');
    __iced_k = __iced_k_noop = function() {};
  
    BaseScraper = require('./base').BaseScraper;
  
    constants = require('../constants').constants;
  
    v_codes = constants.v_codes;
  
    decode_sig = require('kbpgp').ukm.decode_sig;
  
    make_ids = require('../base').make_ids;
  
    url = require('url');
  
    exports.FacebookScraper = FacebookScraper = (function(_super) {
      __extends(FacebookScraper, _super);
  
      function FacebookScraper(opts) {
        FacebookScraper.__super__.constructor.call(this, opts);
      }
  
      FacebookScraper.prototype._check_args = function(args) {
        if (!(args.username != null)) {
          return new Error("Bad args to Facebook proof: no username given");
        } else if (!(args.name != null) || (args.name !== 'facebook')) {
          return new Error("Bad args to Facebook proof: type is " + args.name);
        } else {
          return null;
        }
      };
  
      FacebookScraper.prototype.hunt2 = function(_arg, cb) {
        var err, name, proof_text_check, username;
        username = _arg.username, proof_text_check = _arg.proof_text_check, name = _arg.name;
        err = new Error("hunt2 is a no-op for Facebook");
        return cb(err, {});
      };
  
      FacebookScraper.prototype._convert_url_to_desktop = function(api_url) {
        var desktop, mobile;
        mobile = "https://m.facebook.com/";
        desktop = "https://www.facebook.com/";
        if (api_url.startsWith(mobile)) {
          return api_url.replace(mobile, desktop);
        } else {
          return api_url;
        }
      };
  
      FacebookScraper.prototype._check_api_url = function(_arg) {
        var api_url, desktop_url, rxx, username;
        api_url = _arg.api_url, username = _arg.username;
        if (api_url == null) {
          return false;
        }
        rxx = new RegExp("^https://www.facebook.com/" + username + "/posts/[0-9]+$", "i");
        desktop_url = this._convert_url_to_desktop(api_url);
        return desktop_url.match(rxx);
      };
  
      FacebookScraper.prototype.check_status = function(_arg, cb) {
        var api_url, desktop_url, err, first_code_comment, link_text, page$, proof$, proof_text_check, raw, rc, remote_id, unescaped_comment, username, ___iced_passed_deferral, __iced_deferrals, __iced_k;
        __iced_k = __iced_k_noop;
        ___iced_passed_deferral = iced.findDeferral(arguments);
        username = _arg.username, api_url = _arg.api_url, proof_text_check = _arg.proof_text_check, remote_id = _arg.remote_id;
        if (!this._check_api_url({
          api_url: api_url,
          username: username
        })) {
          this.log("Facebook post URL isn't valid for user " + username + ": " + api_url);
          return cb(null, v_codes.CONTENT_FAILURE);
        }
        desktop_url = this._convert_url_to_desktop(api_url);
        (function(_this) {
          return (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/max/src/keybase/proofs/src/scrapers/facebook.iced",
              funcname: "FacebookScraper.check_status"
            });
            _this._get_url_body({
              url: desktop_url
            }, __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  rc = arguments[1];
                  return raw = arguments[2];
                };
              })(),
              lineno: 81
            }));
            __iced_deferrals._fulfill();
          });
        })(this)((function(_this) {
          return function() {
            var _ref;
            if ((typeof err !== "undefined" && err !== null) || rc !== v_codes.OK) {
              return cb(err, rc);
            }
            page$ = _this.libs.cheerio.load(raw);
            first_code_comment = (_ref = page$('code').eq(0).contents().toArray()[0]) != null ? _ref.data : void 0;
            if (first_code_comment == null) {
              _this.log("failed to find proof markup comment in Facebook response");
              return cb(null, v_codes.TEXT_NOT_FOUND);
            }
            unescaped_comment = first_code_comment.split("-\\-\\").join("--").split("\\\\").join("\\");
            proof$ = _this.libs.cheerio.load(unescaped_comment);
            link_text = proof$('div.userContent+div a').eq(1).text();
            if (link_text.trim() !== proof_text_check.trim()) {
              _this.log("failed to find attachment title '" + proof_text_check + "' in Facebook post " + desktop_url + ": " + (JSON.stringify(link_text.trim())) + " != " + (JSON.stringify(proof_text_check.trim())));
              return cb(null, v_codes.TEXT_NOT_FOUND);
            }
            return cb(null, v_codes.OK);
          };
        })(this));
      };
  
      FacebookScraper.prototype._validate_text_check = function(_arg) {
        var err, med_id, msg, proof_text_check, signature, _ref;
        signature = _arg.signature, proof_text_check = _arg.proof_text_check;
        _ref = decode_sig({
          armored: signature
        }), err = _ref[0], msg = _ref[1];
        if (err == null) {
          med_id = make_ids(msg.body).med_id;
          if (proof_text_check.split(/\s+/).indexOf(med_id) < 0) {
            err = new Error("Cannot find " + med_id + " in " + proof_text_check);
          }
        }
        return err;
      };
  
      return FacebookScraper;
  
    })(BaseScraper);
  
  }).call(this);
  