UNPKG

@netlify/content-engine

Version:
75 lines 3.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.shouldDispatch = shouldDispatch; exports.dispatchLocalFileServiceJob = dispatchLocalFileServiceJob; exports.dispatchLocalImageServiceJob = dispatchLocalImageServiceJob; const path_1 = __importDefault(require("path")); const get_gatsby_version_1 = require("../utils/get-gatsby-version"); const url_generator_1 = require("../utils/url-generator"); const get_request_headers_for_url_1 = require("../utils/get-request-headers-for-url"); function shouldDispatch() { return (!(process.env.GATSBY_CLOUD_IMAGE_CDN === `1` || process.env.GATSBY_CLOUD_IMAGE_CDN === `true`) && process.env.NODE_ENV === `production`); } function dispatchLocalFileServiceJob({ url, filename, contentDigest, }, actions, store) { const GATSBY_VERSION = (0, get_gatsby_version_1.getGatsbyVersion)(); const publicUrl = (0, url_generator_1.generateFileUrl)({ url, filename, }, store).split(`/`); publicUrl.unshift(`public`); // get filename and remove querystring const outputFilename = decodeURI(publicUrl.pop()?.split(`?`)?.[0]); const httpHeaders = (0, get_request_headers_for_url_1.getRequestHeadersForUrl)(url, store); actions.createJobV2({ name: `FILE_CDN`, inputPaths: [], // we know it's an image so we just mimic an image outputDir: path_1.default.join(global.__GATSBY?.root || process.cwd(), ...publicUrl.filter(Boolean)), args: { url, filename: outputFilename, contentDigest, httpHeaders, }, }, { name: `gatsby`, // @ts-ignore - version is allowed version: GATSBY_VERSION, resolve: __dirname, }); } function dispatchLocalImageServiceJob({ url, filename, mimeType, contentDigest, }, imageArgs, actions, store) { const GATSBY_VERSION = (0, get_gatsby_version_1.getGatsbyVersion)(); const publicUrl = (0, url_generator_1.generateImageUrl)({ url, mimeType, filename, internal: { contentDigest }, }, imageArgs, store).split(`/`); publicUrl.unshift(`public`); // get filename and remove querystring const outputFilename = decodeURI(publicUrl.pop()?.split(`?`)?.[0]); const httpHeaders = (0, get_request_headers_for_url_1.getRequestHeadersForUrl)(url, store); actions.createJobV2({ name: `IMAGE_CDN`, inputPaths: [], outputDir: path_1.default.join(global.__GATSBY?.root || process.cwd(), ...publicUrl.filter(Boolean)), args: { url, filename: outputFilename, contentDigest, httpHeaders, ...imageArgs, }, }, { name: `gatsby`, // @ts-ignore - version is allowed version: GATSBY_VERSION, resolve: __dirname, }); } //# sourceMappingURL=dispatchers.js.map