Skip to content

Commit

Permalink
fix multer types part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
3vorp committed Sep 26, 2024
1 parent 86e27b5 commit 55651f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/v2/controller/addonChange.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
SuccessResponse,
Tags,
} from "tsoa";
import { Express, Request as ExRequest } from "express";
import { Request as ExRequest } from "express";
import { WriteConfirmation } from "firestorm-db";
import { File } from "../interfaces/files";
import { File, MulterFile } from "../interfaces/files";
import {
AddonReview,
Addon,
Expand Down Expand Up @@ -123,7 +123,7 @@ export class AddonChangeController extends Controller {
* @param id_or_slug Add-on to add header image to
* @param file File to post
*/
public postHeader(id_or_slug: string, file: Express.Multer.File): Promise<File | void> {
public postHeader(id_or_slug: string, file: MulterFile): Promise<File | void> {
return this.service.postHeader(id_or_slug, file.originalname, file);
}

Expand All @@ -132,7 +132,7 @@ export class AddonChangeController extends Controller {
* @param id_or_slug Add-on to add screenshot to
* @param file File to post
*/
public addonAddScreenshot(id_or_slug: string, file: Express.Multer.File): Promise<File | void> {
public addonAddScreenshot(id_or_slug: string, file: MulterFile): Promise<File | void> {
return this.service.postScreenshot(id_or_slug, file.originalname, file);
}

Expand Down
5 changes: 5 additions & 0 deletions src/v2/interfaces/files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { WriteConfirmation } from "firestorm-db";
import { Express } from "express";

// multer monkey patches express's types and eslint really doesn't like that
// so we need to export this separately to prevent issues
export interface MulterFile extends Express.Multer.File {}

export interface FileParent {
type: string; // collection name (addon, post...)
Expand Down
7 changes: 3 additions & 4 deletions src/v2/service/addon.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { URL } from "url";
import { APIEmbedField } from "discord-api-types/v10";
import { WriteConfirmation } from "firestorm-db";
import { User, UserProfile } from "../interfaces/users";
import { Addons, Addon, AddonStatus, AddonAll, Files, File, FileParent } from "../interfaces";
import { Addons, Addon, AddonStatus, AddonAll, Files, File, FileParent, MulterFile } from "../interfaces";
import { BadRequestError, NotFoundError } from "../tools/errors";
import UserService from "./user.service";
import FileService from "./file.service";
Expand All @@ -16,7 +16,6 @@ import {
} from "../interfaces/addons";
import AddonFirestormRepository from "../repository/addon.repository";
import { discordEmbed } from "../tools/discordEmbed";
import { Express } from "express";

// filter & keep only values that are in a-Z & 0-9 & _ or -
const toSlug = (value: string) =>
Expand Down Expand Up @@ -336,7 +335,7 @@ export default class AddonService {
public async postHeader(
idOrSlug: string,
filename: string,
multerFile: Express.Multer.File,
multerFile: MulterFile,
): Promise<void | File> {
this.validateImageType(multerFile.mimetype);
const { buffer } = multerFile;
Expand Down Expand Up @@ -384,7 +383,7 @@ export default class AddonService {
public async postScreenshot(
idOrSlug: string,
filename: string,
multerFile: Express.Multer.File,
multerFile: MulterFile,
): Promise<void | File> {
this.validateImageType(multerFile.mimetype);
const { buffer } = multerFile;
Expand Down

0 comments on commit 55651f2

Please sign in to comment.