/* ----------------------------------------------------------------------------

 Question Server
 GitLab: <https://gitlab.com/MrFry/mrfrys-node-server>

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program. If not, see <https://www.gnu.org/licenses/>.

 ------------------------------------------------------------------------- */

import { Response } from 'express'

import utils from '../../../utils/utils'
import { Request, SubmoduleData } from '../../../types/basicTypes'

const uloadFiles = 'data/f'

function setup(data: SubmoduleData): void {
    const { app /* userDB, url, publicdirs, moduleSpecificData */ } = data

    app.route('/fosuploader').post(function (req: Request, res: Response) {
        utils.uploadFile(req, uloadFiles).then(({ fileName }) => {
            res.redirect('/f/' + fileName)
        })
    })
}

export default {
    setup: setup,
}
