nuxt-file-storage 0.2.5 → 0.2.6

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
@@ -112,7 +112,7 @@ export default defineEventHandler(async (event) => {
112
112
 
113
113
  for ( const file of files ) {
114
114
  await storeFileLocally(
115
- file.content, // the stringified version of the file
115
+ file, // the file object
116
116
  8, // you can add a name for the file or length of Unique ID that will be automatically generated!
117
117
  '/userFiles' // the folder the file will be stored in
118
118
  )
package/dist/module.d.mts CHANGED
@@ -2,6 +2,7 @@ import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
3
  interface ModuleOptions {
4
4
  mount: string;
5
+ version: string;
5
6
  }
6
7
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
7
8
 
package/dist/module.d.ts CHANGED
@@ -2,6 +2,7 @@ import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
3
  interface ModuleOptions {
4
4
  mount: string;
5
+ version: string;
5
6
  }
6
7
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
7
8
 
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.5"
4
+ "version": "0.2.6"
5
5
  }
package/dist/module.mjs CHANGED
@@ -1,6 +1,8 @@
1
- import { defineNuxtModule, createResolver, addImportsDir, addServerScanDir } from '@nuxt/kit';
1
+ import { defineNuxtModule, logger, createResolver, addImportsDir, addServerScanDir } from '@nuxt/kit';
2
2
  import defu from 'defu';
3
3
 
4
+ const version = "0.2.6";
5
+
4
6
  const module = defineNuxtModule({
5
7
  meta: {
6
8
  name: "nuxt-file-storage",
@@ -9,13 +11,25 @@ const module = defineNuxtModule({
9
11
  //? Default configuration options of the Nuxt module
10
12
  //! no defaults for now
11
13
  // defaults: {
12
- // mount: 'userFiles',
14
+ // version: '0.0.0',
13
15
  // },
14
16
  setup(options, nuxt) {
15
17
  const config = nuxt.options.runtimeConfig;
16
18
  config.public.fileStorage = defu(config.public.fileStorage, {
17
19
  ...options
18
20
  });
21
+ if (nuxt.options.dev) {
22
+ //! I couldn't find a way to detect new updates to warn one time so it will warn every time the server runs again, if you know how to warn about a breaking change only the first run after an update feel free to open a new pull request
23
+ const previousVersion = config.public.fileStorage?.version;
24
+ if (!previousVersion || previousVersion !== version) {
25
+ logger.warn(
26
+ `There is a breaking change in the \`fileStoreLocally\` method, link to changelog:
27
+ https://github.com/NyllRE/nuxt-file-storage/releases/tag/v${version}
28
+ `
29
+ );
30
+ config.public.fileStorage.version = version;
31
+ }
32
+ }
19
33
  const resolve = createResolver(import.meta.url).resolve;
20
34
  addImportsDir(resolve("runtime/composables"));
21
35
  addServerScanDir(resolve("./runtime/server"));
@@ -1,10 +1,20 @@
1
1
  /// <reference types="node" />
2
2
  /**
3
- * @returns mime type
3
+ * #### Will store the file in the specified directory
4
+ * @returns file name: `${filename}`.`${fileExtension}`
5
+ * @prop file: provide the file object
4
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
+ * @prop filelocation: provide the folder you wish to locate the file in
5
8
  */
6
- export declare const storeFileLocally: (dataurl: string, fileNameOrIdLength: string | number, filelocation?: string) => Promise<string>;
9
+ export declare const storeFileLocally: (file: File, fileNameOrIdLength: string | number, filelocation?: string) => Promise<string>;
7
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
+ }
8
18
  /**
9
19
  Parses a data URL and returns an object with the binary data and the file extension.
10
20
  @param {string} file - The data URL
@@ -14,3 +24,4 @@ export declare const parseDataUrl: (file: string) => {
14
24
  binaryString: Buffer;
15
25
  ext: string;
16
26
  };
27
+ export {};
@@ -1,14 +1,15 @@
1
1
  import { writeFile, rm, mkdir } from "fs/promises";
2
2
  import { useRuntimeConfig } from "#imports";
3
- export const storeFileLocally = async (dataurl, fileNameOrIdLength, filelocation = "") => {
4
- const { binaryString, ext } = parseDataUrl(dataurl);
3
+ export const storeFileLocally = async (file, fileNameOrIdLength, filelocation = "") => {
4
+ const { binaryString, ext } = parseDataUrl(file.content);
5
5
  const location = useRuntimeConfig().public.fileStorage.mount;
6
- const filename = typeof fileNameOrIdLength == "number" ? generateRandomId(fileNameOrIdLength) : fileNameOrIdLength;
6
+ const originalExt = file.name.toString().split(".").pop() || ext;
7
+ const filename = typeof fileNameOrIdLength == "number" ? `${generateRandomId(fileNameOrIdLength)}.${originalExt}` : `${fileNameOrIdLength}.${originalExt}`;
7
8
  await mkdir(`${location}${filelocation}`, { recursive: true });
8
- await writeFile(`${location}${filelocation}/${filename}.${ext}`, binaryString, {
9
+ await writeFile(`${location}${filelocation}/${filename}`, binaryString, {
9
10
  flag: "w"
10
11
  });
11
- return `${filename}.${ext}`;
12
+ return filename;
12
13
  };
13
14
  export const deleteFile = async (filename, filelocation = "") => {
14
15
  const location = useRuntimeConfig().public.fileStorage.mount;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-file-storage",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
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",