|
|
|
|
@ -36,6 +36,18 @@ class NetworkManager { |
|
|
|
|
let task = try await URLSession.shared.download(for: request) |
|
|
|
|
if let urlResponse = task.1 as? HTTPURLResponse { |
|
|
|
|
if urlResponse.statusCode == 200 { |
|
|
|
|
|
|
|
|
|
//todo à voir si on en a besoin, permet de re-télécharger un csv si on détecte qu'il a été mis à jour |
|
|
|
|
// if FileManager.default.fileExists(atPath: destinationFileUrl.path()) { |
|
|
|
|
// if let creationDate = try checkFileCreationDate(filePath: task.0.path()), let previousCreationDate = try checkFileCreationDate(filePath: destinationFileUrl.path()) { |
|
|
|
|
// print("File creation date:", creationDate) |
|
|
|
|
// print("File previous creation date:", previousCreationDate) |
|
|
|
|
// if previousCreationDate.isEarlierThan(creationDate) { |
|
|
|
|
// try FileManager.default.removeItem(at: destinationFileUrl) |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
try FileManager.default.copyItem(at: task.0, to: destinationFileUrl) |
|
|
|
|
print("dl rank data ok", lastDateString, fileName) |
|
|
|
|
} else if urlResponse.statusCode == 404 && fileName == "MESSIEURS" { |
|
|
|
|
@ -44,4 +56,11 @@ class NetworkManager { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func checkFileCreationDate(filePath: String) throws -> Date? { |
|
|
|
|
let fileManager = FileManager.default |
|
|
|
|
let attributes = try fileManager.attributesOfItem(atPath: filePath) |
|
|
|
|
return attributes[.creationDate] as? Date |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|