1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package com.pinapelz;
import net.dv8tion.jda.api.entities.Message;
import java.sql.ResultSet;
import java.sql.SQLException;
public class FileSystem {
private Database database;
public FileSystem(String dbHost, String dbUser, String dbPass, String dbName){
database = new Database(dbHost, dbUser, dbPass, dbName);
}
public DiscordFilePath getFileById(int fileId){
String[] rawDiscordFilePath = database.getFileById(fileId);
DiscordFilePath discPath = new DiscordFilePath();
discPath.channelId = Long.parseLong(rawDiscordFilePath[0]);
discPath.messageId = Long.parseLong(rawDiscordFilePath[1]);
discPath.fileName = rawDiscordFilePath[3];
return discPath;
}
public void createNewFile(String channelId, String messageId, int directoryId, String description, Message.Attachment attachment){
int fileSize = attachment.getSize();
String filename = attachment.getFileName();
String mimeType = attachment.getContentType();
try {
database.recordFileMetadata(channelId, messageId, directoryId, filename, description, fileSize, mimeType );
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public ResultSet getFilesByDirectoryIdFiltered(int directoryId, String search, String mimeTypeFilter, String sortBy) {
return database.getFilesByDirectoryId(directoryId, search, mimeTypeFilter, sortBy);
}
public int findOrCreateDirectory(String path) throws SQLException {
ResultSet rs = getAllDirectories();
while (rs.next()) {
if (path.equals(rs.getString("path"))) {
int id = rs.getInt("directory_id");
rs.close();
return id;
}
}
rs.close();
return createDirectory(path);
}
public ResultSet getAllDirectories() {
return database.getAllDirectories();
}
public ResultSet getDirectoryById(int directoryId) {
return database.getDirectoryById(directoryId);
}
public int createDirectory(String path) throws SQLException {
return database.createDirectory(path);
}
public boolean deleteFile(int fileId) throws SQLException {
return database.deleteFile(fileId);
}
public boolean deleteDirectory(int directoryId) throws SQLException {
return database.deleteDirectory(directoryId);
}
}
|