@orion-js/file-manager 3.8.0 → 3.9.1

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.
package/lib/File/index.js CHANGED
@@ -9,6 +9,8 @@ const pick_1 = __importDefault(require("lodash/pick"));
9
9
  const omit_1 = __importDefault(require("lodash/omit"));
10
10
  const schema_1 = require("./schema");
11
11
  const typed_model_1 = require("@orion-js/typed-model");
12
+ const isImage_1 = require("./resolvers/isImage");
13
+ const credentials_1 = require("../credentials");
12
14
  const schema = (0, typed_model_1.getModelForClass)(schema_1.FileSchema).getSchema();
13
15
  exports.default = (0, models_1.createModel)({
14
16
  name: 'File',
@@ -22,8 +24,29 @@ exports.default = (0, models_1.createModel)({
22
24
  const file = await Files_1.Files.findOne({ _id: fileId });
23
25
  if (!file)
24
26
  return null;
27
+ if ((0, isImage_1.isImage)(file)) {
28
+ const options = (0, credentials_1.getFileManagerOptions)();
29
+ if (!file.resizedData && options.getResizedImages) {
30
+ try {
31
+ file.resizedData = await options.getResizedImages(file);
32
+ await Files_1.Files.updateOne(file, { $set: { resizedData: file.resizedData } });
33
+ }
34
+ catch (error) {
35
+ console.error('Error getting resized images', error);
36
+ }
37
+ }
38
+ if (!file.colorsData && options.getImageColors) {
39
+ try {
40
+ file.colorsData = await options.getImageColors(file);
41
+ await Files_1.Files.updateOne(file, { $set: { colorsData: file.colorsData } });
42
+ }
43
+ catch (error) {
44
+ console.error('Error getting image colors', error);
45
+ }
46
+ }
47
+ }
25
48
  const keys = Object.keys((0, omit_1.default)(schema, 'createdBy', 'createdAt', 'status'));
26
49
  const data = (0, pick_1.default)(file, keys);
27
50
  return data;
28
- }
51
+ },
29
52
  });
@@ -1,2 +1,2 @@
1
- declare const _default: import("@orion-js/resolvers").ModelResolver<(file: any, viewer: any) => Promise<"unknown" | "image" | "pdf">>;
1
+ declare const _default: import("@orion-js/resolvers").ModelResolver<(file: any, viewer: any) => Promise<"image" | "unknown" | "pdf">>;
2
2
  export default _default;
@@ -1,5 +1,5 @@
1
1
  declare const _default: {
2
2
  url: import("@orion-js/resolvers").ModelResolver<(file: any) => Promise<string>>;
3
- genericType: import("@orion-js/resolvers").ModelResolver<(file: any, viewer: any) => Promise<"unknown" | "image" | "pdf">>;
3
+ genericType: import("@orion-js/resolvers").ModelResolver<(file: any, viewer: any) => Promise<"image" | "unknown" | "pdf">>;
4
4
  };
5
5
  export default _default;
@@ -0,0 +1,2 @@
1
+ import { FileSchema } from '../schema';
2
+ export declare function isImage(image: FileSchema): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isImage = void 0;
4
+ function isImage(image) {
5
+ if (!image.type) {
6
+ return true;
7
+ }
8
+ const mime = image.type;
9
+ return mime.includes('image');
10
+ }
11
+ exports.isImage = isImage;
@@ -1,3 +1,19 @@
1
+ export declare class FileSchemaResizeData {
2
+ thumbnailURL?: string;
3
+ smallURL?: string;
4
+ mediumURL?: string;
5
+ largeURL?: string;
6
+ extraLargeURL?: string;
7
+ }
8
+ export declare class FileSchemaColorsData {
9
+ vibrant?: string;
10
+ lightVibrant?: string;
11
+ darkVibrant?: string;
12
+ muted?: string;
13
+ lightMuted?: string;
14
+ darkMuted?: string;
15
+ blurhash?: string;
16
+ }
1
17
  export declare class FileSchema {
2
18
  _id: string;
3
19
  hash?: string;
@@ -10,4 +26,6 @@ export declare class FileSchema {
10
26
  status?: string;
11
27
  createdBy?: string;
12
28
  createdAt?: Date;
29
+ resizedData?: FileSchemaResizeData;
30
+ colorsData?: FileSchemaColorsData;
13
31
  }
@@ -9,8 +9,68 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.FileSchema = void 0;
12
+ exports.FileSchema = exports.FileSchemaColorsData = exports.FileSchemaResizeData = void 0;
13
13
  const typed_model_1 = require("@orion-js/typed-model");
14
+ let FileSchemaResizeData = class FileSchemaResizeData {
15
+ };
16
+ __decorate([
17
+ (0, typed_model_1.Prop)({ optional: true }),
18
+ __metadata("design:type", String)
19
+ ], FileSchemaResizeData.prototype, "thumbnailURL", void 0);
20
+ __decorate([
21
+ (0, typed_model_1.Prop)({ optional: true }),
22
+ __metadata("design:type", String)
23
+ ], FileSchemaResizeData.prototype, "smallURL", void 0);
24
+ __decorate([
25
+ (0, typed_model_1.Prop)({ optional: true }),
26
+ __metadata("design:type", String)
27
+ ], FileSchemaResizeData.prototype, "mediumURL", void 0);
28
+ __decorate([
29
+ (0, typed_model_1.Prop)({ optional: true }),
30
+ __metadata("design:type", String)
31
+ ], FileSchemaResizeData.prototype, "largeURL", void 0);
32
+ __decorate([
33
+ (0, typed_model_1.Prop)({ optional: true }),
34
+ __metadata("design:type", String)
35
+ ], FileSchemaResizeData.prototype, "extraLargeURL", void 0);
36
+ FileSchemaResizeData = __decorate([
37
+ (0, typed_model_1.TypedSchema)()
38
+ ], FileSchemaResizeData);
39
+ exports.FileSchemaResizeData = FileSchemaResizeData;
40
+ let FileSchemaColorsData = class FileSchemaColorsData {
41
+ };
42
+ __decorate([
43
+ (0, typed_model_1.Prop)({ optional: true }),
44
+ __metadata("design:type", String)
45
+ ], FileSchemaColorsData.prototype, "vibrant", void 0);
46
+ __decorate([
47
+ (0, typed_model_1.Prop)({ optional: true }),
48
+ __metadata("design:type", String)
49
+ ], FileSchemaColorsData.prototype, "lightVibrant", void 0);
50
+ __decorate([
51
+ (0, typed_model_1.Prop)({ optional: true }),
52
+ __metadata("design:type", String)
53
+ ], FileSchemaColorsData.prototype, "darkVibrant", void 0);
54
+ __decorate([
55
+ (0, typed_model_1.Prop)({ optional: true }),
56
+ __metadata("design:type", String)
57
+ ], FileSchemaColorsData.prototype, "muted", void 0);
58
+ __decorate([
59
+ (0, typed_model_1.Prop)({ optional: true }),
60
+ __metadata("design:type", String)
61
+ ], FileSchemaColorsData.prototype, "lightMuted", void 0);
62
+ __decorate([
63
+ (0, typed_model_1.Prop)({ optional: true }),
64
+ __metadata("design:type", String)
65
+ ], FileSchemaColorsData.prototype, "darkMuted", void 0);
66
+ __decorate([
67
+ (0, typed_model_1.Prop)({ optional: true }),
68
+ __metadata("design:type", String)
69
+ ], FileSchemaColorsData.prototype, "blurhash", void 0);
70
+ FileSchemaColorsData = __decorate([
71
+ (0, typed_model_1.TypedSchema)()
72
+ ], FileSchemaColorsData);
73
+ exports.FileSchemaColorsData = FileSchemaColorsData;
14
74
  let FileSchema = class FileSchema {
15
75
  };
16
76
  __decorate([
@@ -18,15 +78,13 @@ __decorate([
18
78
  __metadata("design:type", String)
19
79
  ], FileSchema.prototype, "_id", void 0);
20
80
  __decorate([
21
- (0, typed_model_1.Prop)({
22
- optional: true
23
- }),
81
+ (0, typed_model_1.Prop)({ optional: true }),
24
82
  __metadata("design:type", String)
25
83
  ], FileSchema.prototype, "hash", void 0);
26
84
  __decorate([
27
85
  (0, typed_model_1.Prop)({
28
86
  optional: true,
29
- private: true
87
+ private: true,
30
88
  }),
31
89
  __metadata("design:type", String)
32
90
  ], FileSchema.prototype, "externalUrl", void 0);
@@ -62,6 +120,14 @@ __decorate([
62
120
  (0, typed_model_1.Prop)({ optional: true }),
63
121
  __metadata("design:type", Date)
64
122
  ], FileSchema.prototype, "createdAt", void 0);
123
+ __decorate([
124
+ (0, typed_model_1.Prop)({ optional: true }),
125
+ __metadata("design:type", FileSchemaResizeData)
126
+ ], FileSchema.prototype, "resizedData", void 0);
127
+ __decorate([
128
+ (0, typed_model_1.Prop)({ optional: true }),
129
+ __metadata("design:type", FileSchemaColorsData)
130
+ ], FileSchema.prototype, "colorsData", void 0);
65
131
  FileSchema = __decorate([
66
132
  (0, typed_model_1.TypedSchema)()
67
133
  ], FileSchema);
@@ -1,3 +1,4 @@
1
+ import { FileSchema, FileSchemaColorsData, FileSchemaResizeData } from './File/schema';
1
2
  export interface FileManagerOptions {
2
3
  accessKeyId: string;
3
4
  secretAccessKey: string;
@@ -8,6 +9,12 @@ export interface FileManagerOptions {
8
9
  basePath: string;
9
10
  endpoint?: string;
10
11
  s3ForcePathStyle?: boolean;
12
+ getResizedImages?: (file: FileSchema) => Promise<FileSchemaResizeData>;
13
+ getImageColors?: (file: FileSchema) => Promise<FileSchemaColorsData>;
11
14
  }
12
15
  export declare const setupFileManager: (options: FileManagerOptions) => void;
16
+ /**
17
+ * @deprecated use getFileManagerOptions instead
18
+ */
13
19
  export declare const getAWSCredentials: () => Partial<FileManagerOptions>;
20
+ export declare const getFileManagerOptions: () => Partial<FileManagerOptions>;
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAWSCredentials = exports.setupFileManager = void 0;
3
+ exports.getFileManagerOptions = exports.getAWSCredentials = exports.setupFileManager = void 0;
4
4
  let savedOptions = {};
5
5
  const setupFileManager = (options) => {
6
6
  savedOptions = options;
7
7
  };
8
8
  exports.setupFileManager = setupFileManager;
9
+ /**
10
+ * @deprecated use getFileManagerOptions instead
11
+ */
9
12
  const getAWSCredentials = () => savedOptions;
10
13
  exports.getAWSCredentials = getAWSCredentials;
14
+ const getFileManagerOptions = () => savedOptions;
15
+ exports.getFileManagerOptions = getFileManagerOptions;
@@ -11,8 +11,8 @@ const fileManagerFiles = (0, paginated_mongodb_1.paginatedResolver)({
11
11
  params: {
12
12
  filter: {
13
13
  type: String,
14
- optional: true
15
- }
14
+ optional: true,
15
+ },
16
16
  },
17
17
  returns: File_1.default,
18
18
  async getCursor({ filter }, viewer) {
@@ -22,6 +22,6 @@ const fileManagerFiles = (0, paginated_mongodb_1.paginatedResolver)({
22
22
  query.name = { $regex: new RegExp(`^${(0, escape_string_regexp_1.default)(filter)}`) };
23
23
  }
24
24
  return Files_1.Files.find(query);
25
- }
25
+ },
26
26
  });
27
27
  exports.default = fileManagerFiles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/file-manager",
3
- "version": "3.8.0",
3
+ "version": "3.9.1",
4
4
  "main": "lib/index.js",
5
5
  "author": "nicolaslopezj",
6
6
  "license": "MIT",
@@ -12,13 +12,13 @@
12
12
  "watch": "yarn run clean && tsc -w"
13
13
  },
14
14
  "dependencies": {
15
- "@orion-js/helpers": "^3.7.4",
16
- "@orion-js/models": "^3.7.6",
17
- "@orion-js/mongodb": "^3.8.0",
18
- "@orion-js/paginated-mongodb": "^3.8.0",
19
- "@orion-js/resolvers": "^3.7.4",
20
- "@orion-js/schema": "^3.7.4",
21
- "@orion-js/typed-model": "^3.7.4",
15
+ "@orion-js/helpers": "^3.9.0",
16
+ "@orion-js/models": "^3.9.0",
17
+ "@orion-js/mongodb": "^3.9.0",
18
+ "@orion-js/paginated-mongodb": "^3.9.0",
19
+ "@orion-js/resolvers": "^3.9.0",
20
+ "@orion-js/schema": "^3.9.0",
21
+ "@orion-js/typed-model": "^3.9.0",
22
22
  "aws-sdk": "^2.1367.0",
23
23
  "escape-string-regexp": "^4.0.0",
24
24
  "lodash": "^4.17.21",
@@ -33,11 +33,8 @@
33
33
  "ts-jest": "27.0.7",
34
34
  "typescript": "^4.6.3"
35
35
  },
36
- "peerDependencies": {
37
- "@orion-js/app": "*"
38
- },
39
36
  "publishConfig": {
40
37
  "access": "public"
41
38
  },
42
- "gitHead": "05bb0f7c0679b17993a2375332804d745dd49ba2"
39
+ "gitHead": "def716136d1b1550a05665e541b55efe901cff9a"
43
40
  }