nuxt-file-storage 0.2.6 → 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/README.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
# Nuxt File Storage
|
|
4
4
|
|
|
5
|
+
[](https://badges.pufler.dev)
|
|
5
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
6
7
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
7
8
|
[![License][license-src]][license-href]
|
|
8
9
|
[![Nuxt][nuxt-src]][nuxt-href]
|
|
9
10
|
|
|
10
|
-
|
|
11
11
|
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.
|
|
12
12
|
|
|
13
13
|
- [✨ Release Notes](/CHANGELOG.md)
|
|
@@ -82,6 +82,9 @@ You can use Nuxt Storage to get the files from the `<input>` tag:
|
|
|
82
82
|
```
|
|
83
83
|
The `files` return a ref object that contains the files
|
|
84
84
|
|
|
85
|
+
> `handleFileInput` returns a promise in case you need to check if the file input has concluded
|
|
86
|
+
|
|
87
|
+
|
|
85
88
|
Here's an example of using files to send them to the backend:
|
|
86
89
|
```html
|
|
87
90
|
<template>
|
package/dist/module.json
CHANGED
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.
|
|
4
|
+
const version = "0.2.8";
|
|
5
5
|
|
|
6
6
|
const module = defineNuxtModule({
|
|
7
7
|
meta: {
|
|
@@ -23,7 +23,7 @@ const module = defineNuxtModule({
|
|
|
23
23
|
const previousVersion = config.public.fileStorage?.version;
|
|
24
24
|
if (!previousVersion || previousVersion !== version) {
|
|
25
25
|
logger.warn(
|
|
26
|
-
`There is a breaking change in the \`
|
|
26
|
+
`There is a breaking change in the \`storeFileLocally\` method, link to changelog:
|
|
27
27
|
https://github.com/NyllRE/nuxt-file-storage/releases/tag/v${version}
|
|
28
28
|
`
|
|
29
29
|
);
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
export default function (): {
|
|
2
|
-
files: import("vue").Ref<
|
|
3
|
-
|
|
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
|
-
}[]>;
|
|
13
|
-
handleFileInput: (event: any) => void;
|
|
2
|
+
files: import("vue").Ref<any[]>;
|
|
3
|
+
handleFileInput: (event: any) => Promise<void>;
|
|
14
4
|
};
|
|
@@ -2,25 +2,32 @@ import { ref } from "vue";
|
|
|
2
2
|
export default function() {
|
|
3
3
|
const files = ref([]);
|
|
4
4
|
const serializeFile = (file) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
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);
|
|
22
|
+
});
|
|
17
23
|
};
|
|
18
|
-
const handleFileInput = (event) => {
|
|
24
|
+
const handleFileInput = async (event) => {
|
|
19
25
|
files.value.splice(0);
|
|
20
|
-
|
|
26
|
+
const promises = [];
|
|
21
27
|
for (const file of event.target.files) {
|
|
22
|
-
serializeFile(file);
|
|
28
|
+
promises.push(serializeFile(file));
|
|
23
29
|
}
|
|
30
|
+
await Promise.all(promises);
|
|
24
31
|
};
|
|
25
32
|
return {
|
|
26
33
|
files,
|
|
@@ -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:
|
|
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.
|
|
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.
|
|
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",
|