nuxt-file-storage 0.2.7 → 0.2.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/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "nuxt-file-storage",
3
3
  "configKey": "fileStorage",
4
- "version": "0.2.7"
4
+ "version": "0.2.8"
5
5
  }
package/dist/module.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { defineNuxtModule, logger, createResolver, addImportsDir, addServerScanDir } from '@nuxt/kit';
2
2
  import defu from 'defu';
3
3
 
4
- const version = "0.2.7";
4
+ const version = "0.2.8";
5
5
 
6
6
  const module = defineNuxtModule({
7
7
  meta: {
@@ -1,14 +1,4 @@
1
1
  export default function (): {
2
- files: import("vue").Ref<{
3
- content: any;
4
- name: string;
5
- lastModified: string;
6
- readonly size: number;
7
- readonly type: string;
8
- arrayBuffer: () => Promise<ArrayBuffer>;
9
- slice: (start?: number | undefined, end?: number | undefined, contentType?: string | undefined) => Blob;
10
- stream: () => ReadableStream<Uint8Array>;
11
- text: () => Promise<string>;
12
- }[]>;
2
+ files: import("vue").Ref<any[]>;
13
3
  handleFileInput: (event: any) => Promise<void>;
14
4
  };
@@ -2,29 +2,33 @@ import { ref } from "vue";
2
2
  export default function() {
3
3
  const files = ref([]);
4
4
  const serializeFile = (file) => {
5
- const reader = new FileReader();
6
- reader.onload = (e) => {
7
- files.value.push({
8
- ...file,
9
- name: file.name,
10
- size: file.size,
11
- type: file.type,
12
- lastModified: file.lastModified,
13
- content: e.target.result
14
- });
15
- };
16
- reader.readAsDataURL(file);
17
- };
18
- const handleFileInput = (event) => {
19
5
  return new Promise((resolve, reject) => {
20
- files.value.splice(0);
21
- const promises = [];
22
- for (const file of event.target.files) {
23
- promises.push(serializeFile(file));
24
- }
25
- Promise.all(promises).then(() => resolve()).catch((error) => reject(error));
6
+ const reader = new FileReader();
7
+ reader.onload = (e) => {
8
+ files.value.push({
9
+ ...file,
10
+ name: file.name,
11
+ size: file.size,
12
+ type: file.type,
13
+ lastModified: file.lastModified,
14
+ content: e.target?.result
15
+ });
16
+ resolve();
17
+ };
18
+ reader.onerror = (error) => {
19
+ reject(error);
20
+ };
21
+ reader.readAsDataURL(file);
26
22
  });
27
23
  };
24
+ const handleFileInput = async (event) => {
25
+ files.value.splice(0);
26
+ const promises = [];
27
+ for (const file of event.target.files) {
28
+ promises.push(serializeFile(file));
29
+ }
30
+ await Promise.all(promises);
31
+ };
28
32
  return {
29
33
  files,
30
34
  handleFileInput
@@ -6,15 +6,8 @@
6
6
  * @prop fileNameOrIdLength: you can pass a string or a number, if you enter a string it will be the file name, if you enter a number it will generate a unique ID
7
7
  * @prop filelocation: provide the folder you wish to locate the file in
8
8
  */
9
- export declare const storeFileLocally: (file: File, fileNameOrIdLength: string | number, filelocation?: string) => Promise<string>;
9
+ export declare const storeFileLocally: (file: ServerFile, fileNameOrIdLength: string | number, filelocation?: string) => Promise<string>;
10
10
  export declare const deleteFile: (filename: string, filelocation?: string) => Promise<void>;
11
- interface File {
12
- name: string;
13
- content: string;
14
- size: string;
15
- type: string;
16
- lastModified: string;
17
- }
18
11
  /**
19
12
  Parses a data URL and returns an object with the binary data and the file extension.
20
13
  @param {string} file - The data URL
@@ -24,4 +17,3 @@ export declare const parseDataUrl: (file: string) => {
24
17
  binaryString: Buffer;
25
18
  ext: string;
26
19
  };
27
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-file-storage",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Easy solution to store files in your nuxt apps. Be able to upload files from the frontend and recieve them from the backend to then save the files in your project.",
5
5
  "repository": "NyllRE/nuxt-file-storage",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  "devDependencies": {
35
35
  "@nuxt/devtools": "latest",
36
36
  "@nuxt/eslint-config": "^0.2.0",
37
- "@nuxt/module-builder": "^0.5.5",
37
+ "@nuxt/module-builder": "^0.8.3",
38
38
  "@nuxt/schema": "^3.9.3",
39
39
  "@nuxt/test-utils": "^3.9.0",
40
40
  "@types/node": "^20.11.5",