polgo-upload-kit 1.0.10 → 1.0.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polgo-upload-kit",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "type": "module",
5
5
  "main": "src/polgoUploadClient.js",
6
6
  "scripts": {
@@ -12,7 +12,6 @@
12
12
  "description": "",
13
13
  "dependencies": {
14
14
  "axios": "^1.7.7",
15
- "file-type": "^16.5.4",
16
15
  "form-data": "^4.0.1",
17
16
  "mime-types": "^2.1.35"
18
17
  }
@@ -1,46 +1,39 @@
1
+ // src/index.js
2
+ import axios from "axios";
3
+
1
4
  class PolgoUploadClient {
2
- constructor(isProd, token, stack) {
5
+ constructor(isProd, token, stack, tipo) {
3
6
  this.ambiente = isProd ? "producao" : "dev";
4
7
  this.url =
5
8
  "https://mkgplyz3tc.execute-api.us-east-1.amazonaws.com/lambdaUploadProducao/arquivo/upload";
6
9
  this.stack = stack;
7
10
  this.token = token;
11
+ this.tipo = tipo;
8
12
  }
9
13
 
10
- async uploadFile(uint8Array, options = {}) {
11
- let fileBlob;
14
+ async uploadFile(bufferArquivo, options = {}) {
15
+ const mimeType = this.tipo;
12
16
 
13
- if (uint8Array instanceof Uint8Array) {
14
- // Defina um tipo MIME padrão se necessário
15
- const mimeType = "application/octet-stream";
16
- fileBlob = new Blob([uint8Array], { type: mimeType });
17
- } else {
18
- throw new TypeError("O arquivo não é um Uint8Array válido.");
19
- }
17
+ const fileBlob = new Blob([bufferArquivo], { type: mimeType });
20
18
 
21
- const queryParams = new URLSearchParams();
22
- queryParams.append("ambiente", this.ambiente);
23
- queryParams.append("stack", this.stack);
19
+ console.log(fileBlob)
24
20
 
25
- if (options.diretorio) {
26
- queryParams.append("diretorio", options.diretorio);
27
- }
28
- if (options.nomeArquivo) {
29
- queryParams.append("nomeArquivo", options.nomeArquivo);
30
- }
21
+ const queryParams = new URLSearchParams({
22
+ ambiente: this.ambiente,
23
+ stack: this.stack,
24
+ });
31
25
 
32
- const finalUrl = `${this.url}${
33
- queryParams.toString() ? `?${queryParams.toString()}` : ""
34
- }`;
26
+ if (options.diretorio) queryParams.append("diretorio", options.diretorio);
27
+ if (options.nomeArquivo)
28
+ queryParams.append("nomeArquivo", options.nomeArquivo);
35
29
 
30
+ const finalUrl = `${this.url}?${queryParams.toString()}`;
36
31
  const form = new FormData();
37
- const fileName = options.nomeArquivo || "uploaded_file";
38
- form.append("file", fileBlob, fileName);
32
+ form.append("file", fileBlob, options.nomeArquivo || "uploaded_file");
39
33
 
40
34
  try {
41
35
  const response = await axios.post(finalUrl, form, {
42
36
  headers: {
43
- "Content-Type": "multipart/form-data",
44
37
  Authorization: `Bearer ${this.token}`,
45
38
  },
46
39
  });
@@ -53,3 +46,5 @@ class PolgoUploadClient {
53
46
  }
54
47
  }
55
48
  }
49
+
50
+ export { PolgoUploadClient };