LNMediaFileUtils.swift 763 B

1234567891011121314151617181920212223242526
  1. //
  2. // LNMediaFileUtils.swift
  3. // Lanu
  4. //
  5. // Created by OneeChan on 2026/03/08.
  6. //
  7. import Foundation
  8. struct LNMediaFileUtils {
  9. static func persistTemporaryVideo(from url: URL) -> URL? {
  10. let fileManager = FileManager.default
  11. let destinationUrl = fileManager.temporaryDirectory
  12. .appendingPathComponent(UUID().uuidString)
  13. .appendingPathExtension(url.pathExtension.isEmpty ? "mp4" : url.pathExtension)
  14. do {
  15. if fileManager.fileExists(atPath: destinationUrl.path) {
  16. try fileManager.removeItem(at: destinationUrl)
  17. }
  18. try fileManager.copyItem(at: url, to: destinationUrl)
  19. return destinationUrl
  20. } catch {
  21. return url
  22. }
  23. }
  24. }