@orion-js/file-manager 4.0.0-next.2 → 4.0.0-next.4
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/LICENSE +21 -0
- package/dist/index.cjs +263 -393
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +252 -395
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,345 +1,106 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
var __esm = (fn, res) => function __init() {
|
|
7
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
4
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
5
|
+
var __typeError = (msg) => {
|
|
6
|
+
throw TypeError(msg);
|
|
8
7
|
};
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
|
+
var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
|
|
11
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
12
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
13
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
14
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
15
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
16
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
17
|
+
return value;
|
|
12
18
|
};
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
20
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
21
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
22
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
23
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
24
|
+
return __privateGet(this, extra);
|
|
25
|
+
}, set [name](x) {
|
|
26
|
+
return __privateSet(this, extra, x);
|
|
27
|
+
} }, name));
|
|
28
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
29
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
30
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
31
|
+
if (k) {
|
|
32
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
33
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
34
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
35
|
+
}
|
|
36
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
37
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
38
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
39
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
18
40
|
}
|
|
19
|
-
return
|
|
41
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
20
42
|
};
|
|
21
|
-
var
|
|
43
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
44
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
45
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
46
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
47
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
48
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
22
49
|
|
|
23
|
-
// src/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
getAWSCredentials = /* @__PURE__ */ __name(() => savedOptions, "getAWSCredentials");
|
|
32
|
-
getFileManagerOptions = /* @__PURE__ */ __name(() => savedOptions, "getFileManagerOptions");
|
|
33
|
-
}
|
|
34
|
-
});
|
|
50
|
+
// src/resolvers/fileManagerFile.ts
|
|
51
|
+
import { createResolver } from "@orion-js/resolvers";
|
|
52
|
+
|
|
53
|
+
// src/Files/index.ts
|
|
54
|
+
import { createCollection as createCollection2 } from "@orion-js/mongodb";
|
|
55
|
+
|
|
56
|
+
// src/File/schema.ts
|
|
57
|
+
import { Prop, TypedSchema } from "@orion-js/typed-model";
|
|
35
58
|
|
|
36
59
|
// src/File/resolvers/genericType.ts
|
|
37
60
|
import { modelResolver } from "@orion-js/resolvers";
|
|
38
|
-
var genericType_default
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (type.startsWith("image/")) return "image";
|
|
47
|
-
if (type.startsWith("application/pdf")) return "pdf";
|
|
48
|
-
return "unknown";
|
|
49
|
-
}
|
|
50
|
-
});
|
|
61
|
+
var genericType_default = modelResolver({
|
|
62
|
+
returns: String,
|
|
63
|
+
async resolve(file, viewer) {
|
|
64
|
+
const { type } = file;
|
|
65
|
+
if (!type) return "unknown";
|
|
66
|
+
if (type.startsWith("image/")) return "image";
|
|
67
|
+
if (type.startsWith("application/pdf")) return "pdf";
|
|
68
|
+
return "unknown";
|
|
51
69
|
}
|
|
52
70
|
});
|
|
53
71
|
|
|
54
72
|
// src/File/resolvers/url.ts
|
|
55
73
|
import { modelResolver as modelResolver2 } from "@orion-js/resolvers";
|
|
74
|
+
|
|
75
|
+
// src/credentials.ts
|
|
76
|
+
var savedOptions = {};
|
|
77
|
+
var setupFileManager = (options) => {
|
|
78
|
+
savedOptions = options;
|
|
79
|
+
};
|
|
80
|
+
var getAWSCredentials = () => savedOptions;
|
|
81
|
+
var getFileManagerOptions = () => savedOptions;
|
|
82
|
+
|
|
83
|
+
// src/File/resolvers/url.ts
|
|
56
84
|
function getFileURL(file) {
|
|
57
85
|
if (file.externalUrl) return file.externalUrl;
|
|
58
86
|
const options = getAWSCredentials();
|
|
59
87
|
if (options.getFileURL) return options.getFileURL(file);
|
|
60
88
|
return `https://s3.amazonaws.com/${file.bucket}/${encodeURIComponent(file.key)}`;
|
|
61
89
|
}
|
|
62
|
-
var url_default
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
__name(getFileURL, "getFileURL");
|
|
67
|
-
url_default = modelResolver2({
|
|
68
|
-
returns: String,
|
|
69
|
-
async resolve(file) {
|
|
70
|
-
return getFileURL(file);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
90
|
+
var url_default = modelResolver2({
|
|
91
|
+
returns: String,
|
|
92
|
+
async resolve(file) {
|
|
93
|
+
return getFileURL(file);
|
|
73
94
|
}
|
|
74
95
|
});
|
|
75
96
|
|
|
76
97
|
// src/File/resolvers/index.ts
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
var resolvers_default;
|
|
82
|
-
var init_resolvers = __esm({
|
|
83
|
-
"src/File/resolvers/index.ts"() {
|
|
84
|
-
init_genericType();
|
|
85
|
-
init_url();
|
|
86
|
-
resolvers_default = {
|
|
87
|
-
url: url_default,
|
|
88
|
-
genericType: genericType_default
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// src/resolvers/fileManagerFile.ts
|
|
94
|
-
import { resolver } from "@orion-js/resolvers";
|
|
95
|
-
|
|
96
|
-
// src/File/index.ts
|
|
97
|
-
import { createModel } from "@orion-js/models";
|
|
98
|
-
|
|
99
|
-
// src/Files/index.ts
|
|
100
|
-
import { createCollection } from "@orion-js/mongodb";
|
|
101
|
-
|
|
102
|
-
// src/File/schema.ts
|
|
103
|
-
import { getModelForClass, Prop, TypedSchema } from "@orion-js/typed-model";
|
|
104
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
105
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
106
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
107
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
108
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
109
|
-
}
|
|
110
|
-
__name(_ts_decorate, "_ts_decorate");
|
|
111
|
-
function _ts_metadata(k, v) {
|
|
112
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
113
|
-
}
|
|
114
|
-
__name(_ts_metadata, "_ts_metadata");
|
|
115
|
-
var _FileSchemaResizeData = class _FileSchemaResizeData {
|
|
116
|
-
thumbnailURL;
|
|
117
|
-
smallURL;
|
|
118
|
-
mediumURL;
|
|
119
|
-
largeURL;
|
|
120
|
-
extraLargeURL;
|
|
121
|
-
};
|
|
122
|
-
__name(_FileSchemaResizeData, "FileSchemaResizeData");
|
|
123
|
-
var FileSchemaResizeData = _FileSchemaResizeData;
|
|
124
|
-
_ts_decorate([
|
|
125
|
-
Prop({
|
|
126
|
-
optional: true
|
|
127
|
-
}),
|
|
128
|
-
_ts_metadata("design:type", String)
|
|
129
|
-
], FileSchemaResizeData.prototype, "thumbnailURL", void 0);
|
|
130
|
-
_ts_decorate([
|
|
131
|
-
Prop({
|
|
132
|
-
optional: true
|
|
133
|
-
}),
|
|
134
|
-
_ts_metadata("design:type", String)
|
|
135
|
-
], FileSchemaResizeData.prototype, "smallURL", void 0);
|
|
136
|
-
_ts_decorate([
|
|
137
|
-
Prop({
|
|
138
|
-
optional: true
|
|
139
|
-
}),
|
|
140
|
-
_ts_metadata("design:type", String)
|
|
141
|
-
], FileSchemaResizeData.prototype, "mediumURL", void 0);
|
|
142
|
-
_ts_decorate([
|
|
143
|
-
Prop({
|
|
144
|
-
optional: true
|
|
145
|
-
}),
|
|
146
|
-
_ts_metadata("design:type", String)
|
|
147
|
-
], FileSchemaResizeData.prototype, "largeURL", void 0);
|
|
148
|
-
_ts_decorate([
|
|
149
|
-
Prop({
|
|
150
|
-
optional: true
|
|
151
|
-
}),
|
|
152
|
-
_ts_metadata("design:type", String)
|
|
153
|
-
], FileSchemaResizeData.prototype, "extraLargeURL", void 0);
|
|
154
|
-
FileSchemaResizeData = _ts_decorate([
|
|
155
|
-
TypedSchema()
|
|
156
|
-
], FileSchemaResizeData);
|
|
157
|
-
var _FileSchemaDimensionsData = class _FileSchemaDimensionsData {
|
|
158
|
-
width;
|
|
159
|
-
height;
|
|
160
|
-
};
|
|
161
|
-
__name(_FileSchemaDimensionsData, "FileSchemaDimensionsData");
|
|
162
|
-
var FileSchemaDimensionsData = _FileSchemaDimensionsData;
|
|
163
|
-
_ts_decorate([
|
|
164
|
-
Prop({
|
|
165
|
-
optional: true
|
|
166
|
-
}),
|
|
167
|
-
_ts_metadata("design:type", Number)
|
|
168
|
-
], FileSchemaDimensionsData.prototype, "width", void 0);
|
|
169
|
-
_ts_decorate([
|
|
170
|
-
Prop({
|
|
171
|
-
optional: true
|
|
172
|
-
}),
|
|
173
|
-
_ts_metadata("design:type", Number)
|
|
174
|
-
], FileSchemaDimensionsData.prototype, "height", void 0);
|
|
175
|
-
FileSchemaDimensionsData = _ts_decorate([
|
|
176
|
-
TypedSchema()
|
|
177
|
-
], FileSchemaDimensionsData);
|
|
178
|
-
var _FileSchemaColorsData = class _FileSchemaColorsData {
|
|
179
|
-
front;
|
|
180
|
-
background;
|
|
181
|
-
blurhash;
|
|
182
|
-
};
|
|
183
|
-
__name(_FileSchemaColorsData, "FileSchemaColorsData");
|
|
184
|
-
var FileSchemaColorsData = _FileSchemaColorsData;
|
|
185
|
-
_ts_decorate([
|
|
186
|
-
Prop({
|
|
187
|
-
optional: true
|
|
188
|
-
}),
|
|
189
|
-
_ts_metadata("design:type", String)
|
|
190
|
-
], FileSchemaColorsData.prototype, "front", void 0);
|
|
191
|
-
_ts_decorate([
|
|
192
|
-
Prop({
|
|
193
|
-
optional: true
|
|
194
|
-
}),
|
|
195
|
-
_ts_metadata("design:type", String)
|
|
196
|
-
], FileSchemaColorsData.prototype, "background", void 0);
|
|
197
|
-
_ts_decorate([
|
|
198
|
-
Prop({
|
|
199
|
-
optional: true
|
|
200
|
-
}),
|
|
201
|
-
_ts_metadata("design:type", String)
|
|
202
|
-
], FileSchemaColorsData.prototype, "blurhash", void 0);
|
|
203
|
-
FileSchemaColorsData = _ts_decorate([
|
|
204
|
-
TypedSchema()
|
|
205
|
-
], FileSchemaColorsData);
|
|
206
|
-
var _FileSchema = class _FileSchema {
|
|
207
|
-
_id;
|
|
208
|
-
hash;
|
|
209
|
-
externalUrl;
|
|
210
|
-
key;
|
|
211
|
-
bucket;
|
|
212
|
-
name;
|
|
213
|
-
type;
|
|
214
|
-
size;
|
|
215
|
-
status;
|
|
216
|
-
createdBy;
|
|
217
|
-
createdAt;
|
|
218
|
-
dimensions;
|
|
219
|
-
resizedData;
|
|
220
|
-
colorsData;
|
|
98
|
+
var resolvers_default = {
|
|
99
|
+
url: url_default,
|
|
100
|
+
genericType: genericType_default
|
|
221
101
|
};
|
|
222
|
-
__name(_FileSchema, "FileSchema");
|
|
223
|
-
var FileSchema = _FileSchema;
|
|
224
|
-
_ts_decorate([
|
|
225
|
-
Prop({
|
|
226
|
-
type: "ID"
|
|
227
|
-
}),
|
|
228
|
-
_ts_metadata("design:type", String)
|
|
229
|
-
], FileSchema.prototype, "_id", void 0);
|
|
230
|
-
_ts_decorate([
|
|
231
|
-
Prop({
|
|
232
|
-
optional: true
|
|
233
|
-
}),
|
|
234
|
-
_ts_metadata("design:type", String)
|
|
235
|
-
], FileSchema.prototype, "hash", void 0);
|
|
236
|
-
_ts_decorate([
|
|
237
|
-
Prop({
|
|
238
|
-
optional: true,
|
|
239
|
-
private: true
|
|
240
|
-
}),
|
|
241
|
-
_ts_metadata("design:type", String)
|
|
242
|
-
], FileSchema.prototype, "externalUrl", void 0);
|
|
243
|
-
_ts_decorate([
|
|
244
|
-
Prop({
|
|
245
|
-
optional: true
|
|
246
|
-
}),
|
|
247
|
-
_ts_metadata("design:type", String)
|
|
248
|
-
], FileSchema.prototype, "key", void 0);
|
|
249
|
-
_ts_decorate([
|
|
250
|
-
Prop({
|
|
251
|
-
optional: true
|
|
252
|
-
}),
|
|
253
|
-
_ts_metadata("design:type", String)
|
|
254
|
-
], FileSchema.prototype, "bucket", void 0);
|
|
255
|
-
_ts_decorate([
|
|
256
|
-
Prop({
|
|
257
|
-
optional: true
|
|
258
|
-
}),
|
|
259
|
-
_ts_metadata("design:type", String)
|
|
260
|
-
], FileSchema.prototype, "name", void 0);
|
|
261
|
-
_ts_decorate([
|
|
262
|
-
Prop({
|
|
263
|
-
optional: true
|
|
264
|
-
}),
|
|
265
|
-
_ts_metadata("design:type", String)
|
|
266
|
-
], FileSchema.prototype, "type", void 0);
|
|
267
|
-
_ts_decorate([
|
|
268
|
-
Prop({
|
|
269
|
-
optional: true
|
|
270
|
-
}),
|
|
271
|
-
_ts_metadata("design:type", Number)
|
|
272
|
-
], FileSchema.prototype, "size", void 0);
|
|
273
|
-
_ts_decorate([
|
|
274
|
-
Prop({
|
|
275
|
-
optional: true
|
|
276
|
-
}),
|
|
277
|
-
_ts_metadata("design:type", String)
|
|
278
|
-
], FileSchema.prototype, "status", void 0);
|
|
279
|
-
_ts_decorate([
|
|
280
|
-
Prop({
|
|
281
|
-
optional: true
|
|
282
|
-
}),
|
|
283
|
-
_ts_metadata("design:type", String)
|
|
284
|
-
], FileSchema.prototype, "createdBy", void 0);
|
|
285
|
-
_ts_decorate([
|
|
286
|
-
Prop({
|
|
287
|
-
optional: true
|
|
288
|
-
}),
|
|
289
|
-
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
290
|
-
], FileSchema.prototype, "createdAt", void 0);
|
|
291
|
-
_ts_decorate([
|
|
292
|
-
Prop({
|
|
293
|
-
optional: true,
|
|
294
|
-
type: getModelForClass(FileSchemaDimensionsData)
|
|
295
|
-
}),
|
|
296
|
-
_ts_metadata("design:type", typeof FileSchemaDimensionsData === "undefined" ? Object : FileSchemaDimensionsData)
|
|
297
|
-
], FileSchema.prototype, "dimensions", void 0);
|
|
298
|
-
_ts_decorate([
|
|
299
|
-
Prop({
|
|
300
|
-
optional: true,
|
|
301
|
-
type: getModelForClass(FileSchemaResizeData)
|
|
302
|
-
}),
|
|
303
|
-
_ts_metadata("design:type", typeof FileSchemaResizeData === "undefined" ? Object : FileSchemaResizeData)
|
|
304
|
-
], FileSchema.prototype, "resizedData", void 0);
|
|
305
|
-
_ts_decorate([
|
|
306
|
-
Prop({
|
|
307
|
-
optional: true,
|
|
308
|
-
type: getModelForClass(FileSchemaColorsData)
|
|
309
|
-
}),
|
|
310
|
-
_ts_metadata("design:type", typeof FileSchemaColorsData === "undefined" ? Object : FileSchemaColorsData)
|
|
311
|
-
], FileSchema.prototype, "colorsData", void 0);
|
|
312
|
-
FileSchema = _ts_decorate([
|
|
313
|
-
TypedSchema()
|
|
314
|
-
], FileSchema);
|
|
315
|
-
|
|
316
|
-
// src/Files/index.ts
|
|
317
|
-
var Files = createCollection({
|
|
318
|
-
name: "filemanager_files",
|
|
319
|
-
model: File_default,
|
|
320
|
-
schema: FileSchema,
|
|
321
|
-
indexes: [
|
|
322
|
-
{
|
|
323
|
-
keys: {
|
|
324
|
-
key: 1,
|
|
325
|
-
bucket: 1
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
keys: {
|
|
330
|
-
hash: 1
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
]
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
// src/File/index.ts
|
|
337
|
-
import pick from "lodash/pick";
|
|
338
|
-
import omit from "lodash/omit";
|
|
339
|
-
import { getModelForClass as getModelForClass2 } from "@orion-js/typed-model";
|
|
340
102
|
|
|
341
103
|
// src/resolvers/generateImageInfo.ts
|
|
342
|
-
init_credentials();
|
|
343
104
|
import { isEmpty } from "lodash";
|
|
344
105
|
|
|
345
106
|
// src/File/resolvers/isImage.ts
|
|
@@ -350,7 +111,6 @@ function isImage(image) {
|
|
|
350
111
|
const mime = image.type;
|
|
351
112
|
return mime.includes("image");
|
|
352
113
|
}
|
|
353
|
-
__name(isImage, "isImage");
|
|
354
114
|
|
|
355
115
|
// src/resolvers/generateImageInfo.ts
|
|
356
116
|
async function generateImageInfo(file) {
|
|
@@ -362,11 +122,7 @@ async function generateImageInfo(file) {
|
|
|
362
122
|
try {
|
|
363
123
|
file.dimensions = await options.getImageDimensions(file);
|
|
364
124
|
if (!isEmpty(file.dimensions)) {
|
|
365
|
-
await Files.updateOne(file._id, {
|
|
366
|
-
$set: {
|
|
367
|
-
dimensions: file.dimensions
|
|
368
|
-
}
|
|
369
|
-
});
|
|
125
|
+
await Files.updateOne(file._id, { $set: { dimensions: file.dimensions } });
|
|
370
126
|
}
|
|
371
127
|
} catch (error) {
|
|
372
128
|
console.error("Error getting image dimensions", error);
|
|
@@ -376,11 +132,7 @@ async function generateImageInfo(file) {
|
|
|
376
132
|
try {
|
|
377
133
|
file.resizedData = await options.getResizedImages(file);
|
|
378
134
|
if (!isEmpty(file.resizedData)) {
|
|
379
|
-
await Files.updateOne(file._id, {
|
|
380
|
-
$set: {
|
|
381
|
-
resizedData: file.resizedData
|
|
382
|
-
}
|
|
383
|
-
});
|
|
135
|
+
await Files.updateOne(file._id, { $set: { resizedData: file.resizedData } });
|
|
384
136
|
}
|
|
385
137
|
} catch (error) {
|
|
386
138
|
console.error("Error getting resized images", error);
|
|
@@ -390,11 +142,7 @@ async function generateImageInfo(file) {
|
|
|
390
142
|
try {
|
|
391
143
|
file.colorsData = await options.getImageColors(file);
|
|
392
144
|
if (!isEmpty(file.colorsData)) {
|
|
393
|
-
await Files.updateOne(file._id, {
|
|
394
|
-
$set: {
|
|
395
|
-
colorsData: file.colorsData
|
|
396
|
-
}
|
|
397
|
-
});
|
|
145
|
+
await Files.updateOne(file._id, { $set: { colorsData: file.colorsData } });
|
|
398
146
|
}
|
|
399
147
|
} catch (error) {
|
|
400
148
|
console.error("Error getting image colors", error);
|
|
@@ -402,37 +150,161 @@ async function generateImageInfo(file) {
|
|
|
402
150
|
}
|
|
403
151
|
}
|
|
404
152
|
}
|
|
405
|
-
__name(generateImageInfo, "generateImageInfo");
|
|
406
153
|
|
|
407
|
-
// src/File/
|
|
408
|
-
|
|
409
|
-
|
|
154
|
+
// src/File/schema.ts
|
|
155
|
+
import { pick } from "lodash";
|
|
156
|
+
|
|
157
|
+
// src/File/getFileData.ts
|
|
158
|
+
import { createCollection } from "@orion-js/mongodb";
|
|
159
|
+
var readOnlyCollection = createCollection({ name: "filemanager_files" });
|
|
160
|
+
async function getFileData(fileId) {
|
|
161
|
+
const file = await readOnlyCollection.findOne({ _id: fileId });
|
|
162
|
+
return file;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/File/schema.ts
|
|
166
|
+
var _extraLargeURL_dec, _largeURL_dec, _mediumURL_dec, _smallURL_dec, _thumbnailURL_dec, _FileSchemaResizeData_decorators, _init;
|
|
167
|
+
_FileSchemaResizeData_decorators = [TypedSchema()], _thumbnailURL_dec = [Prop({ optional: true, type: "string" })], _smallURL_dec = [Prop({ optional: true, type: "string" })], _mediumURL_dec = [Prop({ optional: true, type: "string" })], _largeURL_dec = [Prop({ optional: true, type: "string" })], _extraLargeURL_dec = [Prop({ optional: true, type: "string" })];
|
|
168
|
+
var FileSchemaResizeData = class {
|
|
169
|
+
constructor() {
|
|
170
|
+
__publicField(this, "thumbnailURL", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
171
|
+
__publicField(this, "smallURL", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
|
|
172
|
+
__publicField(this, "mediumURL", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
|
|
173
|
+
__publicField(this, "largeURL", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
|
|
174
|
+
__publicField(this, "extraLargeURL", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
|
|
175
|
+
}
|
|
176
|
+
// 2400 height max
|
|
177
|
+
};
|
|
178
|
+
_init = __decoratorStart(null);
|
|
179
|
+
__decorateElement(_init, 5, "thumbnailURL", _thumbnailURL_dec, FileSchemaResizeData);
|
|
180
|
+
__decorateElement(_init, 5, "smallURL", _smallURL_dec, FileSchemaResizeData);
|
|
181
|
+
__decorateElement(_init, 5, "mediumURL", _mediumURL_dec, FileSchemaResizeData);
|
|
182
|
+
__decorateElement(_init, 5, "largeURL", _largeURL_dec, FileSchemaResizeData);
|
|
183
|
+
__decorateElement(_init, 5, "extraLargeURL", _extraLargeURL_dec, FileSchemaResizeData);
|
|
184
|
+
FileSchemaResizeData = __decorateElement(_init, 0, "FileSchemaResizeData", _FileSchemaResizeData_decorators, FileSchemaResizeData);
|
|
185
|
+
__runInitializers(_init, 1, FileSchemaResizeData);
|
|
186
|
+
var _height_dec, _width_dec, _FileSchemaDimensionsData_decorators, _init2;
|
|
187
|
+
_FileSchemaDimensionsData_decorators = [TypedSchema()], _width_dec = [Prop({ optional: true, type: "number" })], _height_dec = [Prop({ optional: true, type: "number" })];
|
|
188
|
+
var FileSchemaDimensionsData = class {
|
|
189
|
+
constructor() {
|
|
190
|
+
__publicField(this, "width", __runInitializers(_init2, 8, this)), __runInitializers(_init2, 11, this);
|
|
191
|
+
__publicField(this, "height", __runInitializers(_init2, 12, this)), __runInitializers(_init2, 15, this);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
_init2 = __decoratorStart(null);
|
|
195
|
+
__decorateElement(_init2, 5, "width", _width_dec, FileSchemaDimensionsData);
|
|
196
|
+
__decorateElement(_init2, 5, "height", _height_dec, FileSchemaDimensionsData);
|
|
197
|
+
FileSchemaDimensionsData = __decorateElement(_init2, 0, "FileSchemaDimensionsData", _FileSchemaDimensionsData_decorators, FileSchemaDimensionsData);
|
|
198
|
+
__runInitializers(_init2, 1, FileSchemaDimensionsData);
|
|
199
|
+
var _blurhash_dec, _background_dec, _front_dec, _FileSchemaColorsData_decorators, _init3;
|
|
200
|
+
_FileSchemaColorsData_decorators = [TypedSchema()], _front_dec = [Prop({ optional: true, type: "string" })], _background_dec = [Prop({ optional: true, type: "string" })], _blurhash_dec = [Prop({ optional: true, type: "string" })];
|
|
201
|
+
var FileSchemaColorsData = class {
|
|
202
|
+
constructor() {
|
|
203
|
+
__publicField(this, "front", __runInitializers(_init3, 8, this)), __runInitializers(_init3, 11, this);
|
|
204
|
+
__publicField(this, "background", __runInitializers(_init3, 12, this)), __runInitializers(_init3, 15, this);
|
|
205
|
+
__publicField(this, "blurhash", __runInitializers(_init3, 16, this)), __runInitializers(_init3, 19, this);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
_init3 = __decoratorStart(null);
|
|
209
|
+
__decorateElement(_init3, 5, "front", _front_dec, FileSchemaColorsData);
|
|
210
|
+
__decorateElement(_init3, 5, "background", _background_dec, FileSchemaColorsData);
|
|
211
|
+
__decorateElement(_init3, 5, "blurhash", _blurhash_dec, FileSchemaColorsData);
|
|
212
|
+
FileSchemaColorsData = __decorateElement(_init3, 0, "FileSchemaColorsData", _FileSchemaColorsData_decorators, FileSchemaColorsData);
|
|
213
|
+
__runInitializers(_init3, 1, FileSchemaColorsData);
|
|
214
|
+
var _colorsData_dec, _resizedData_dec, _dimensions_dec, _createdAt_dec, _createdBy_dec, _status_dec, _size_dec, _type_dec, _name_dec, _bucket_dec, _key_dec, _externalUrl_dec, _hash_dec, __id_dec, _FileSchema_decorators, _init4;
|
|
215
|
+
_FileSchema_decorators = [TypedSchema({
|
|
410
216
|
name: "File",
|
|
411
|
-
|
|
412
|
-
resolvers: /* @__PURE__ */ __name(() => (init_resolvers(), __toCommonJS(resolvers_exports)), "resolvers"),
|
|
217
|
+
resolvers: resolvers_default,
|
|
413
218
|
// this is only called when its child
|
|
414
219
|
async clean(value) {
|
|
415
220
|
if (!value) return null;
|
|
416
221
|
const fileId = value._id;
|
|
417
|
-
const file = await
|
|
418
|
-
_id: fileId
|
|
419
|
-
});
|
|
222
|
+
const file = await getFileData(fileId);
|
|
420
223
|
if (!file) return null;
|
|
421
224
|
await generateImageInfo(file);
|
|
422
|
-
const keys =
|
|
225
|
+
const keys = [
|
|
226
|
+
"_id",
|
|
227
|
+
"hash",
|
|
228
|
+
"externalUrl",
|
|
229
|
+
"key",
|
|
230
|
+
"bucket",
|
|
231
|
+
"name",
|
|
232
|
+
"type",
|
|
233
|
+
"size",
|
|
234
|
+
// 'status',
|
|
235
|
+
// 'createdBy',
|
|
236
|
+
// 'createdAt',
|
|
237
|
+
"dimensions",
|
|
238
|
+
"resizedData",
|
|
239
|
+
"colorsData"
|
|
240
|
+
];
|
|
423
241
|
const data = pick(file, keys);
|
|
424
242
|
return data;
|
|
425
243
|
}
|
|
244
|
+
})], __id_dec = [Prop({ type: "ID" })], _hash_dec = [Prop({ optional: true, type: "string" })], _externalUrl_dec = [Prop({ optional: true, type: "string" })], _key_dec = [Prop({ optional: true, type: "string" })], _bucket_dec = [Prop({ optional: true, type: "string" })], _name_dec = [Prop({ optional: true, type: "string" })], _type_dec = [Prop({ optional: true, type: "string" })], _size_dec = [Prop({ optional: true, type: "number" })], _status_dec = [Prop({ optional: true, type: "string" })], _createdBy_dec = [Prop({ optional: true, type: "string" })], _createdAt_dec = [Prop({ optional: true, type: Date })], _dimensions_dec = [Prop({ optional: true, type: FileSchemaDimensionsData })], _resizedData_dec = [Prop({ optional: true, type: FileSchemaResizeData })], _colorsData_dec = [Prop({ optional: true, type: FileSchemaColorsData })];
|
|
245
|
+
var FileSchema = class {
|
|
246
|
+
constructor() {
|
|
247
|
+
__publicField(this, "_id", __runInitializers(_init4, 8, this)), __runInitializers(_init4, 11, this);
|
|
248
|
+
__publicField(this, "hash", __runInitializers(_init4, 12, this)), __runInitializers(_init4, 15, this);
|
|
249
|
+
__publicField(this, "externalUrl", __runInitializers(_init4, 16, this)), __runInitializers(_init4, 19, this);
|
|
250
|
+
__publicField(this, "key", __runInitializers(_init4, 20, this)), __runInitializers(_init4, 23, this);
|
|
251
|
+
__publicField(this, "bucket", __runInitializers(_init4, 24, this)), __runInitializers(_init4, 27, this);
|
|
252
|
+
__publicField(this, "name", __runInitializers(_init4, 28, this)), __runInitializers(_init4, 31, this);
|
|
253
|
+
__publicField(this, "type", __runInitializers(_init4, 32, this)), __runInitializers(_init4, 35, this);
|
|
254
|
+
__publicField(this, "size", __runInitializers(_init4, 36, this)), __runInitializers(_init4, 39, this);
|
|
255
|
+
__publicField(this, "status", __runInitializers(_init4, 40, this)), __runInitializers(_init4, 43, this);
|
|
256
|
+
__publicField(this, "createdBy", __runInitializers(_init4, 44, this)), __runInitializers(_init4, 47, this);
|
|
257
|
+
__publicField(this, "createdAt", __runInitializers(_init4, 48, this)), __runInitializers(_init4, 51, this);
|
|
258
|
+
__publicField(this, "dimensions", __runInitializers(_init4, 52, this)), __runInitializers(_init4, 55, this);
|
|
259
|
+
__publicField(this, "resizedData", __runInitializers(_init4, 56, this)), __runInitializers(_init4, 59, this);
|
|
260
|
+
__publicField(this, "colorsData", __runInitializers(_init4, 60, this)), __runInitializers(_init4, 63, this);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
_init4 = __decoratorStart(null);
|
|
264
|
+
__decorateElement(_init4, 5, "_id", __id_dec, FileSchema);
|
|
265
|
+
__decorateElement(_init4, 5, "hash", _hash_dec, FileSchema);
|
|
266
|
+
__decorateElement(_init4, 5, "externalUrl", _externalUrl_dec, FileSchema);
|
|
267
|
+
__decorateElement(_init4, 5, "key", _key_dec, FileSchema);
|
|
268
|
+
__decorateElement(_init4, 5, "bucket", _bucket_dec, FileSchema);
|
|
269
|
+
__decorateElement(_init4, 5, "name", _name_dec, FileSchema);
|
|
270
|
+
__decorateElement(_init4, 5, "type", _type_dec, FileSchema);
|
|
271
|
+
__decorateElement(_init4, 5, "size", _size_dec, FileSchema);
|
|
272
|
+
__decorateElement(_init4, 5, "status", _status_dec, FileSchema);
|
|
273
|
+
__decorateElement(_init4, 5, "createdBy", _createdBy_dec, FileSchema);
|
|
274
|
+
__decorateElement(_init4, 5, "createdAt", _createdAt_dec, FileSchema);
|
|
275
|
+
__decorateElement(_init4, 5, "dimensions", _dimensions_dec, FileSchema);
|
|
276
|
+
__decorateElement(_init4, 5, "resizedData", _resizedData_dec, FileSchema);
|
|
277
|
+
__decorateElement(_init4, 5, "colorsData", _colorsData_dec, FileSchema);
|
|
278
|
+
FileSchema = __decorateElement(_init4, 0, "FileSchema", _FileSchema_decorators, FileSchema);
|
|
279
|
+
__runInitializers(_init4, 1, FileSchema);
|
|
280
|
+
|
|
281
|
+
// src/Files/index.ts
|
|
282
|
+
var Files = createCollection2({
|
|
283
|
+
name: "filemanager_files",
|
|
284
|
+
schema: FileSchema,
|
|
285
|
+
indexes: [
|
|
286
|
+
{
|
|
287
|
+
keys: {
|
|
288
|
+
key: 1,
|
|
289
|
+
bucket: 1
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
keys: {
|
|
294
|
+
hash: 1
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
]
|
|
426
298
|
});
|
|
427
299
|
|
|
428
300
|
// src/resolvers/fileManagerFile.ts
|
|
429
|
-
var fileManagerFile_default =
|
|
301
|
+
var fileManagerFile_default = createResolver({
|
|
430
302
|
params: {
|
|
431
303
|
fileId: {
|
|
432
304
|
type: "ID"
|
|
433
305
|
}
|
|
434
306
|
},
|
|
435
|
-
returns:
|
|
307
|
+
returns: FileSchema,
|
|
436
308
|
async resolve({ fileId }) {
|
|
437
309
|
return await Files.findOne(fileId);
|
|
438
310
|
}
|
|
@@ -448,16 +320,12 @@ var fileManagerFiles = paginatedResolver({
|
|
|
448
320
|
optional: true
|
|
449
321
|
}
|
|
450
322
|
},
|
|
451
|
-
returns:
|
|
323
|
+
returns: FileSchema,
|
|
452
324
|
async getCursor({ filter }, viewer) {
|
|
453
|
-
const query = {
|
|
454
|
-
status: "uploaded"
|
|
455
|
-
};
|
|
325
|
+
const query = { status: "uploaded" };
|
|
456
326
|
query.createdBy = viewer.userId;
|
|
457
327
|
if (filter) {
|
|
458
|
-
query.name = {
|
|
459
|
-
$regex: new RegExp(`^${escapeString(filter)}`)
|
|
460
|
-
};
|
|
328
|
+
query.name = { $regex: new RegExp(`^${escapeString(filter)}`) };
|
|
461
329
|
}
|
|
462
330
|
return Files.find(query);
|
|
463
331
|
}
|
|
@@ -465,37 +333,29 @@ var fileManagerFiles = paginatedResolver({
|
|
|
465
333
|
var fileManagerFiles_default = fileManagerFiles;
|
|
466
334
|
|
|
467
335
|
// src/resolvers/completeUpload.ts
|
|
468
|
-
import {
|
|
469
|
-
var completeUpload_default =
|
|
336
|
+
import { createResolver as createResolver2 } from "@orion-js/resolvers";
|
|
337
|
+
var completeUpload_default = createResolver2({
|
|
470
338
|
params: {
|
|
471
339
|
fileId: {
|
|
472
340
|
type: "ID"
|
|
473
341
|
}
|
|
474
342
|
},
|
|
475
|
-
returns:
|
|
343
|
+
returns: FileSchema,
|
|
476
344
|
mutation: true,
|
|
477
345
|
async resolve({ fileId }, viewer) {
|
|
478
|
-
const file = await Files.findOne({
|
|
479
|
-
|
|
480
|
-
_id: fileId
|
|
481
|
-
});
|
|
482
|
-
await Files.updateOne(file, {
|
|
483
|
-
$set: {
|
|
484
|
-
status: "uploaded"
|
|
485
|
-
}
|
|
486
|
-
});
|
|
346
|
+
const file = await Files.findOne({ createdBy: viewer.userId, _id: fileId });
|
|
347
|
+
await Files.updateOne(file, { $set: { status: "uploaded" } });
|
|
487
348
|
await generateImageInfo(file);
|
|
488
349
|
return file;
|
|
489
350
|
}
|
|
490
351
|
});
|
|
491
352
|
|
|
492
353
|
// src/resolvers/generateUploadCredentials.ts
|
|
493
|
-
|
|
494
|
-
import { resolver as resolver3 } from "@orion-js/resolvers";
|
|
354
|
+
import { resolver } from "@orion-js/resolvers";
|
|
495
355
|
import { generateId, generateUUID } from "@orion-js/helpers";
|
|
496
|
-
import { createModel
|
|
356
|
+
import { createModel } from "@orion-js/models";
|
|
497
357
|
import AWS from "aws-sdk";
|
|
498
|
-
var generateUploadCredentials =
|
|
358
|
+
var generateUploadCredentials = resolver({
|
|
499
359
|
params: {
|
|
500
360
|
name: {
|
|
501
361
|
type: String
|
|
@@ -507,7 +367,7 @@ var generateUploadCredentials = resolver3({
|
|
|
507
367
|
type: String
|
|
508
368
|
}
|
|
509
369
|
},
|
|
510
|
-
returns:
|
|
370
|
+
returns: createModel({
|
|
511
371
|
name: "UploadCredentials",
|
|
512
372
|
schema: {
|
|
513
373
|
fileId: {
|
|
@@ -526,7 +386,16 @@ var generateUploadCredentials = resolver3({
|
|
|
526
386
|
}),
|
|
527
387
|
mutation: true,
|
|
528
388
|
async resolve(params, viewer) {
|
|
529
|
-
const {
|
|
389
|
+
const {
|
|
390
|
+
accessKeyId,
|
|
391
|
+
secretAccessKey,
|
|
392
|
+
region,
|
|
393
|
+
bucket,
|
|
394
|
+
endpoint,
|
|
395
|
+
s3ForcePathStyle,
|
|
396
|
+
canUpload,
|
|
397
|
+
basePath
|
|
398
|
+
} = getAWSCredentials();
|
|
530
399
|
const s3 = new AWS.S3({
|
|
531
400
|
accessKeyId,
|
|
532
401
|
secretAccessKey,
|
|
@@ -550,33 +419,26 @@ var generateUploadCredentials = resolver3({
|
|
|
550
419
|
createdAt: /* @__PURE__ */ new Date()
|
|
551
420
|
});
|
|
552
421
|
const result = await new Promise((resolve, reject) => {
|
|
553
|
-
s3.createPresignedPost(
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
[
|
|
557
|
-
"content-length-range",
|
|
558
|
-
params.
|
|
559
|
-
|
|
422
|
+
s3.createPresignedPost(
|
|
423
|
+
{
|
|
424
|
+
Bucket: bucket,
|
|
425
|
+
Conditions: [
|
|
426
|
+
["content-length-range", params.size, params.size],
|
|
427
|
+
{ "Content-Type": params.type },
|
|
428
|
+
{ "Cache-Control": "public, max-age=31536000, immutable" },
|
|
429
|
+
{ Key: key }
|
|
560
430
|
],
|
|
561
|
-
{
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
{
|
|
431
|
+
Fields: {
|
|
432
|
+
key,
|
|
433
|
+
"Content-Type": params.type,
|
|
565
434
|
"Cache-Control": "public, max-age=31536000, immutable"
|
|
566
|
-
},
|
|
567
|
-
{
|
|
568
|
-
Key: key
|
|
569
435
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
"Cache-Control": "public, max-age=31536000, immutable"
|
|
436
|
+
},
|
|
437
|
+
function(error, data) {
|
|
438
|
+
if (error) reject(error);
|
|
439
|
+
else resolve(data);
|
|
575
440
|
}
|
|
576
|
-
|
|
577
|
-
if (error) reject(error);
|
|
578
|
-
else resolve(data);
|
|
579
|
-
});
|
|
441
|
+
);
|
|
580
442
|
});
|
|
581
443
|
return {
|
|
582
444
|
fileId,
|
|
@@ -594,12 +456,7 @@ var resolvers = {
|
|
|
594
456
|
generateUploadCredentials
|
|
595
457
|
};
|
|
596
458
|
var resolvers_default2 = resolvers;
|
|
597
|
-
|
|
598
|
-
// src/index.ts
|
|
599
|
-
init_credentials();
|
|
600
|
-
init_url();
|
|
601
459
|
export {
|
|
602
|
-
File_default as File,
|
|
603
460
|
FileSchema,
|
|
604
461
|
Files,
|
|
605
462
|
getAWSCredentials,
|