gatsby-source-prismic
Version:
Gatsby source plugin for building websites using Prismic as a data source
1 lines • 1.77 kB
Source Map (JSON)
{"version":3,"file":"shouldDownloadFile.cjs","sources":["../../../src/lib/shouldDownloadFile.ts"],"sourcesContent":["import type { ImageFieldImage, LinkToMediaField } from \"@prismicio/client\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype ShouldDownloadFileArgs = {\n\tpath: string[];\n\tfield: ImageFieldImage<\"filled\"> | LinkToMediaField<\"filled\">;\n\tpluginOptions: PluginOptions;\n};\n\nexport const shouldDownloadFile = async (\n\targs: ShouldDownloadFileArgs,\n): Promise<boolean> => {\n\tconst fieldDotPath = args.path.join(\".\");\n\n\tswitch (typeof args.pluginOptions.shouldDownloadFiles) {\n\t\tcase \"boolean\": {\n\t\t\treturn args.pluginOptions.shouldDownloadFiles;\n\t\t}\n\n\t\tcase \"function\": {\n\t\t\treturn await args.pluginOptions.shouldDownloadFiles(args.field);\n\t\t}\n\n\t\tcase \"object\": {\n\t\t\tconst predicate = args.pluginOptions.shouldDownloadFiles[fieldDotPath];\n\n\t\t\tif (predicate) {\n\t\t\t\tswitch (typeof predicate) {\n\t\t\t\t\tcase \"boolean\": {\n\t\t\t\t\t\treturn predicate;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase \"function\": {\n\t\t\t\t\t\treturn await predicate(args.field);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tdefault: {\n\t\t\treturn false;\n\t\t}\n\t}\n};\n"],"names":[],"mappings":";;AAUa,MAAA,qBAAqB,OACjC,SACqB;AACrB,QAAM,eAAe,KAAK,KAAK,KAAK,GAAG;AAE/B,UAAA,OAAO,KAAK,cAAc,qBAAqB;AAAA,IACtD,KAAK,WAAW;AACf,aAAO,KAAK,cAAc;AAAA,IAC1B;AAAA,IAED,KAAK,YAAY;AAChB,aAAO,MAAM,KAAK,cAAc,oBAAoB,KAAK,KAAK;AAAA,IAC9D;AAAA,IAED,KAAK,UAAU;AACd,YAAM,YAAY,KAAK,cAAc,oBAAoB,YAAY;AAErE,UAAI,WAAW;AACd,gBAAQ,OAAO,WAAW;AAAA,UACzB,KAAK,WAAW;AACR,mBAAA;AAAA,UACP;AAAA,UAED,KAAK,YAAY;AACT,mBAAA,MAAM,UAAU,KAAK,KAAK;AAAA,UACjC;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IAED,SAAS;AACD,aAAA;AAAA,IACP;AAAA,EACD;AACF;;"}