Skip to content

Commit

Permalink
Merge pull request #937 from myrotvorets/renovate/linters
Browse files Browse the repository at this point in the history
chore(deps): update dependency @myrotvorets/eslint-config-myrotvorets-ts to ^2.22.4
  • Loading branch information
myrotvorets-team authored Oct 12, 2023
2 parents 61fbc8b + 98fcb5e commit fb4c13d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 125 deletions.
120 changes: 20 additions & 100 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"sharp": "^0.32.6"
},
"devDependencies": {
"@myrotvorets/eslint-config-myrotvorets-ts": "^2.21.0",
"@myrotvorets/eslint-config-myrotvorets-ts": "^2.22.4",
"@types/chai": "^4.3.7",
"@types/chai-as-promised": "^7.1.6",
"@types/chai-subset": "^1.3.3",
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/upload.mts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function searchUploadHandler(
res: Response<UploadResponse>,
next: NextFunction,
): Promise<void> {
const file = (req.files as Express.Multer.File[])[0];
const file = (req.files as Express.Multer.File[])[0]!;
const { guid } = req.params;

await UploadService.uploadFile(file, guid);
Expand Down
18 changes: 1 addition & 17 deletions src/server.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import express, { type Express, json, static as staticMiddleware } from 'express';
import express, { type Express, json } from 'express';
import { installOpenApiValidator } from '@myrotvorets/oav-installer';
import { errorMiddleware, notFoundMiddleware } from '@myrotvorets/express-microservice-middlewares';
import { cleanUploadedFilesMiddleware } from '@myrotvorets/clean-up-after-multer';
Expand All @@ -18,22 +18,6 @@ import { uploadErrorHandlerMiddleware } from './middleware/upload.mjs';
export async function configureApp(app: express.Express): Promise<void> {
const env = environment();

/* c8 ignore start */
if (env.NODE_ENV !== 'production') {
app.use(
'/specs/',
staticMiddleware(join(dirname(fileURLToPath(import.meta.url)), 'specs'), {
acceptRanges: false,
index: false,
}),
);

if (process.env.HAVE_SWAGGER === 'true') {
app.get('/', (_req, res) => res.redirect('/swagger/'));
}
}
/* c8 ignore end */

app.use(json());

await installOpenApiValidator(
Expand Down
18 changes: 12 additions & 6 deletions src/services/upload.mts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { mkdir } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join, sep } from 'node:path';
import sharp from 'sharp';

type UploadedFileInternal =
| (Pick<Express.Multer.File, 'path' | 'destination'> & { buffer: undefined })
| (Pick<Express.Multer.File, 'buffer'> & { path: undefined; destination: undefined });

type UploadedFile = Pick<Express.Multer.File, 'path' | 'destination' | 'buffer'>;

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class UploadService {
public static async uploadFile(
file: Pick<Express.Multer.File, 'path' | 'destination' | 'buffer'>,
guid: string,
): Promise<string> {
const img = await UploadService.prepareFile(file.path ?? file.buffer); // memoryStorage() returns Buffer
public static async uploadFile(file: UploadedFile, guid: string): Promise<string> {
const f = file as unknown as UploadedFileInternal;
const img = await UploadService.prepareFile(f.path ?? f.buffer); // memoryStorage() returns Buffer
const hashedPath = UploadService.hashFileName(guid);
const filename = `${guid}.jpg`;
const destPath = join(file.destination ?? '', hashedPath); // No file.destination for memoryStorage()
const destPath = join(f.destination ?? tmpdir(), hashedPath); // No file.destination for memoryStorage()
const destJpeg = join(destPath, filename);

await mkdir(destPath, { recursive: true, mode: 0o755 });
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"noUnusedLocals": true,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"resolveJsonModule": true
},
Expand Down

0 comments on commit fb4c13d

Please sign in to comment.