aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/pinapelz/FileSystem.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/pinapelz/FileSystem.java')
-rw-r--r--src/main/java/com/pinapelz/FileSystem.java49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/main/java/com/pinapelz/FileSystem.java b/src/main/java/com/pinapelz/FileSystem.java
index 1f252a2..d073691 100644
--- a/src/main/java/com/pinapelz/FileSystem.java
+++ b/src/main/java/com/pinapelz/FileSystem.java
@@ -2,6 +2,7 @@ package com.pinapelz;
import net.dv8tion.jda.api.entities.Message;
+import java.sql.ResultSet;
import java.sql.SQLException;
public class FileSystem {
@@ -14,14 +15,58 @@ public class FileSystem {
return database.getFileById(fileId);
}
- public void createNewFile(String channelId, String messageId, String description, Message.Attachment attachment){
+ 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, 1, filename, description, fileSize, mimeType );
+ database.recordFileMetadata(channelId, messageId, directoryId, filename, description, fileSize, mimeType );
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
+
+ // Backward compatibility - defaults to root directory (ID 1)
+ public void createNewFile(String channelId, String messageId, String description, Message.Attachment attachment){
+ createNewFile(channelId, messageId, 1, description, attachment);
+ }
+ 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 {
+ // Try to find existing directory
+ ResultSet rs = getAllDirectories();
+ while (rs.next()) {
+ if (path.equals(rs.getString("path"))) {
+ int id = rs.getInt("directory_id");
+ rs.close();
+ return id;
+ }
+ }
+ rs.close();
+
+ // Create new directory if not found
+ 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);
+ }
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage