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

/***/ 26438:
/***/ ((__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?.method == "POST") {
        return new Proxy({}, {
            get (_, key) {
                return req.body?.[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 __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;
const pool_1 = __importDefault(__webpack_require__(541808));
async function checkPathExists(public_path_id) {
    if (typeof public_path_id != "string" || public_path_id.length != 40) {
        throw Error(`invalid public path id ${public_path_id}`);
    }
    const pool = (0, pool_1.default)();
    const { rows } = await pool.query("SELECT COUNT(*)::INT FROM public_paths WHERE id=$1", [public_path_id]);
    if (rows[0].count == 0) {
        throw Error(`no public path with id ${public_path_id}`);
    }
}
async function star(public_path_id, account_id) {
    await checkPathExists(public_path_id);
    const pool = (0, pool_1.default)();
    await pool.query("INSERT INTO public_path_stars (public_path_id, account_id, time) VALUES($1,$2,NOW())", [public_path_id, account_id]);
}
exports.star = star;
async function unstar(public_path_id, account_id) {
    await checkPathExists(public_path_id);
    const pool = (0, pool_1.default)();
    await pool.query("DELETE FROM public_path_stars WHERE public_path_id=$1 AND account_id=$2", [public_path_id, account_id]);
}
exports.unstar = unstar;
// see https://stackoverflow.com/questions/66389300/postgres-cast-count-as-integer for why ::int is needed; it's due to BigInt.
async function numStars(public_path_id) {
    const pool = (0, pool_1.default)();
    const { rows } = await pool.query("SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=$1", [public_path_id]);
    return rows[0].count ?? 0;
}
exports.numStars = numStars;
async function isStarred(public_path_id, account_id) {
    const pool = (0, pool_1.default)();
    const { rows } = await pool.query("SELECT COUNT(*)::INT FROM public_path_stars WHERE public_path_id=$1 AND account_id=$2", [public_path_id, account_id]);
    return rows[0].count > 0;
}
exports.isStarred = isStarred;
async function getStars(account_id) {
    const pool = (0, pool_1.default)();
    const { rows } = await pool.query("SELECT public_path_id FROM public_path_stars WHERE account_id=$1", [account_id]);
    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)
}


/***/ })

};
;