utils.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name in all)
  7. __defProp(target, name, { get: all[name], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var utils_exports = {};
  19. __export(utils_exports, {
  20. getContentFromKVAsset: () => getContentFromKVAsset
  21. });
  22. module.exports = __toCommonJS(utils_exports);
  23. const getContentFromKVAsset = async (path, options) => {
  24. let ASSET_MANIFEST;
  25. if (options && options.manifest) {
  26. if (typeof options.manifest === "string") {
  27. ASSET_MANIFEST = JSON.parse(options.manifest);
  28. } else {
  29. ASSET_MANIFEST = options.manifest;
  30. }
  31. } else {
  32. if (typeof __STATIC_CONTENT_MANIFEST === "string") {
  33. ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
  34. } else {
  35. ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST;
  36. }
  37. }
  38. let ASSET_NAMESPACE;
  39. if (options && options.namespace) {
  40. ASSET_NAMESPACE = options.namespace;
  41. } else {
  42. ASSET_NAMESPACE = __STATIC_CONTENT;
  43. }
  44. const key = ASSET_MANIFEST[path];
  45. if (!key) {
  46. return null;
  47. }
  48. const content = await ASSET_NAMESPACE.get(key, { type: "stream" });
  49. if (!content) {
  50. return null;
  51. }
  52. return content;
  53. };
  54. // Annotate the CommonJS export names for ESM import in node:
  55. 0 && (module.exports = {
  56. getContentFromKVAsset
  57. });