exports.id = 4032;
exports.ids = [4032];
exports.modules = {

/***/ 426006:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (/* binding */ getParams)
/* harmony export */ });
function getParams(req) {
    if ((req === null || req === void 0 ? void 0 : req.method) == "POST") {
        return new Proxy({}, {
            get (_, key) {
                var ref;
                return (ref = req.body) === null || ref === void 0 ? void 0 : ref[key];
            }
        });
    /*
    // Disabled, since this could lead to a sneaky click on a link attack.
    // Should only be enabled for dev purposes.
    } else if (req?.method == "GET") {
    return new Proxy(
      {},
      {
        get(_, key) {
          if (typeof key != "string") {
            return undefined;
          }
          return req.query?.[key];
        },
      }
    );
*/ } else {
        // only support params for POST requests.
        return {};
    }
};


/***/ }),

/***/ 958509:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {

"use strict";

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getStars = exports.isStarred = exports.numStars = exports.unstar = exports.star = void 0;
var pool_1 = __importDefault(__webpack_require__(541808));
function checkPathExists(public_path_id) {
    return __awaiter(this, void 0, void 0, function () {
        var pool, rows;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    if (typeof public_path_id != "string" || public_path_id.length != 40) {
                        throw Error("invalid public path id ".concat(public_path_id));
                    }
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("SELECT COUNT(*)::INT FROM public_paths WHERE id=$1", [public_path_id])];
                case 1:
                    rows = (_a.sent()).rows;
                    if (rows[0].count == 0) {
                        throw Error("no public path with id ".concat(public_path_id));
                    }
                    return [2 /*return*/];
            }
        });
    });
}
function star(public_path_id, account_id) {
    return __awaiter(this, void 0, void 0, function () {
        var pool;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, checkPathExists(public_path_id)];
                case 1:
                    _a.sent();
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("INSERT INTO public_path_stars (public_path_id, account_id, time) VALUES($1,$2,NOW())", [public_path_id, account_id])];
                case 2:
                    _a.sent();
                    return [2 /*return*/];
            }
        });
    });
}
exports.star = star;
function unstar(public_path_id, account_id) {
    return __awaiter(this, void 0, void 0, function () {
        var pool;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, checkPathExists(public_path_id)];
                case 1:
                    _a.sent();
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("DELETE FROM public_path_stars WHERE public_path_id=$1 AND account_id=$2", [public_path_id, account_id])];
                case 2:
                    _a.sent();
                    return [2 /*return*/];
            }
        });
    });
}
exports.unstar = unstar;
// see https://stackoverflow.com/questions/66389300/postgres-cast-count-as-integer for why ::int is needed; it's due to BigInt.
function numStars(public_path_id) {
    var _a;
    return __awaiter(this, void 0, void 0, function () {
        var pool, rows;
        return __generator(this, function (_b) {
            switch (_b.label) {
                case 0:
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=$1", [public_path_id])];
                case 1:
                    rows = (_b.sent()).rows;
                    return [2 /*return*/, (_a = rows[0].count) !== null && _a !== void 0 ? _a : 0];
            }
        });
    });
}
exports.numStars = numStars;
function isStarred(public_path_id, account_id) {
    return __awaiter(this, void 0, void 0, function () {
        var pool, rows;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=$1 AND account_id=$2", [public_path_id, account_id])];
                case 1:
                    rows = (_a.sent()).rows;
                    return [2 /*return*/, rows[0].count > 0];
            }
        });
    });
}
exports.isStarred = isStarred;
function getStars(account_id) {
    return __awaiter(this, void 0, void 0, function () {
        var pool, rows;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    pool = (0, pool_1.default)();
                    return [4 /*yield*/, pool.query("SELECT public_path_id FROM public_path_stars WHERE account_id=$1", [account_id])];
                case 1:
                    rows = (_a.sent()).rows;
                    return [2 /*return*/, rows];
            }
        });
    });
}
exports.getStars = getStars;
/*
// commented out since might not need it.
// Do a global query of all stars by everybody and return a map from
// public paths to how many times they have been stared, for all paths
// with at least 1 star.  This is cached for a bit.
// TODO: This does not scale indefinitely, but is an easy way to get started.
// This will obviously (hopefully!) have to get rewritten at some point in the future.
export async function globalStarCounts(): Promise<{
  [public_path_id: string]: number;
}> {
  const pool = getPool("medium");
  const { rows } = await pool.query(
    "select public_path_id, count(*)::INT from public_path_stars group by public_path_id"
  );
  const v: { [public_path_id: string]: number } = {};
  for (const row of rows) {
    v[row.public_path_id] = row.count;
  }
  return v;
}
*/
//# sourceMappingURL=star.js.map

/***/ }),

/***/ 630900:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {

var crypto = __webpack_require__(706113);

var rn = function(max) {
  var rnBytes = crypto.randomBytes(2);
  var randomNum = rnBytes.readUInt8(0) * 256 + rnBytes.readUInt8(1);
  return randomNum % max;
}

var digits = '0123456789'
var base62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'
var base30 = '0123456789ABCDFHKLMNPQRSTUVWXYZ'  // 1-9, A-Z exclude(E, G, I, J, O) for human read

exports.generate = function(len, chars) {
  len = len || 16;
  chars = chars || base62;
  var key = '';
  var charsLen = chars.length;
  for (var i=0; i<len; i++) {
    key += chars[rn(charsLen)];
  }
  return key;
};

exports.generateDigits = function(len) {
  len = len || 16;
  return exports.generate(len, digits)
};

exports.generateBase30 = function(len) {
  len = len || 16;
  return exports.generate(len, base30)
}


/***/ })

};
;