Vérification du nombre de fichiers présents pour un utilisateur avant de lui permettre d'ajouter un fichier
This commit is contained in:
parent
64fd230294
commit
203ceabdf1
@ -56,42 +56,47 @@ public class SavefileRule extends ProtocolReader {
|
||||
super.read(reader);
|
||||
System.out.printf("Sauvegarde du fichier : %s %d\n", filename, size);
|
||||
|
||||
try {
|
||||
FileReceiver fileReceiver = new FileReceiver(storagePath);
|
||||
if (getContext().canAddFile()) {
|
||||
try {
|
||||
FileReceiver fileReceiver = new FileReceiver(storagePath);
|
||||
|
||||
// Ajout login devant le nom du fichier
|
||||
this.filename = getContext().getLogin() + "_" + this.filename;
|
||||
// Ajout login devant le nom du fichier
|
||||
this.filename = getContext().getLogin() + "_" + this.filename;
|
||||
|
||||
// Hashage du nom du fichier
|
||||
ShaHasher hasher = new ShaHasher(this.filename);
|
||||
this.filename = hasher.nextHashing();
|
||||
String fileNameSalt = hasher.getSalt();
|
||||
// Hashage du nom du fichier
|
||||
ShaHasher hasher = new ShaHasher(this.filename);
|
||||
this.filename = hasher.nextHashing();
|
||||
String fileNameSalt = hasher.getSalt();
|
||||
|
||||
String key = getContext().getAesKey();
|
||||
String iv = AES_GCM.generateIV();
|
||||
String key = getContext().getAesKey();
|
||||
String iv = AES_GCM.generateIV();
|
||||
|
||||
// retrieve file and new size
|
||||
int encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv);
|
||||
if (encryptedFileSize < 0) throw new IOException();
|
||||
// retrieve file and new size
|
||||
int encryptedFileSize = fileReceiver.receiveFile(reader, this.filename, this.size, key, iv);
|
||||
if (encryptedFileSize < 0) throw new IOException();
|
||||
|
||||
String fileHash = SHA.hashFile(storagePath, this.filename);
|
||||
String fileHash = SHA.hashFile(storagePath, this.filename);
|
||||
|
||||
// On met les données de la requête actuelle
|
||||
getContext().putDataString("fileName", filename);
|
||||
getContext().putDataInt("size", size);
|
||||
getContext().putDataString("iv", iv);
|
||||
getContext().putDataString("fileNameSalt", fileNameSalt);
|
||||
// On met les données de la requête actuelle
|
||||
getContext().putDataString("fileName", filename);
|
||||
getContext().putDataInt("size", size);
|
||||
getContext().putDataString("iv", iv);
|
||||
getContext().putDataString("fileNameSalt", fileNameSalt);
|
||||
|
||||
this.setResultCommand(protocolRep.executeWriter(getContext(), SendfileRule.NAME, this.filename, String.valueOf(encryptedFileSize), fileHash), ResultCmdReceiver.STOREBACKEND);
|
||||
} catch (IOException | SHA.ShaException e) {
|
||||
this.setResultCommand(protocolRep.executeWriter(getContext(), SendfileRule.NAME, this.filename, String.valueOf(encryptedFileSize), fileHash), ResultCmdReceiver.STOREBACKEND);
|
||||
} catch (IOException | SHA.ShaException e) {
|
||||
this.setResultCommand(protocolRep.executeWriter(getContext(), SaveFileErrorRule.NAME), ResultCmdReceiver.CLIENT);
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
this.setResultCommand(protocolRep.executeWriter(getContext(), SaveFileErrorRule.NAME), ResultCmdReceiver.CLIENT);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette méthode est appelée lors de l'exécution de la règle
|
||||
*
|
||||
* @param data Paramètres pour créer la commande.
|
||||
*/
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user