mirror of
https://github.com/Myxelium/RandomMemerBot.git
synced 2026-07-09 06:25:08 +00:00
Add database
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import * as fileSystem from 'fs';
|
||||
import express from 'express';
|
||||
import { loadAvoidList } from '../../helpers/load-avoid-list';
|
||||
import { loadAvoidList } from '../../helpers/loadAvoidList';
|
||||
|
||||
/**
|
||||
* Adds a user to the avoid list.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
import * as fileSystem from 'fs';
|
||||
import { LoggerColors } from '../../helpers/logger-colors';
|
||||
import { LoggerColors } from '../../helpers/loggerColors';
|
||||
import { DeleteSoundFromDatabase } from '../data/deleteSound';
|
||||
|
||||
/**
|
||||
* Deletes a file from the sounds folder by filename
|
||||
@@ -16,4 +17,6 @@ export function DeleteSoundFile(response: express.Response, request: express.Req
|
||||
}
|
||||
response.send('File deleted successfully.');
|
||||
});
|
||||
|
||||
DeleteSoundFromDatabase(request.params.filename);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import express from 'express';
|
||||
import fs from 'fs';
|
||||
import { loadAvoidList } from '../../helpers/load-avoid-list';
|
||||
import { loadAvoidList } from '../../helpers/loadAvoidList';
|
||||
|
||||
/**
|
||||
* Removes a user from the avoid list.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
import * as fileSystem from 'fs';
|
||||
import { LoggerColors } from '../../helpers/logger-colors';
|
||||
import { LoggerColors } from '../../helpers/loggerColors';
|
||||
|
||||
/**
|
||||
* Returns a list of all sound files in the sounds directory.
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
import { AddUserToAvoidList } from './addUserToAvoidList';
|
||||
import { DeleteSoundFile } from './deleteSoundFile';
|
||||
import { GetSoundFiles } from './getSoundFiles';
|
||||
import { UploadYouTubeFile } from './uploadYouTubeFile';
|
||||
import { DeleteUserFromAvoidList } from './deleteUserFromAvoidList';
|
||||
import { JoinChannel } from './joinChannel';
|
||||
|
||||
export class Handlers {
|
||||
public static AddUserToAvoidList = AddUserToAvoidList;
|
||||
public static DeleteSoundFile = DeleteSoundFile;
|
||||
public static GetSoundFiles = GetSoundFiles;
|
||||
public static UploadYouTubeFile = UploadYouTubeFile;
|
||||
public static DeleteUserFromAvoidList = DeleteUserFromAvoidList;
|
||||
public static JoinChannel = JoinChannel;
|
||||
}
|
||||
export { AddUserToAvoidList } from './addUserToAvoidList';
|
||||
export { DeleteSoundFile } from './deleteSoundFile';
|
||||
export { GetSoundFiles } from './getSoundFiles';
|
||||
export { UploadYouTubeFile } from './uploadYouTubeFile';
|
||||
export { DeleteUserFromAvoidList } from './deleteUserFromAvoidList';
|
||||
export { JoinChannel } from './joinChannel';
|
||||
|
||||
42
client/handlers/uploadMp3FIle.ts
Normal file
42
client/handlers/uploadMp3FIle.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import express from "express";
|
||||
import { UploaderInformation } from "../../models/uploaderInformation";
|
||||
import multer, { diskStorage } from "multer";
|
||||
import { generateFileName } from "../../helpers/generateFileName";
|
||||
import { AddSoundToDatabase } from "../data/addSound";
|
||||
import path from "path";
|
||||
const destination = "sounds/";
|
||||
|
||||
var uploaderInformation : UploaderInformation;
|
||||
|
||||
const storage = diskStorage({
|
||||
destination: destination,
|
||||
filename: function (_req, file, cb) {
|
||||
let fileName = generateFileName(file.originalname)
|
||||
|
||||
cb(null, fileName);
|
||||
|
||||
AddSoundToDatabase(fileName);
|
||||
}
|
||||
});
|
||||
|
||||
const upload = multer({
|
||||
storage: storage,
|
||||
limits: { fileSize: 1 * 1024 * 1024 },
|
||||
fileFilter: function (_req, file, cb) {
|
||||
if (path.extname(file.originalname) !== '.mp3') {
|
||||
return cb(new Error('Only .mp3 files are allowed'));
|
||||
}
|
||||
|
||||
cb(null, true);
|
||||
}
|
||||
});
|
||||
|
||||
export async function UploadMp3File(response: express.Response, request: express.Request) {
|
||||
upload.any()(request, response, function(err) {
|
||||
if (err) {
|
||||
return response.status(500).json({ error: err.message });
|
||||
}
|
||||
uploaderInformation = request.body;
|
||||
response.send('File uploaded successfully.');
|
||||
});
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import path from 'path';
|
||||
import ytdl from 'ytdl-core';
|
||||
import * as fileSystem from 'fs';
|
||||
import ffmpeg from 'fluent-ffmpeg';
|
||||
import { generateFileName } from '../../helpers/generate-file-name';
|
||||
import { generateFileName } from '../../helpers/generateFileName';
|
||||
|
||||
/**
|
||||
* Uploads a YouTube video as an mp3 file to the sounds folder.
|
||||
|
||||
Reference in New Issue
Block a user