diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..8326441 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,328 @@ +module.exports = { + root: true, + parser: '@typescript-eslint/parser', + parserOptions: { + project: './tsconfig.eslint.json', + sourceType: 'module', + ecmaVersion: 2020, + }, + extends: ['plugin:@typescript-eslint/recommended'], + env: { + node: true, + }, + rules: { + '@typescript-eslint/adjacent-overload-signatures': 'error', + '@typescript-eslint/array-type': 'off', + '@typescript-eslint/await-thenable': 'off', + '@typescript-eslint/ban-ts-comment': [ + 'error', + { + minimumDescriptionLength: 3, + 'ts-check': true, + 'ts-expect-error': 'allow-with-description', + 'ts-ignore': 'allow-with-description', + 'ts-nocheck': true + } + ], + '@typescript-eslint/class-literal-property-style': 'error', + '@typescript-eslint/consistent-type-definitions': 'error', + '@typescript-eslint/default-param-last': 'error', + '@typescript-eslint/dot-notation': [ + 'error', + { + allowKeywords: true, + allowPattern: '(^[A-Z])|(^[a-z]+(_[a-z]+)+$)', + allowPrivateClassPropertyAccess: true + } + ], + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/explicit-member-accessibility': 'error', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/init-declarations': 'off', + '@typescript-eslint/member-ordering': [ + 'error', + { + default: [ + 'signature', + 'public-instance-field', + 'protected-instance-field', + 'private-instance-field', + 'instance-field', + 'public-constructor', + 'protected-constructor', + 'private-constructor', + 'constructor', + 'public-instance-method', + 'protected-instance-method', + 'private-instance-method', + 'instance-method', + 'public-static-field', + 'protected-static-field', + 'private-static-field', + 'static-field', + 'public-static-method', + 'protected-static-method', + 'private-static-method', + 'static-method' + ] + } + ], + '@typescript-eslint/no-base-to-string': 'error', + '@typescript-eslint/no-dupe-class-members': 'error', + '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-extra-non-null-assertion': 'error', + '@typescript-eslint/no-extraneous-class': 'error', + '@typescript-eslint/no-floating-promises': 'error', + '@typescript-eslint/no-for-in-array': 'error', + '@typescript-eslint/no-implied-eval': 'error', + '@typescript-eslint/no-invalid-this': 'error', + '@typescript-eslint/no-invalid-void-type': 'error', + '@typescript-eslint/no-misused-new': 'error', + '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-throw-literal': 'error', + '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error', + '@typescript-eslint/no-unnecessary-qualifier': 'error', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/no-useless-constructor': 'error', + '@typescript-eslint/no-var-requires': 'error', + '@typescript-eslint/prefer-as-const': 'error', + '@typescript-eslint/prefer-for-of': 'error', + '@typescript-eslint/prefer-includes': 'error', + '@typescript-eslint/prefer-reduce-type-parameter': 'error', + '@typescript-eslint/prefer-string-starts-ends-with': 'error', + '@typescript-eslint/promise-function-async': 'off', + '@typescript-eslint/require-await': 'error', + '@typescript-eslint/restrict-plus-operands': 'off', + '@typescript-eslint/switch-exhaustiveness-check': 'warn', + '@typescript-eslint/unbound-method': 'error', + '@typescript-eslint/unified-signatures': 'error', + 'accessor-pairs': 'off', + 'array-callback-return': 'error', + 'block-scoped-var': 'error', + 'callback-return': 'off', + 'capitalized-comments': 'off', + 'class-methods-use-this': 'off', + complexity: 'off', + 'consistent-return': 'off', + 'consistent-this': ['error', 'self'], + 'constructor-super': 'off', + 'default-case': 'off', + 'dot-notation': 'off', + eqeqeq: ['error', 'smart'], + 'for-direction': 'off', + 'func-name-matching': ['warn', 'always'], + 'func-names': ['warn', 'as-needed'], + 'func-style': 'off', + 'global-require': 'off', + 'guard-for-in': 'warn', + 'handle-callback-err': 'off', + 'id-blacklist': 'off', + 'id-length': 'off', + 'id-match': 'off', + 'init-declarations': 'off', + 'line-comment-position': 'off', + 'lines-between-class-members': [ + 'error', + 'always', + { + exceptAfterSingleLine: true + } + ], + 'max-depth': 'off', + 'max-lines': 'off', + 'max-nested-callbacks': 'off', + 'max-params': 'off', + 'max-statements': 'off', + 'max-statements-per-line': [ + 'error', + { + max: 1 + } + ], + 'multiline-comment-style': 'off', + 'new-cap': 'off', + 'no-alert': 'error', + 'no-array-constructor': 'off', + 'no-await-in-loop': 'off', + 'no-bitwise': 'off', + 'no-buffer-constructor': 'error', + 'no-caller': 'error', + 'no-case-declarations': 'error', + 'no-catch-shadow': 'error', + 'no-class-assign': 'warn', + 'no-compare-neg-zero': 'error', + 'no-cond-assign': 'warn', + 'no-console': 'off', + 'no-const-assign': 'error', + 'no-constant-condition': 'off', + 'no-control-regex': 'off', + 'no-debugger': 'error', + 'no-delete-var': 'error', + 'no-div-regex': 'off', + 'no-dupe-args': 'error', + 'no-dupe-class-members': 'off', + 'no-dupe-keys': 'error', + 'no-duplicate-case': 'error', + 'no-duplicate-imports': [ + 'error', + { + includeExports: false + } + ], + 'no-else-return': 'warn', + 'no-empty': 'off', + 'no-empty-character-class': 'error', + 'no-empty-function': 'off', + 'no-empty-pattern': 'off', + 'no-eq-null': 'warn', + 'no-eval': 'warn', + 'no-ex-assign': 'off', + 'no-extend-native': 'warn', + 'no-extra-bind': 'off', + 'no-extra-boolean-cast': 'off', + 'no-extra-label': 'warn', + 'no-fallthrough': 'off', + 'no-func-assign': 'off', + 'no-global-assign': 'off', + 'no-implicit-coercion': 'error', + 'no-implicit-globals': 'off', + 'no-implied-eval': 'off', + 'no-import-assign': 'warn', + 'no-inline-comments': 'off', + 'no-inner-declarations': 'off', + 'no-invalid-regexp': 'warn', + 'no-invalid-this': 'off', + 'no-irregular-whitespace': [ + 'error', + { + skipComments: true, + skipRegExps: true, + skipStrings: true, + skipTemplates: true + } + ], + 'no-iterator': 'off', + 'no-label-var': 'error', + 'no-labels': 'off', + 'no-lone-blocks': 'off', + 'no-lonely-if': 'error', + 'no-loop-func': 'off', + 'no-magic-numbers': 'off', + 'no-mixed-requires': 'error', + 'no-multi-assign': 'warn', + 'no-multi-str': 'error', + 'no-negated-condition': 'warn', + 'no-nested-ternary': 'off', + 'no-new': 'off', + 'no-new-func': 'warn', + 'no-new-object': 'error', + 'no-new-require': 'error', + 'no-new-symbol': 'warn', + 'no-new-wrappers': 'warn', + 'no-obj-calls': 'warn', + 'no-octal': 'error', + 'no-octal-escape': 'error', + 'no-param-reassign': 'off', + 'no-path-concat': 'warn', + 'no-plusplus': 'off', + 'no-process-env': 'off', + 'no-process-exit': 'off', + 'no-proto': 'off', + 'no-prototype-builtins': 'off', + 'no-redeclare': 'off', + 'no-regex-spaces': 'warn', + 'no-restricted-globals': 'off', + 'no-restricted-imports': 'off', + 'no-restricted-modules': 'off', + 'no-restricted-properties': 'off', + 'no-restricted-syntax': 'off', + 'no-return-assign': 'off', + 'no-return-await': 'warn', + 'no-script-url': 'off', + 'no-self-assign': 'error', + 'no-self-compare': 'warn', + 'no-setter-return': 'warn', + 'no-shadow': 'off', + 'no-shadow-restricted-names': 'error', + 'no-sparse-arrays': 'warn', + 'no-sync': 'off', + 'no-template-curly-in-string': 'error', + 'no-ternary': 'off', + 'no-this-before-super': 'error', + 'no-throw-literal': 'off', + 'no-undef': 'off', + 'no-undef-init': 'off', + 'no-undefined': 'off', + 'no-underscore-dangle': 'off', + 'no-unmodified-loop-condition': 'off', + 'no-unneeded-ternary': 'off', + 'no-unreachable': 'warn', + 'no-unsafe-finally': 'warn', + 'no-unsafe-negation': 'error', + 'no-unused-expressions': 'off', + 'no-unused-labels': 'error', + 'no-unused-vars': 'off', + 'no-use-before-define': 'off', + 'no-useless-call': 'off', + 'no-useless-computed-key': 'error', + 'no-useless-concat': 'warn', + 'no-useless-constructor': 'off', + 'no-useless-escape': 'off', + 'no-useless-rename': 'error', + 'no-useless-return': 'warn', + 'no-var': 'error', + 'no-void': 'off', + 'no-warning-comments': 'off', + 'no-with': 'error', + 'object-shorthand': ['error', 'always'], + 'one-var': ['error', 'never'], + 'operator-assignment': ['error', 'always'], + 'padding-line-between-statements': 'off', + 'prefer-const': [ + 'error', + { + destructuring: 'all' + } + ], + 'prefer-destructuring': [ + 'error', + { + AssignmentExpression: { + array: true, + object: false + }, + VariableDeclarator: { + array: false, + object: true + } + } + ], + 'prefer-numeric-literals': 'off', + 'prefer-promise-reject-errors': 'error', + 'prefer-rest-params': 'warn', + 'prefer-spread': 'error', + 'prefer-template': 'warn', + radix: 'error', + 'require-await': 'off', + 'require-jsdoc': 'off', + 'require-yield': 'warn', + 'sort-imports': 'off', + 'sort-keys': 'off', + 'sort-vars': 'off', + 'spaced-comment': ['error', 'always'], + strict: ['error', 'never'], + 'symbol-description': 'warn', + 'use-isnan': 'error', + 'valid-jsdoc': 'off', + 'valid-typeof': 'error', + 'vars-on-top': 'off', + yoda: 'error' + } +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 6e23d0a..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "@sapphire" -} diff --git a/package.json b/package.json index 0b7b5e0..28bf65a 100644 --- a/package.json +++ b/package.json @@ -31,26 +31,25 @@ "prettier": "prettier --write **/*.{ts,js,json,yml,yaml}" }, "devDependencies": { - "@sapphire/eslint-config": "^3.2.3", - "@types/express": "^4.17.13", - "@types/multer": "^1.4.7", - "@types/node": "^16.7.6", - "@types/node-fetch": "2.5.12", - "@types/prettier": "^2.3.2", - "@typescript-eslint/eslint-plugin": "^3.9.0", - "@typescript-eslint/parser": "^3.9.0", - "eslint": "^7.6.0", - "eslint-config-prettier": "^6.11.0", - "eslint-plugin-prettier": "^3.1.4", - "gen-esm-wrapper": "^1.1.2", - "husky": "^6.0.0", - "lint-staged": "^10.4.2", - "rimraf": "^3.0.2", - "typescript": "^4.4.2" + "@types/express": "^4.17.21", + "@types/multer": "^1.4.11", + "@types/node": "^20.10.0", + "@types/node-fetch": "2.6.9", + "@types/prettier": "^2.7.3", + "@typescript-eslint/eslint-plugin": "^6.12.0", + "@typescript-eslint/parser": "^6.12.0", + "eslint": "^8.54.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-prettier": "^5.0.1", + "gen-esm-wrapper": "^1.1.3", + "husky": "^8.0.3", + "lint-staged": "^15.1.0", + "rimraf": "^5.0.5", + "typescript": "^4.9.5" }, "dependencies": { "form-data": "^4.0.0", - "node-fetch": "v2" + "node-fetch": "^3.3.2" }, "repository": { "type": "git", @@ -60,4 +59,4 @@ "url": "https://github.com/zaida04/multer-cloudflare-storage.git/issues" }, "homepage": "https://github.com/zaida04/multer-cloudflare-storage.git#readme" -} \ No newline at end of file +} diff --git a/src/multer.ts b/src/multer.ts index 8bdfdac..c5914a2 100644 --- a/src/multer.ts +++ b/src/multer.ts @@ -17,8 +17,11 @@ class CloudflareStorage implements StorageEngine { public _handleFile(_req: Request, file: Express.Multer.File, callback: CallbackFunction): void { const body = new FormData(); body.append("file", file.stream, file.originalname); + void this._uploadFile(body, callback); + } - this._uploadFile(body, callback); + public _removeFile(_req: Request, file: Express.Multer.File, callback: (error: Error | null) => void): void { + void this._deleteFile(file.destination, callback); } private async _uploadFile(body: FormData, callback: CallbackFunction) { @@ -43,10 +46,6 @@ class CloudflareStorage implements StorageEngine { return callback(new Error("There was an error in uploading an asset to Cloudflare Images.")); } - public _removeFile(_req: Request, file: Express.Multer.File, callback: (error: Error | null) => void): void { - this._deleteFile(file.destination, callback); - } - private async _deleteFile(filedestination: string, callback: CallbackFunction) { const request = await fetch(`${this.destURL}/${filedestination}`, { method: "DELETE",