importer-storage 1.0.7 → 1.0.8

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/dist/index.cjs CHANGED
@@ -92,46 +92,57 @@ var S3Storage = class {
92
92
  saveFiles(keys, options) {
93
93
  return __async(this, null, function* () {
94
94
  const result = [];
95
+ const errored = [];
95
96
  for (const { key, filePath } of keys) {
96
- const s3Key = `${options.savePath}/${key}`;
97
- let stream = void 0;
98
- let buffer = void 0;
99
- if (isHttp(filePath)) {
100
- const axiosResponse = yield import_axios.default.get(filePath, {
101
- responseType: "arraybuffer",
102
- headers: options.headers
97
+ try {
98
+ const s3Key = `${options.savePath}/${key}`;
99
+ let stream = void 0;
100
+ let buffer = void 0;
101
+ if (isHttp(filePath)) {
102
+ const axiosResponse = yield import_axios.default.get(filePath, {
103
+ responseType: "arraybuffer",
104
+ headers: options.headers
105
+ });
106
+ buffer = Buffer.from(axiosResponse.data);
107
+ } else {
108
+ stream = (0, import_fs.createReadStream)(filePath);
109
+ }
110
+ const tagString = options.tags.map(
111
+ (tag) => `${encodeURIComponent(tag.split(":")[0])}=${encodeURIComponent(tag.split(":")[1])}`
112
+ ).join("&");
113
+ if (!stream && !buffer) {
114
+ throw new Error("buffer or stream not set");
115
+ }
116
+ const image = buffer ? yield import_jimp.Jimp.fromBuffer(buffer) : yield import_jimp.Jimp.read(filePath);
117
+ const command = new import_client_s3.PutObjectCommand({
118
+ Body: buffer || stream,
119
+ Bucket: BUCKET_NAME,
120
+ Key: s3Key,
121
+ Tagging: tagString || void 0,
122
+ ContentType: `image/${extractFileInfo(key).extension}`,
123
+ ContentDisposition: "inline",
124
+ Metadata: {
125
+ "img-width": image.width.toString(),
126
+ "img-height": image.height.toString()
127
+ }
128
+ });
129
+ result.push({
130
+ key,
131
+ filePath,
132
+ uploadUrl: `https://${BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${s3Key}`
133
+ });
134
+ yield s3.send(command);
135
+ } catch (e) {
136
+ const error = e;
137
+ console.warn(error.message);
138
+ errored.push({
139
+ key,
140
+ filePath,
141
+ message: error.message
103
142
  });
104
- buffer = Buffer.from(axiosResponse.data);
105
- } else {
106
- stream = (0, import_fs.createReadStream)(filePath);
107
- }
108
- const tagString = options.tags.map(
109
- (tag) => `${encodeURIComponent(tag.split(":")[0])}=${encodeURIComponent(tag.split(":")[1])}`
110
- ).join("&");
111
- if (!stream && !buffer) {
112
- throw new Error("buffer or stream not set");
113
143
  }
114
- const image = buffer ? yield import_jimp.Jimp.fromBuffer(buffer) : yield import_jimp.Jimp.read(filePath);
115
- const command = new import_client_s3.PutObjectCommand({
116
- Body: buffer || stream,
117
- Bucket: BUCKET_NAME,
118
- Key: s3Key,
119
- Tagging: tagString || void 0,
120
- ContentType: `image/${extractFileInfo(key).extension}`,
121
- ContentDisposition: "inline",
122
- Metadata: {
123
- "img-width": image.width.toString(),
124
- "img-height": image.height.toString()
125
- }
126
- });
127
- result.push({
128
- key,
129
- filePath,
130
- uploadUrl: `https://${BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${s3Key}`
131
- });
132
- yield s3.send(command);
133
144
  }
134
- return { result };
145
+ return { result, errored };
135
146
  });
136
147
  }
137
148
  removeTag(savePath, tags) {
package/dist/index.d.cts CHANGED
@@ -8,6 +8,11 @@ interface IStorage {
8
8
  tags: Array<StorageTag>;
9
9
  savePath: string;
10
10
  }): Promise<{
11
+ errored: Array<{
12
+ key: string;
13
+ filePath: string;
14
+ message: string;
15
+ }>;
11
16
  result: Array<{
12
17
  key: string;
13
18
  filePath: string;
@@ -31,6 +36,11 @@ declare class S3Storage implements IStorage {
31
36
  filePath: string;
32
37
  uploadUrl: string;
33
38
  }[];
39
+ errored: {
40
+ key: string;
41
+ filePath: string;
42
+ message: string;
43
+ }[];
34
44
  }>;
35
45
  removeTag(savePath: string, tags: Array<StorageTag>): Promise<void>;
36
46
  }
package/dist/index.d.ts CHANGED
@@ -8,6 +8,11 @@ interface IStorage {
8
8
  tags: Array<StorageTag>;
9
9
  savePath: string;
10
10
  }): Promise<{
11
+ errored: Array<{
12
+ key: string;
13
+ filePath: string;
14
+ message: string;
15
+ }>;
11
16
  result: Array<{
12
17
  key: string;
13
18
  filePath: string;
@@ -31,6 +36,11 @@ declare class S3Storage implements IStorage {
31
36
  filePath: string;
32
37
  uploadUrl: string;
33
38
  }[];
39
+ errored: {
40
+ key: string;
41
+ filePath: string;
42
+ message: string;
43
+ }[];
34
44
  }>;
35
45
  removeTag(savePath: string, tags: Array<StorageTag>): Promise<void>;
36
46
  }
@@ -76245,46 +76245,57 @@ For more information please go to https://github.com/aws/aws-sdk-js-v3#functiona
76245
76245
  saveFiles(keys, options) {
76246
76246
  return __async(this, null, function* () {
76247
76247
  const result = [];
76248
+ const errored = [];
76248
76249
  for (const { key, filePath } of keys) {
76249
- const s3Key = `${options.savePath}/${key}`;
76250
- let stream5 = void 0;
76251
- let buffer = void 0;
76252
- if (isHttp(filePath)) {
76253
- const axiosResponse = yield axios_default.get(filePath, {
76254
- responseType: "arraybuffer",
76255
- headers: options.headers
76250
+ try {
76251
+ const s3Key = `${options.savePath}/${key}`;
76252
+ let stream5 = void 0;
76253
+ let buffer = void 0;
76254
+ if (isHttp(filePath)) {
76255
+ const axiosResponse = yield axios_default.get(filePath, {
76256
+ responseType: "arraybuffer",
76257
+ headers: options.headers
76258
+ });
76259
+ buffer = Buffer.from(axiosResponse.data);
76260
+ } else {
76261
+ stream5 = (0, import_fs8.createReadStream)(filePath);
76262
+ }
76263
+ const tagString = options.tags.map(
76264
+ (tag) => `${encodeURIComponent(tag.split(":")[0])}=${encodeURIComponent(tag.split(":")[1])}`
76265
+ ).join("&");
76266
+ if (!stream5 && !buffer) {
76267
+ throw new Error("buffer or stream not set");
76268
+ }
76269
+ const image2 = buffer ? yield Jimp.fromBuffer(buffer) : yield Jimp.read(filePath);
76270
+ const command = new PutObjectCommand({
76271
+ Body: buffer || stream5,
76272
+ Bucket: BUCKET_NAME,
76273
+ Key: s3Key,
76274
+ Tagging: tagString || void 0,
76275
+ ContentType: `image/${extractFileInfo(key).extension}`,
76276
+ ContentDisposition: "inline",
76277
+ Metadata: {
76278
+ "img-width": image2.width.toString(),
76279
+ "img-height": image2.height.toString()
76280
+ }
76281
+ });
76282
+ result.push({
76283
+ key,
76284
+ filePath,
76285
+ uploadUrl: `https://${BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${s3Key}`
76286
+ });
76287
+ yield s32.send(command);
76288
+ } catch (e5) {
76289
+ const error = e5;
76290
+ console.warn(error.message);
76291
+ errored.push({
76292
+ key,
76293
+ filePath,
76294
+ message: error.message
76256
76295
  });
76257
- buffer = Buffer.from(axiosResponse.data);
76258
- } else {
76259
- stream5 = (0, import_fs8.createReadStream)(filePath);
76260
- }
76261
- const tagString = options.tags.map(
76262
- (tag) => `${encodeURIComponent(tag.split(":")[0])}=${encodeURIComponent(tag.split(":")[1])}`
76263
- ).join("&");
76264
- if (!stream5 && !buffer) {
76265
- throw new Error("buffer or stream not set");
76266
76296
  }
76267
- const image2 = buffer ? yield Jimp.fromBuffer(buffer) : yield Jimp.read(filePath);
76268
- const command = new PutObjectCommand({
76269
- Body: buffer || stream5,
76270
- Bucket: BUCKET_NAME,
76271
- Key: s3Key,
76272
- Tagging: tagString || void 0,
76273
- ContentType: `image/${extractFileInfo(key).extension}`,
76274
- ContentDisposition: "inline",
76275
- Metadata: {
76276
- "img-width": image2.width.toString(),
76277
- "img-height": image2.height.toString()
76278
- }
76279
- });
76280
- result.push({
76281
- key,
76282
- filePath,
76283
- uploadUrl: `https://${BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${s3Key}`
76284
- });
76285
- yield s32.send(command);
76286
76297
  }
76287
- return { result };
76298
+ return { result, errored };
76288
76299
  });
76289
76300
  }
76290
76301
  removeTag(savePath, tags) {
package/dist/index.js CHANGED
@@ -63,46 +63,57 @@ var S3Storage = class {
63
63
  saveFiles(keys, options) {
64
64
  return __async(this, null, function* () {
65
65
  const result = [];
66
+ const errored = [];
66
67
  for (const { key, filePath } of keys) {
67
- const s3Key = `${options.savePath}/${key}`;
68
- let stream = void 0;
69
- let buffer = void 0;
70
- if (isHttp(filePath)) {
71
- const axiosResponse = yield axios.get(filePath, {
72
- responseType: "arraybuffer",
73
- headers: options.headers
68
+ try {
69
+ const s3Key = `${options.savePath}/${key}`;
70
+ let stream = void 0;
71
+ let buffer = void 0;
72
+ if (isHttp(filePath)) {
73
+ const axiosResponse = yield axios.get(filePath, {
74
+ responseType: "arraybuffer",
75
+ headers: options.headers
76
+ });
77
+ buffer = Buffer.from(axiosResponse.data);
78
+ } else {
79
+ stream = createReadStream(filePath);
80
+ }
81
+ const tagString = options.tags.map(
82
+ (tag) => `${encodeURIComponent(tag.split(":")[0])}=${encodeURIComponent(tag.split(":")[1])}`
83
+ ).join("&");
84
+ if (!stream && !buffer) {
85
+ throw new Error("buffer or stream not set");
86
+ }
87
+ const image = buffer ? yield Jimp.fromBuffer(buffer) : yield Jimp.read(filePath);
88
+ const command = new PutObjectCommand({
89
+ Body: buffer || stream,
90
+ Bucket: BUCKET_NAME,
91
+ Key: s3Key,
92
+ Tagging: tagString || void 0,
93
+ ContentType: `image/${extractFileInfo(key).extension}`,
94
+ ContentDisposition: "inline",
95
+ Metadata: {
96
+ "img-width": image.width.toString(),
97
+ "img-height": image.height.toString()
98
+ }
99
+ });
100
+ result.push({
101
+ key,
102
+ filePath,
103
+ uploadUrl: `https://${BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${s3Key}`
104
+ });
105
+ yield s3.send(command);
106
+ } catch (e) {
107
+ const error = e;
108
+ console.warn(error.message);
109
+ errored.push({
110
+ key,
111
+ filePath,
112
+ message: error.message
74
113
  });
75
- buffer = Buffer.from(axiosResponse.data);
76
- } else {
77
- stream = createReadStream(filePath);
78
- }
79
- const tagString = options.tags.map(
80
- (tag) => `${encodeURIComponent(tag.split(":")[0])}=${encodeURIComponent(tag.split(":")[1])}`
81
- ).join("&");
82
- if (!stream && !buffer) {
83
- throw new Error("buffer or stream not set");
84
114
  }
85
- const image = buffer ? yield Jimp.fromBuffer(buffer) : yield Jimp.read(filePath);
86
- const command = new PutObjectCommand({
87
- Body: buffer || stream,
88
- Bucket: BUCKET_NAME,
89
- Key: s3Key,
90
- Tagging: tagString || void 0,
91
- ContentType: `image/${extractFileInfo(key).extension}`,
92
- ContentDisposition: "inline",
93
- Metadata: {
94
- "img-width": image.width.toString(),
95
- "img-height": image.height.toString()
96
- }
97
- });
98
- result.push({
99
- key,
100
- filePath,
101
- uploadUrl: `https://${BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${s3Key}`
102
- });
103
- yield s3.send(command);
104
115
  }
105
- return { result };
116
+ return { result, errored };
106
117
  });
107
118
  }
108
119
  removeTag(savePath, tags) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "importer-storage",
3
3
  "private": false,
4
- "version": "1.0.7",
4
+ "version": "1.0.8",
5
5
  "main": "dist/index.js",
6
6
  "files": [
7
7
  "dist",