Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adapted code to @fastify/multipart #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^3.2.0",
"fastify": "^3.21.3",
"fastify-multipart": "^5.0.0",
"nodemon": "^2.0.12",
"prettier": "^2.2.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.3.0",
"typescript": "^4.1.2"
},
"dependencies": {
"@fastify/multipart": "^7.7.3"
}
}
2 changes: 1 addition & 1 deletion src/multipart/file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MultipartFile as _MultipartFile } from "fastify-multipart";
import { MultipartFile as _MultipartFile } from "@fastify/multipart";
import { Readable } from "stream";

import { Storage, StorageFile } from "../storage";
Expand Down
6 changes: 5 additions & 1 deletion src/multipart/handlers/any-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { StorageFile } from "../../storage";
import { getParts } from "../request";
import { removeStorageFiles } from "../file";
import { filterUpload } from "../filter";
import { MultipartFile } from "@fastify/multipart";

export const handleMultipartAnyFiles = async (
req: FastifyRequest,
Expand All @@ -22,7 +23,10 @@ export const handleMultipartAnyFiles = async (
try {
for await (const part of parts) {
if (part.file) {
const file = await options.storage!.handleFile(part, req);
const file = await options.storage!.handleFile(
<MultipartFile>part,
req,
);

if (await filterUpload(options, req, file)) {
files.push(file);
Expand Down
6 changes: 5 additions & 1 deletion src/multipart/handlers/file-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { StorageFile } from "../../storage/storage";
import { getParts } from "../request";
import { removeStorageFiles } from "../file";
import { filterUpload } from "../filter";
import { MultipartFile } from "@fastify/multipart";

export interface UploadField {
/**
Expand Down Expand Up @@ -66,7 +67,10 @@ export const handleMultipartFileFields = async (
);
}

const file = await options.storage!.handleFile(part, req);
const file = await options.storage!.handleFile(
<MultipartFile>part,
req,
);

if (await filterUpload(options, req, file)) {
files[part.fieldname].push(file);
Expand Down
6 changes: 5 additions & 1 deletion src/multipart/handlers/multiple-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { StorageFile } from "../../storage";
import { removeStorageFiles } from "../file";
import { getParts } from "../request";
import { filterUpload } from "../filter";
import { MultipartFile } from "@fastify/multipart";

export const handleMultipartMultipleFiles = async (
req: FastifyRequest,
Expand Down Expand Up @@ -37,7 +38,10 @@ export const handleMultipartMultipleFiles = async (
);
}

const file = await options.storage!.handleFile(part, req);
const file = await options.storage!.handleFile(
<MultipartFile>part,
req,
);

if (await filterUpload(options, req, file)) {
files.push(file);
Expand Down
6 changes: 5 additions & 1 deletion src/multipart/handlers/single-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { UploadOptions } from "../options";
import { StorageFile } from "../../storage";
import { getParts } from "../request";
import { filterUpload } from "../filter";
import { MultipartFile } from "@fastify/multipart";

export const handleMultipartSingleFile = async (
req: FastifyRequest,
Expand Down Expand Up @@ -34,7 +35,10 @@ export const handleMultipartSingleFile = async (
);
}

const _file = await options.storage!.handleFile(part, req);
const _file = await options.storage!.handleFile(
<MultipartFile>part,
req,
);

if (await filterUpload(options, req, _file)) {
file = _file;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/disk-storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MultipartFile } from "fastify-multipart";
import { MultipartFile } from "@fastify/multipart";
import { FastifyRequest } from "fastify";
import { tmpdir } from "os";
import { createWriteStream } from "fs";
Expand Down
2 changes: 1 addition & 1 deletion src/storage/memory-storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyRequest } from "fastify";
import { MultipartFile } from "fastify-multipart";
import { MultipartFile } from "@fastify/multipart";
import { RouteGenericInterface } from "fastify/types/route";
import { Server, IncomingMessage } from "http";

Expand Down
2 changes: 1 addition & 1 deletion src/storage/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyRequest } from "fastify";
import { MultipartFile } from "fastify-multipart";
import { MultipartFile } from "@fastify/multipart";

export interface StorageFile {
size: number;
Expand Down
Loading