fetch-inline-assets.js 1005 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.fetchInlineAsset = fetchInlineAsset;
  6. var _fs = require("fs");
  7. var _bodyStreams = require("../../body-streams");
  8. var _path = require("path");
  9. async function fetchInlineAsset(options) {
  10. var ref;
  11. const inputString = String(options.input);
  12. if (!inputString.startsWith("blob:")) {
  13. return;
  14. }
  15. const hash = inputString.replace("blob:", "");
  16. const asset = (ref = options.assets) == null ? void 0 : ref.find((x)=>x.name === hash);
  17. if (!asset) {
  18. return;
  19. }
  20. const filePath = (0, _path).resolve(options.distDir, asset.filePath);
  21. const fileIsReadable = await _fs.promises.access(filePath).then(()=>true, ()=>false);
  22. if (fileIsReadable) {
  23. const readStream = (0, _fs).createReadStream(filePath);
  24. return new options.context.Response((0, _bodyStreams).requestToBodyStream(options.context, readStream));
  25. }
  26. }
  27. //# sourceMappingURL=fetch-inline-assets.js.map