@sprucelabs/spruce-file-utils 7.1.0 → 7.1.2

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.
@@ -0,0 +1,6 @@
1
+ import { UploadStrategy, UploadStrategyUploadOptions } from './FileUploader';
2
+ export default class LocalUploadStrategy implements UploadStrategy {
3
+ private localUploadDir;
4
+ constructor(localUploadDir: string);
5
+ upload(options: UploadStrategyUploadOptions): Promise<string>;
6
+ }
@@ -0,0 +1,23 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { diskUtil } from '@sprucelabs/spruce-skill-utils';
11
+ export default class LocalUploadStrategy {
12
+ constructor(localUploadDir) {
13
+ this.localUploadDir = localUploadDir;
14
+ }
15
+ upload(options) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const { name, buffer } = options;
18
+ const destination = diskUtil.resolvePath(this.localUploadDir, name);
19
+ diskUtil.writeFile(destination, buffer.toString('utf-8'));
20
+ return destination;
21
+ });
22
+ }
23
+ }
@@ -0,0 +1,4 @@
1
+ import { UploadStrategy, UploadStrategyUploadOptions } from './FileUploader';
2
+ export default class S3UploadStrategy implements UploadStrategy {
3
+ upload(options: UploadStrategyUploadOptions): Promise<string>;
4
+ }
@@ -0,0 +1,36 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { assertOptions } from '@sprucelabs/schema';
11
+ import AWS from 'aws-sdk';
12
+ export default class S3UploadStrategy {
13
+ upload(options) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const { name, buffer, type } = options;
16
+ const { env: { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_S3_BUCKET }, } = assertOptions(process, [
17
+ 'env.AWS_ACCESS_KEY_ID',
18
+ 'env.AWS_SECRET_ACCESS_KEY',
19
+ 'env.AWS_S3_BUCKET',
20
+ ]);
21
+ const s3 = new AWS.S3({
22
+ accessKeyId: AWS_ACCESS_KEY_ID,
23
+ secretAccessKey: AWS_SECRET_ACCESS_KEY,
24
+ });
25
+ const s3Params = {
26
+ Bucket: AWS_S3_BUCKET,
27
+ Key: name,
28
+ Body: buffer,
29
+ ACL: 'public-read',
30
+ ContentType: type,
31
+ };
32
+ const uploadedFile = yield s3.upload(s3Params).promise();
33
+ return uploadedFile.Location;
34
+ });
35
+ }
36
+ }
@@ -0,0 +1,6 @@
1
+ import { UploadStrategy, UploadStrategyUploadOptions } from './FileUploader';
2
+ export default class LocalUploadStrategy implements UploadStrategy {
3
+ private localUploadDir;
4
+ constructor(localUploadDir: string);
5
+ upload(options: UploadStrategyUploadOptions): Promise<string>;
6
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
4
+ class LocalUploadStrategy {
5
+ constructor(localUploadDir) {
6
+ this.localUploadDir = localUploadDir;
7
+ }
8
+ async upload(options) {
9
+ const { name, buffer } = options;
10
+ const destination = spruce_skill_utils_1.diskUtil.resolvePath(this.localUploadDir, name);
11
+ spruce_skill_utils_1.diskUtil.writeFile(destination, buffer.toString('utf-8'));
12
+ return destination;
13
+ }
14
+ }
15
+ exports.default = LocalUploadStrategy;
@@ -0,0 +1,4 @@
1
+ import { UploadStrategy, UploadStrategyUploadOptions } from './FileUploader';
2
+ export default class S3UploadStrategy implements UploadStrategy {
3
+ upload(options: UploadStrategyUploadOptions): Promise<string>;
4
+ }
@@ -0,0 +1,31 @@
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
+ const schema_1 = require("@sprucelabs/schema");
7
+ const aws_sdk_1 = __importDefault(require("aws-sdk"));
8
+ class S3UploadStrategy {
9
+ async upload(options) {
10
+ const { name, buffer, type } = options;
11
+ const { env: { AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_S3_BUCKET }, } = (0, schema_1.assertOptions)(process, [
12
+ 'env.AWS_ACCESS_KEY_ID',
13
+ 'env.AWS_SECRET_ACCESS_KEY',
14
+ 'env.AWS_S3_BUCKET',
15
+ ]);
16
+ const s3 = new aws_sdk_1.default.S3({
17
+ accessKeyId: AWS_ACCESS_KEY_ID,
18
+ secretAccessKey: AWS_SECRET_ACCESS_KEY,
19
+ });
20
+ const s3Params = {
21
+ Bucket: AWS_S3_BUCKET,
22
+ Key: name,
23
+ Body: buffer,
24
+ ACL: 'public-read',
25
+ ContentType: type,
26
+ };
27
+ const uploadedFile = await s3.upload(s3Params).promise();
28
+ return uploadedFile.Location;
29
+ }
30
+ }
31
+ exports.default = S3UploadStrategy;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sprucelabs/spruce-file-utils",
3
3
  "description": "Utils for working with files and Sprucebot.",
4
- "version": "7.1.0",
4
+ "version": "7.1.2",
5
5
  "skill": {
6
6
  "namespace": "files"
7
7
  },
@@ -16,12 +16,25 @@
16
16
  "files": [
17
17
  "build/index-module.js",
18
18
  "build/index-module.d.ts",
19
- "build/uploading/FileUploader.d.ts",
20
- "build/uploading/FileUploader.js",
19
+
21
20
  "build/esm/index-module.js",
22
21
  "build/esm/index-module.d.ts",
22
+
23
23
  "build/esm/uploading/FileUploader.d.ts",
24
- "build/esm/uploading/FileUploader.js"
24
+ "build/esm/uploading/FileUploader.js",
25
+ "build/uploading/FileUploader.d.ts",
26
+ "build/uploading/FileUploader.js",
27
+
28
+ "build/esm/uploading/LocalUploadStrategy.d.ts",
29
+ "build/esm/uploading/LocalUploadStrategy.js",
30
+ "build/uploading/LocalUploadStrategy.d.ts",
31
+ "build/uploading/LocalUploadStrategy.js",
32
+
33
+ "build/esm/uploading/S3UploadStrategy.d.ts",
34
+ "build/esm/uploading/S3UploadStrategy.js",
35
+ "build/uploading/S3UploadStrategy.d.ts",
36
+ "build/uploading/S3UploadStrategy.js"
37
+
25
38
  ],
26
39
  "keywords": [],
27
40
  "scripts": {
@@ -37,4 +50,4 @@
37
50
  "engines": {
38
51
  "yarn": "1.x"
39
52
  }
40
- }
53
+ }