types.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { AssetNamingStrategy, AssetStorageStrategy } from '@vendure/core';
  2. /**
  3. * @description
  4. * Specifies the way in which an asset preview image will be resized to fit in the
  5. * proscribed dimensions:
  6. *
  7. * * crop: crops the image to cover both provided dimensions
  8. * * resize: Preserving aspect ratio, resizes the image to be as large as possible
  9. * while ensuring its dimensions are less than or equal to both those specified.
  10. *
  11. * @docsCategory AssetServerPlugin
  12. */
  13. export type ImageTransformMode = 'crop' | 'resize';
  14. /**
  15. * @description
  16. * A configuration option for an image size preset for the AssetServerPlugin.
  17. *
  18. * Presets allow a shorthand way to generate a thumbnail preview of an asset. For example,
  19. * the built-in "tiny" preset generates a 50px x 50px cropped preview, which can be accessed
  20. * by appending the string `preset=tiny` to the asset url:
  21. *
  22. * `http://localhost:3000/assets/some-asset.jpg?preset=tiny`
  23. *
  24. * is equivalent to:
  25. *
  26. * `http://localhost:3000/assets/some-asset.jpg?w=50&h=50&mode=crop`
  27. *
  28. * @docsCategory AssetServerPlugin
  29. */
  30. export interface ImageTransformPreset {
  31. name: string;
  32. width: number;
  33. height: number;
  34. mode: ImageTransformMode;
  35. }
  36. /**
  37. * @description
  38. * The configuration options for the AssetServerPlugin.
  39. *
  40. * @docsCategory AssetServerPlugin
  41. */
  42. export interface AssetServerOptions {
  43. hostname?: string;
  44. /**
  45. * @description
  46. * The local port that the server will run on. Note that the AssetServerPlugin
  47. * includes a proxy server which allows the asset server to be accessed on the same
  48. * port as the main Vendure server.
  49. */
  50. port: number;
  51. /**
  52. * @description
  53. * The proxy route to the asset server.
  54. */
  55. route: string;
  56. /**
  57. * @description
  58. * The local directory to which assets will be uploaded when using the {@link LocalAssetStorageStrategy}.
  59. */
  60. assetUploadDir: string; // TODO: this is strategy-specific and should be moved out of the global options
  61. /**
  62. * @description
  63. * The complete URL prefix of the asset files. For example, "https://demo.vendure.io/assets/"
  64. *
  65. * If not provided, the plugin will attempt to guess based off the incoming
  66. * request and the configured route. However, in all but the simplest cases,
  67. * this guess may not yield correct results.
  68. */
  69. assetUrlPrefix?: string;
  70. /**
  71. * @description
  72. * The max width in pixels of a generated preview image.
  73. *
  74. * @default 1600
  75. */
  76. previewMaxWidth?: number;
  77. /**
  78. * @description
  79. * The max height in pixels of a generated preview image.
  80. *
  81. * @default 1600
  82. */
  83. previewMaxHeight?: number;
  84. /**
  85. * @description
  86. * An array of additional {@link ImageTransformPreset} objects.
  87. */
  88. presets?: ImageTransformPreset[];
  89. /**
  90. * @description
  91. * Defines how asset files and preview images are named before being saved.
  92. *
  93. * @default HashedAssetNamingStrategy
  94. */
  95. namingStrategy?: AssetNamingStrategy;
  96. /**
  97. * @description
  98. * A function which can be used to configure an {@link AssetStorageStrategy}. This is useful e.g. if you wish to store your assets
  99. * using a cloud storage provider. By default, the {@link LocalAssetStorageStrategy} is used.
  100. *
  101. * @default () => LocalAssetStorageStrategy
  102. */
  103. storageStrategyFactory?: (
  104. options: AssetServerOptions,
  105. ) => AssetStorageStrategy | Promise<AssetStorageStrategy>;
  106. }