<commit_before>import {
    Controller,
    Delete,
    FileInterceptor,
    Get,
    HttpCode,
    HttpException,
    Inject,
    Param,
    Post,
    UploadedFile,
    UseInterceptors,
    Response, Headers,
} from '@nestjs/common'
import { ApiOperation, ApiUseTags } from '@nestjs/swagger'
import { Upload } from './entity'
import { UploadsService } from './service'
import { AuthedUser } from '../../auth.middleware'
import { User } from '../users/entity'
import { UserService } from '../users/service'
import { Response as IResponse } from 'express'

@ApiUseTags('Uploads')
@Controller('/api/v1/uploads')
export class UploadsController {
    constructor(
        @Inject(UserService)
        private readonly userService: UserService,
    ) {
        // Set up expiry monitor
        // Runs every 5 minutes
        setInterval(() => {
            for (let user of this.userService.find()) UploadsService.clean(user)
        }, 1000 * 60 * 5)
    }

    @Get()
    @ApiOperation({ title: 'List' })
    list(
        @AuthedUser() user: User
    ): Upload[] {
        return UploadsService.find(user)
    }

    @Post()
    @ApiOperation({ title: 'Upload' })
    @HttpCode(201)
    @UseInterceptors(FileInterceptor('file', { dest: 'uploads' }))
    async add(
        @AuthedUser() user: User,
        @UploadedFile() file: Express.Multer.File, // Express.Multer.File is in global namespace
        @Headers('x-lifespan') lifespan: number | string = 84
    ): Promise<Upload> {
        return UploadsService.create(user, file, +lifespan)
    }

    @Delete(':id')
    @ApiOperation({ title: 'Delete' })
    @HttpCode(204)
    delete(
        @AuthedUser() user: User,
        @Param() params: { id: string }
    ): void {
        return UploadsService.delete(user, params.id)
    }

    @Get(':user/:id')
    @ApiOperation({ title: 'View' })
    @HttpCode(200)
    view(
        @Param() params: { id: string, user: string }
    ): Upload {
        const user = this.userService.findOne(params.user)
        const upload = user.uploads.findOne(params.id)
        if (!upload) throw new HttpException('Upload not found', 404)
        return upload
    }

    @Get(':user/:id/download')
    @ApiOperation({ title: 'Download' })
    download(
        @Param() params: { id: string, user: string },
        @Response() res: IResponse
    ): void {
        const user = this.userService.findOne(params.user)
        const upload = user.uploads.findOne(params.id)
        if (!upload) throw new HttpException('Upload not found', 404)
        return res.sendFile(user.uploads.getPath(upload), {<commit_msg>Use correct findOne method (from the service)<commit_after>import {
    Controller,
    Delete,
    FileInterceptor,
    Get,
    Headers,
    HttpCode,
    Inject,
    Param,
    Post,
    Response,
    UploadedFile,
    UseInterceptors,
} from '@nestjs/common'
import { ApiOperation, ApiUseTags } from '@nestjs/swagger'
import { Upload } from './entity'
import { UploadsService } from './service'
import { AuthedUser } from '../../auth.middleware'
import { User } from '../users/entity'
import { UserService } from '../users/service'
import { Response as IResponse } from 'express'

@ApiUseTags('Uploads')
@Controller('/api/v1/uploads')
export class UploadsController {
    constructor(
        @Inject(UserService)
        private readonly userService: UserService,
    ) {
        // Set up expiry monitor
        // Runs every 5 minutes
        setInterval(() => {
            for (let user of this.userService.find()) UploadsService.clean(user)
        }, 1000 * 60 * 5)
    }

    @Get()
    @ApiOperation({ title: 'List' })
    list(
        @AuthedUser() user: User
    ): Upload[] {
        return UploadsService.find(user)
    }

    @Post()
    @ApiOperation({ title: 'Upload' })
    @HttpCode(201)
    @UseInterceptors(FileInterceptor('file', { dest: 'uploads' }))
    async add(
        @AuthedUser() user: User,
        @UploadedFile() file: Express.Multer.File, // Express.Multer.File is in global namespace
        @Headers('x-lifespan') lifespan: number | string = 84
    ): Promise<Upload> {
        return UploadsService.create(user, file, +lifespan)
    }

    @Delete(':id')
    @ApiOperation({ title: 'Delete' })
    @HttpCode(204)
    delete(
        @AuthedUser() user: User,
        @Param() params: { id: string }
    ): void {
        return UploadsService.delete(user, params.id)
    }

    @Get(':user/:id')
    @ApiOperation({ title: 'View' })
    @HttpCode(200)
    view(
        @Param() params: { id: string, user: string }
    ): Upload {
        const user = this.userService.findOne(params.user)
        const upload = UploadsService.findOne(user, params.id)
        return upload
    }

    @Get(':user/:id/download')
    @ApiOperation({ title: 'Download' })
    download(
        @Param() params: { id: string, user: string },
        @Response() res: IResponse
    ): void {
        const user = this.userService.findOne(params.user)
        const upload = UploadsService.findOne(user, params.id)
        return res.sendFile(user.uploads.getPath(upload), {
{'fraction_non_alphanumeric': 0.1398313394783291, 'fraction_numerical': 0.00902137674053736, 'mean_word_length': 2.637660485021398, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7370952', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1570, 'n_words': 381}