@openstax/ts-utils 1.21.4 → 1.21.6

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.
@@ -12,7 +12,7 @@ export declare type FolderValue = {
12
12
  export declare const isFileValue: (thing: any) => thing is FileValue;
13
13
  export declare const isFolderValue: (thing: any) => thing is FolderValue;
14
14
  export interface FileServerAdapter {
15
- putFileContent: (source: FileValue, content: string) => Promise<void>;
15
+ putFileContent: (source: FileValue, content: string) => Promise<FileValue>;
16
16
  getSignedViewerUrl: (source: FileValue) => Promise<string>;
17
17
  getFileContent: (source: FileValue) => Promise<Buffer>;
18
18
  }
@@ -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,7 +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
- return fs_1.default.promises.writeFile(filePath, content);
69
+ await fs_1.default.promises.writeFile(filePath, content);
70
+ return source;
70
71
  };
71
72
  return {
72
73
  getSignedViewerUrl,
@@ -38,6 +38,7 @@ const s3FileServer = (initializer) => (configProvider) => {
38
38
  ContentType: source.mimeType,
39
39
  });
40
40
  await (await s3Service()).send(command);
41
+ return source;
41
42
  };
42
43
  return {
43
44
  getFileContent,