2018-08-29 06:15:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
2022-07-07 10:45:47 +00:00
|
|
|
use SplFileInfo;
|
|
|
|
use Throwable;
|
|
|
|
|
2021-12-06 16:12:47 +00:00
|
|
|
class Helper
|
2018-08-29 06:15:11 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get a unique hash from a file path.
|
|
|
|
* This hash can then be used as the Song record's ID.
|
|
|
|
*/
|
2022-07-07 10:45:47 +00:00
|
|
|
public static function getFileHash(string $path): string
|
2018-08-29 06:15:11 +00:00
|
|
|
{
|
2020-12-22 20:11:22 +00:00
|
|
|
return md5(config('app.key') . $path);
|
2018-08-29 06:15:11 +00:00
|
|
|
}
|
2022-07-07 10:45:47 +00:00
|
|
|
|
|
|
|
public static function getModifiedTime(string|SplFileInfo $file): int
|
|
|
|
{
|
|
|
|
$file = is_string($file) ? new SplFileInfo($file) : $file;
|
|
|
|
|
|
|
|
// Workaround for #344, where getMTime() fails for certain files with Unicode names on Windows.
|
|
|
|
try {
|
|
|
|
return $file->getMTime();
|
|
|
|
} catch (Throwable) {
|
|
|
|
// Just use current stamp for mtime.
|
|
|
|
return time();
|
|
|
|
}
|
|
|
|
}
|
2018-08-29 06:15:11 +00:00
|
|
|
}
|