graphile-upload-plugin 1.1.0 → 2.2.0

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,62 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Uploader = void 0;
7
- const s3_streamer_1 = __importDefault(require("@constructive-io/s3-streamer"));
8
- const upload_names_1 = __importDefault(require("@constructive-io/upload-names"));
9
- class Uploader {
10
- opts;
11
- streamerInstance;
12
- constructor(opts) {
13
- this.opts = opts;
14
- const { bucketName, awsRegion, awsSecretKey, awsAccessKey, minioEndpoint, provider } = this.opts;
15
- this.streamerInstance = new s3_streamer_1.default({
16
- defaultBucket: bucketName,
17
- awsRegion,
18
- awsSecretKey,
19
- awsAccessKey,
20
- minioEndpoint,
21
- provider,
22
- });
23
- }
24
- async resolveUpload(upload, _args, _context, info) {
25
- const { uploadPlugin: { tags, type } } = info;
26
- const readStream = upload.createReadStream();
27
- const { filename } = upload;
28
- const rand = Math.random().toString(36).substring(2, 7) +
29
- Math.random().toString(36).substring(2, 7);
30
- const key = `${rand}-${(0, upload_names_1.default)(filename)}`;
31
- const result = await this.streamerInstance.upload({
32
- readStream,
33
- filename,
34
- key,
35
- bucket: this.opts.bucketName
36
- });
37
- const url = result.upload.Location;
38
- const { contentType, magic: { charset } } = result;
39
- const typ = type || tags.type;
40
- const allowedMimes = tags.mime
41
- ? tags.mime.trim().split(',').map((a) => a.trim())
42
- : typ === 'image'
43
- ? ['image/jpg', 'image/jpeg', 'image/png', 'image/svg+xml']
44
- : [];
45
- if (allowedMimes.length && !allowedMimes.includes(contentType)) {
46
- throw new Error(`UPLOAD_MIMETYPE ${allowedMimes.join(',')}`);
47
- }
48
- switch (typ) {
49
- case 'image':
50
- case 'upload':
51
- return {
52
- filename,
53
- mime: contentType,
54
- url
55
- };
56
- case 'attachment':
57
- default:
58
- return url;
59
- }
60
- }
61
- }
62
- exports.Uploader = Uploader;