Added file deletion functionality to the storage service

Signed-off-by: arzumify <jliwin98@danwin1210.de>
This commit is contained in:
Tracker-Friendly 2024-12-09 21:09:00 +00:00
parent 6eeea11a75
commit 9736939a07
1 changed files with 28 additions and 0 deletions

View File

@ -268,6 +268,32 @@ func getFile(information library.ServiceInitializationInformation, message libra
} }
} }
func deleteFile(information library.ServiceInitializationInformation, message library.InterServiceMessage) {
// Check if the file exists
path := filepath.Join(information.Configuration["path"].(string), message.Message.(nucleusLibrary.File).User.String(), message.Message.(nucleusLibrary.File).Name)
_, err := os.Stat(path)
if os.IsNotExist(err) {
respondError("file not found", information, false, message.ServiceID)
return
}
// Delete the file
err = os.Remove(path)
if err != nil {
respondError(err.Error(), information, true, message.ServiceID)
}
// Success
information.Outbox <- library.InterServiceMessage{
ServiceID: ServiceInformation.ServiceID,
ForServiceID: message.ServiceID,
MessageType: 0,
SentAt: time.Now(),
Message: nil,
}
}
// processInterServiceMessages listens for incoming messages and processes them // processInterServiceMessages listens for incoming messages and processes them
func processInterServiceMessages(information library.ServiceInitializationInformation) { func processInterServiceMessages(information library.ServiceInitializationInformation) {
// Listen for incoming messages // Listen for incoming messages
@ -286,6 +312,8 @@ func processInterServiceMessages(information library.ServiceInitializationInform
case 4: case 4:
// Get file // Get file
getFile(information, message) getFile(information, message)
case 5:
deleteFile(information, message)
default: default:
// Respond with an error message // Respond with an error message
respondError("invalid message type", information, false, message.ServiceID) respondError("invalid message type", information, false, message.ServiceID)