utils.js 915 B

1234567891011121314151617181920212223242526272829303132333435
  1. // src/adapter/cloudflare-workers/utils.ts
  2. var getContentFromKVAsset = async (path, options) => {
  3. let ASSET_MANIFEST;
  4. if (options && options.manifest) {
  5. if (typeof options.manifest === "string") {
  6. ASSET_MANIFEST = JSON.parse(options.manifest);
  7. } else {
  8. ASSET_MANIFEST = options.manifest;
  9. }
  10. } else {
  11. if (typeof __STATIC_CONTENT_MANIFEST === "string") {
  12. ASSET_MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
  13. } else {
  14. ASSET_MANIFEST = __STATIC_CONTENT_MANIFEST;
  15. }
  16. }
  17. let ASSET_NAMESPACE;
  18. if (options && options.namespace) {
  19. ASSET_NAMESPACE = options.namespace;
  20. } else {
  21. ASSET_NAMESPACE = __STATIC_CONTENT;
  22. }
  23. const key = ASSET_MANIFEST[path];
  24. if (!key) {
  25. return null;
  26. }
  27. const content = await ASSET_NAMESPACE.get(key, { type: "stream" });
  28. if (!content) {
  29. return null;
  30. }
  31. return content;
  32. };
  33. export {
  34. getContentFromKVAsset
  35. };