@openstax/ts-utils 1.21.5 → 1.21.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import { ConfigProviderForConfig } from '../../config';
2
2
  import { FileServerAdapter } from '.';
3
3
  export declare type Config = {
4
- port: string;
5
- host: string;
4
+ port?: string;
5
+ host?: string;
6
6
  storagePrefix: string;
7
7
  };
8
8
  interface Initializer<C> {
@@ -10,8 +10,8 @@ interface Initializer<C> {
10
10
  configSpace?: C;
11
11
  }
12
12
  export declare const localFileServer: <C extends string = "local">(initializer: Initializer<C>) => (configProvider: { [key in C]: {
13
- port: import("../../config").ConfigValueProvider<string>;
14
- host: import("../../config").ConfigValueProvider<string>;
13
+ port?: import("../../config").ConfigValueProvider<string> | undefined;
14
+ host?: import("../../config").ConfigValueProvider<string> | undefined;
15
15
  storagePrefix: import("../../config").ConfigValueProvider<string>;
16
16
  }; }) => FileServerAdapter;
17
17
  export {};
@@ -51,12 +51,12 @@ const startServer = (0, helpers_1.once)((port, uploadDir) => {
51
51
  });
52
52
  const localFileServer = (initializer) => (configProvider) => {
53
53
  const config = configProvider[(0, guards_1.ifDefined)(initializer.configSpace, 'local')];
54
- const port = (0, config_1.resolveConfigValue)(config.port);
55
- const host = (0, config_1.resolveConfigValue)(config.host);
54
+ const port = (0, config_1.resolveConfigValue)(config.port || '');
55
+ const host = (0, config_1.resolveConfigValue)(config.host || '');
56
56
  const storagePrefix = (0, config_1.resolveConfigValue)(config.storagePrefix);
57
57
  const fileDir = storagePrefix.then((prefix) => path_1.default.join(initializer.dataDir, prefix));
58
58
  Promise.all([port, fileDir])
59
- .then(([port, fileDir]) => startServer(port, fileDir));
59
+ .then(([port, fileDir]) => port && startServer(port, fileDir));
60
60
  const getSignedViewerUrl = async (source) => {
61
61
  return `https://${await host}:${await port}/${source.path}`;
62
62
  };
@@ -66,6 +66,8 @@ const localFileServer = (initializer) => (configProvider) => {
66
66
  };
67
67
  const putFileContent = async (source, content) => {
68
68
  const filePath = path_1.default.join(await fileDir, source.path);
69
+ const directory = path_1.default.dirname(filePath);
70
+ await fs_1.default.promises.mkdir(directory, { recursive: true });
69
71
  await fs_1.default.promises.writeFile(filePath, content);
70
72
  return source;
71
73
  };